blog
blog copied to clipboard
Adding a custom dependency injection container in ASP.NET Core
Written on 08.05.2017 22:07:53
URL: http://asp.net-hacker.rocks/2017/05/08/add-custom-ioc-in-aspnetcore.html
Comment written by Jürgen Gutsch on 03.09.2017 08:04:54
really? It was much more work in the past.
It depends o which DI container you wanna use. E. g. it is pretty less effort using Autofaq
Thanks for this post, however, has this been updated since ASP.Net Core 3.0? As soon as I modified my ConfigureServices(...) method, I'm not getting a warning:
Warning ASP0000 Calling 'BuildServiceProvider' from application code results in an additional copy of singleton services being created. Consider alternatives such as dependency injecting services as parameters to 'Configure'. Is there a newer, more correct way to use AutoFac today with current version of ASP.Net Core?
Hi @rhartness You are right. Unfortunately this post is pretty much outdated now. The way the IServiceProvider is created changed a little bit.
This post is a bit newer: https://asp.net-hacker.rocks/2018/09/27/customizing-aspnetcore-03-dependency-injection.html I'm also writing on a book about customizing ASP.NET Core, where I did an update on 3.0: https://github.com/JuergenGutsch/customizing-aspnetcore-book/blob/develop/manuscript/03-dependency-injection.md
Hope that helps :-)
I think I'm working my way through this. It's getting a bit muddied for two reasons. First, for the past 7 years, all of my contracts have been with existing applications so setting up a new project isn't something I've had to do in... ages. Second, I'm setting up a Web API project vs. a full blown ASP.Net application with a full MVC setup. Since my project is simpler from the VS templates, it's hard to discern what is need and what isn't, from the Autofac documentation.
Your original article was pretty easy to understand, so I'll be sure to check out the links you posted. Thanks!