Skip to content

Grace.DependencyInjection.Exceptions.RecursiveLocateException with Decoration in HostBuilder #25

Closed

Description

@Mike-E-angelo

Hello there,

I am exploring the use of this library, but am having some difficulty with decorations during the configuration of a host builder.

Here is the xUnit test I am developing:

[Fact]
async Task Grace()
{
	var host = new HostBuilder().UseGrace()
	                            .ConfigureServices(x => x.AddSingleton("Hello World!"))
	                            .ConfigureContainer<IInjectionScope>(x => x.Configure(y => y.ExportDecorator<string>(z => $"Decorated: {z}")))
	                            .Build();
	await host.StartAsync();

	host.Services.GetRequiredService<string>().Should().Be("Decorated: Hello World!");
}

When using the above, I get a rather lengthy error:


Grace.DependencyInjection.Exceptions.RecursiveLocateException : Recursive object graph detected
1 Importing System.String 
2 Importing System.String 
3 Importing System.String 
4 Importing System.String 
5 Importing System.String 
6 Importing System.String 
7 Importing System.String 
8 Importing System.String 
9 Importing System.String 
10 Importing System.String 
11 Importing System.String 
12 Importing System.String 
13 Importing System.String 
14 Importing System.String 
15 Importing System.String 
16 Importing System.String 
17 Importing System.String 
18 Importing System.String 
19 Importing System.String 
20 Importing System.String 

Dropped 60 entries

81 Importing System.String 
82 Importing System.String 
83 Importing System.String 
84 Importing System.String 
85 Importing System.String 
86 Importing System.String 
87 Importing System.String 
88 Importing System.String 
89 Importing System.String 
90 Importing System.String 
91 Importing System.String 
92 Importing System.String 
93 Importing System.String 
94 Importing System.String 
95 Importing System.String 
96 Importing System.String 
97 Importing System.String 
98 Importing System.String 
99 Importing System.String 
100 Importing System.String 

   at Grace.DependencyInjection.Impl.Expressions.ActivationExpressionRequest.NewRequest(Type activationType, IActivationStrategy requestingStrategy, Type injectedType, RequestType requestType, Object info, Boolean maintainPaths, Boolean carryData)
   at Grace.DependencyInjection.Impl.CompiledStrategies.CompiledInitializationDecoratorStrategy`1.InternalGetDecoratorActivationExpression(IInjectionScope scope, IActivationExpressionRequest request)
   at Grace.DependencyInjection.Impl.CompiledStrategies.CompiledInitializationDecoratorStrategy`1.GetDecoratorActivationExpression(IInjectionScope scope, IActivationExpressionRequest request, ICompiledLifestyle lifestyle)
   at Grace.DependencyInjection.Impl.Expressions.DecoratorActivationPathNode.GetActivationExpression(IInjectionScope scope, IActivationExpressionRequest request)
   at Grace.DependencyInjection.Impl.Expressions.ActivationExpressionBuilder.CreateDecoratedActivationStrategy(IInjectionScope scope, IActivationExpressionRequest request, ICompiledExportStrategy strategy, List`1 decorators)
   at Grace.DependencyInjection.Impl.Expressions.ActivationExpressionBuilder.DecorateExportStrategy(IInjectionScope scope, IActivationExpressionRequest request, ICompiledExportStrategy strategy)
   at Grace.DependencyInjection.Impl.InstanceStrategies.BaseInstanceExportStrategy.GetActivationExpression(IInjectionScope scope, IActivationExpressionRequest request)
   at Grace.DependencyInjection.Impl.Expressions.ActivationExpressionBuilder.ActivationExpressionForStrategy(IInjectionScope scope, IActivationExpressionRequest request, ICompiledExportStrategy strategy)
   at Grace.DependencyInjection.Impl.Expressions.ActivationExpressionBuilder.GetExpressionFromStrategyCollection(IInjectionScope scope, IActivationExpressionRequest request)
   at Grace.DependencyInjection.Impl.Expressions.ActivationExpressionBuilder.GetActivationExpressionFromStrategies(IInjectionScope scope, IActivationExpressionRequest request)
   at Grace.DependencyInjection.Impl.Expressions.ActivationExpressionBuilder.GetActivationExpression(IInjectionScope scope, IActivationExpressionRequest request)
   at Grace.DependencyInjection.Impl.CompiledStrategies.CompiledInitializationDecoratorStrategy`1.InternalGetDecoratorActivationExpression(IInjectionScope scope, IActivationExpressionRequest request)
   at 

... much repeat. 😆

My intent here is to utilize the "built-in" Microsoft.DependencyInjection.Abstractions (AddSingleton, AddTransient, AddScoped, etc) and then use the ConfigureContainer for Grace-specific functionality such as decoration.

FWIW, this approach worked fine when using LightInject, but because it appears that it does some funny business with Func<,> delegates that cannot be turned off, it has forced me to consider alternatives.

Is there a very obvious method call and/or configuration I am overlooking, perhaps?

Thank you for any assistance you can provide and for your efforts into this library. 👍

Activity

  1. Mike-E-angelo commented on Jan 17, 2020

    @Mike-E-angelo
    Author

    The other observation of note is that the ExportDecorator method I am using in the above test is a void method, which seems different from all the other fluent-based method calls that I see having to deal with decorator (and pretty much everything else 😆), so perhaps this is not the right method to call.

    I did not see any others or equivalents that perform the same registration as I am attempting to do here, nor have I found any documentation around decorations, but will continue to search in the meantime and update here accordingly.

  2. ipjohnson commented on Jan 17, 2020

    @ipjohnson
    Owner

    Hi mike

    I’ll take a look today. I’m not exactly sure why it’s doing this.

  3. silkfire commented on Jan 17, 2020

    @silkfire
    Contributor

    @mike-eee It looks like the generic ExportDecorator method indeed returns void, whereas the non-generic one returns IFluentDecoratorStrategyConfiguration.

    https://github.com/ipjohnson/Grace/blob/e6853c7fb3b23a27824b9b2e17ad860b9b4a403b/src/Grace/DependencyInjection/Impl/ExportRegistrationBlock.cs#L529

  4. ipjohnson commented on Jan 17, 2020

    @ipjohnson
    Owner

    Good catch, I apparently overlooked the delegate decorator configuration.

  5. Mike-E-angelo commented on Jan 17, 2020

    @Mike-E-angelo
    Author

    Woohoo, happy to "help" yall. 😆

  6. ipjohnson commented on Jan 18, 2020

    @ipjohnson
    Owner

    I've committed a fix for this issue and I'll be looking to do a Beta release this weekend with a couple other issues.

    I'll update this issue when they are released.

  7. Mike-E-angelo commented on Jan 18, 2020

    @Mike-E-angelo
    Author

    Great! Thank you, @ipjohnson!

  8. ipjohnson commented on Jan 18, 2020

    @ipjohnson
    Owner

    Hi @mike-eee

    I've pushed a beta package to NuGet to address this so you'll need to install Grace.7.1.1-Beta784

  9. Mike-E-angelo commented on Jan 19, 2020

    @Mike-E-angelo
    Author

    Awesome, thank you @ipjohnson! I can confirm that this now works as expected on my side. 👍 I appreciate the quick weekend efforts!

  10. ipjohnson commented on Jan 19, 2020

    @ipjohnson
    Owner

    Your welcome any other issues let me know

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions