Hacker News new | ask | show | jobs
by keithnz 2463 days ago
its very simple to get .net core DI working, shouldn't be much code other than registering your types / service.

await new HostBuilder().ConfigureServices((context, services) => { // services.AddTransient.... }).UseConsoleLifetime().Build.RunAsync()

1 comments

I’m talking DI for ASP.NET MVC 5, non-Core.

That required a custom provider (trivial), and non-obviously a custom ControllerFactory as I picked Core DI instead of a more fully-fledged solution.

Unfortunately there is very little obviousness in documentation and germs often get conflated and confused. Perhaps this is MS trying to get me to take one of their infamous certification courses?

That is because MVC 5 did not support DI out of the box. This has been fixed with Core. It is quite easy now, since I was able to figure it out haha.