Reputation: 857
Is there anything like https://github.com/aspnet/DependencyInjection for good old .NET framework applications?
"Contains common DI abstractions that ASP.NET Core and Entity Framework Core use."
I am writing a framework and I do not want to force a specific IoC container on users.
Upvotes: 3
Views: 1092
Reputation: 172646
I am writing a framework and I do not want to force a specific IoC container on users.
The way to do that is to create good extension points for users to replace. Having a common DI abstraction is a bad idea, because this is an anti-pattern called Conforming Container. This anti-pattern is not something theoretical; ASP.NET Core applies this anti-pattern and the result of this is that both the Simple Injector maintainers AND the Autofac Maintainers were unable to create an adapter implementation that fully complies with the defined contract. The Simple Injector story can be read here and here and a general discussion with Microsoft about this can be found here. You can read my open letter to Microsoft in this thread here and you can see that the Autofac maintainers agree with this statement.
In the end, Microsoft acknowledged the problems by promising that they will build a good integration possibilities by providing
adequate composition roots per framework to make integration as smooth as it can be.
So prevent applying the Conforming Container anti-pattern in your own framework. We already see Microsoft fixing the problems that this anti-pattern has caused in the next minor release of ASP.NET Core. Instead do provide "good integration possibilities" as Mark Seemann described here.
Upvotes: 6
Reputation: 24525
You can use a .NET Core
project that consumes the DI packages, and then have this project target the full framework. You'd target one of the "full" target framework monikers (TFM), and you're project.json
would look something like this:
{
"dependencies": {
"Microsoft.Extensions.DependencyInjection": "1.0.0"
},
"frameworks": {
"net46": { }
},
"version": "1.0.0-*"
}
Upvotes: 2