Dotnettency icon indicating copy to clipboard operation
Dotnettency copied to clipboard

Use Dazinator.Extensions.DependencyInjection.ChildContainers

Open dazinator opened this issue 3 years ago • 1 comments

Autofac and Structuremap are "non native" DI containers.

I now have a solution to create child containers using the native Microsoft ServiceProvider: https://github.com/dazinator/Dazinator.Extensions.DependencyInjection/blob/develop/src/DependencyInjection.ChildContainers/README.md

I'll need to make this the "default" approach used, and possibly deprecate autofac and structuremap until they can be added back in future (if its too much work to tackle at this stage)

This will help solve a number of issues a bugs like #74

I was also never truly happy with the resolution of #38 because it involved creating a temporary "copy" of services that needed to be present in the child IServiceCollection when building the child container otherwise AddXyz() calls that look for those services and sometimes grab instances, could fail. The new approach solves that thanks to ChildServiceCollection: https://github.com/dazinator/Dazinator.Extensions.DependencyInjection/blob/develop/src/DependencyInjection.Tests/ChildServiceProvider/ChildServiceCollectionTests.cs

dazinator avatar Sep 23 '20 12:09 dazinator

I've updated to the latest version of Dazinator.Extensions.DependencyInjection.ChildContainers as part of the feature branch to update to dotnet6.

I've not tested fully that the updated package hasn't broken anything - I am using a class "ChildServiceCollection" from that package to filter the services added to the child container being built for autofac, however I think some stuff changed and I actually now need to build a child service provider as shown by that package, as part of the building a child service provider is that it knows how to delegate requests for things like parent open generic services, to the parent correctly.

So I will remove stucturemap and autofac, and change the child container implementation to be more suitable to this new approach as part of the .net 6 feature branch upgrade.

dazinator avatar Jan 12 '24 10:01 dazinator