Wrapping DryIoc for ASP.NET Core MVC (.NET 5)

241 Views Asked by At

I am attempting to upgrade a legacy .NET Framework 4.7.2 solution, to be ASP.NET Core 5

The legacy solution used DryIoc 2.12.10. It was wrapped it in a class (called DIContainer) that was passed into the Register method of classes that were referenced in appsettings.json's System/Dependency/Containers array.

In my ASP.NET Core MVC (.NET 5) solution, I upgraded to DryIoc 4.7.5 (which is .NET Core compatible) and am hoping to retain the DIContainer wrapper approach in order to avoid rewriting a bunch of application code.

I have studied the provided DryIoc samples, which cover ASP.NET Core 3.1 and WebApi usage. Neither are 100% exactly what you would do for ASP.NET Core 5, but pretty close. I have been able to get things almost working.

One thing that frustrates me is that in my IServiceProviderFactory.CreateBuilder implementation, I cannot return DIContainer, for the Main method to use when invoking HostBuilder.Build(). I guess it makes sense, since DIContainer does not conform to the interface it's probably trying to use internally.

My current issue, though, is that in my Program.cs Main() method, I get the error: System.InvalidOperationException: 'No service for type 'Microsoft.Extensions.Hosting.IHost' has been registered.'

I'm a bit lost on how to proceed with that. I'm not sure what code people would need to see to help debug things. Please feel free to ask for specifics, and I'll try to explain further, with code samples.

0

There are 0 best solutions below