dazinator / Dotnettency

Mutlitenancy for dotnet applications
MIT License
111 stars 23 forks source link

Bi-directional dependency relationship detected #34

Closed amalabey closed 6 years ago

amalabey commented 6 years ago

I ran into an issue (Bi-directional dependency relationship detected) when using Serilog with Dotnettency in my ASP.NET Core 2.0 app. I am using "1.4.0-unstable0024" version. Can you please confirm what is the right version for ASP.NET Core 2.0? Also, how do I obtain the symbols for the version of the nuget package. I can build the PDBs myself, but I need to know how to find the source code matching my nuget version.

Bi-directional dependency relationship detected! Check the StructureMap stacktrace below: 1.) Instance of Dotnettency.Container.ITenantContainerAdaptor (Dotnettency.Container.StructureMapTenantContainerAdaptor) 2.) Lambda: (IContext.GetInstance() As IServiceProvider) 3.) Instance of System.IServiceProvider 4.) Lambda: Invoke(value(Dotnettency.Container.StructureMap.ContainerExtensions+<>c__DisplayClass5_0).descriptor.ImplementationFactory, IContext.GetInstance()) 5.) Instance of Microsoft.Extensions.Logging.ILoggerFactory (System.Object) 6.) new Logger`1(Default of ILoggerFactory) 7.) Logger ('701fb36d-7d22-4ae2-a142-b87bef278de9') 8.) Instance of ILogger ('701fb36d-7d22-4ae2-a142-b87bef278de9') 9.) new StructureMapTenantContainerAdaptor(Default of ILogger, Default of IContainer, Value: Root) 10.) Dotnettency.Container.StructureMapTenantContainerAdaptor 11.) Instance of Dotnettency.Container.ITenantContainerAdaptor (Dotnettency.Container.StructureMapTenantContainerAdaptor) 12.) Container.GetInstance()

dazinator commented 6 years ago

Thanks for reporting. I need to make sure any serilog dependency is removed as it is unintentional if this dependency is being passed on to consumers. In terms of versions used, on the Readme is a link to a dotnettency.samples repo, and there if you switch to the aspnetcore20 branch you should see some relevant aspnetcore20 sample projects.

amalabey commented 6 years ago

It appears the issue is not directly related to serilog.

If I register a ILoggerFactory like "services.AddSingleton<ILoggerFactory, CustomLoggerFactory>();" this works, but if I do "services.AddSingleton(svc => new CustomLoggerFactory());" it fails. Probably because the second one requires IServiceProvider. But, "StructureMapTenantContainerAdaptor" in turns depends on "ILogger". What do you think the fix should be?

dazinator commented 6 years ago

Not sure I fully understand the issue but best thing to do is set up logging as early as possible. If adding the logger factory early is not a problem then just do that..

dazinator commented 6 years ago

For asp.net core 2.0 please take a look at the sample here: https://github.com/dazinator/Dotnettency.Samples/tree/aspnetcore20/src

I think the problem you are hitting is likely because you are using 1.4.0-unstable, I think you need to upgrade to 2.0.0-unstable. Let me know if you are still hitting issues.