How is AutoFac better than Microsoft.Extensions.DependencyInjection? Autofac supports Property and Method injection (however I don't really understand where Property and Method injection might be useful).
I mean why should I use AutoFac when I can do the same thing by Microsoft.Extensions.DependencyInjection
AutoFac provides better integration for the ASP.NET MVC framework and is developed using Google code. AutoFac manages the dependencies of classes so that the application may be easy to change when it is scaled up in size and complexity.
It manages the dependencies between classes so that applications stay easy to change as they grow in size and complexity. Autofac is the most popular DI/IoC container for ASP.NET and it works with . NET Core flawlessly.
¶ Autofac is an addictive IoC container for . NET. It manages the dependencies between classes so that applications stay easy to change as they grow in size and complexity. This is achieved by treating regular .
Autofac is an IoC container that provides better integration for the ASP.NET MVC Framework, and manages dependencies between classes so that applications stay easy to change.
It's a fair question; fundamentally the difference is in the additional features Autofac can offer you if you need them. For simple applications, the Microsoft DI may offer enough functionality, but I've found as my application grows there's some extra features I find myself wanting/needing.
The features that in my mind encouraged me to originally start using Aufofac are:
Meta<Lazy<IMyService>>
)There's plenty more, but those are some of my favourite features. Check the docs for all the goodness.
Also, there's no reason you can't start using the built-in DI and then add Autofac later when you realise you need it. The Autofac ASP.NET Core integration (https://autofaccn.readthedocs.io/en/latest/integration/aspnetcore.html) will just pick up all your existing registrations, and then you can add those extra features on top.
In the interest of full disclosure here, I will point out that I am one of the maintainers of Autofac.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With