Using DryIoc ASP.NET Core MVC (.NET 5) #398
-
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 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. Thank you for any help! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
I am not sure about this problem, because HostBuilder still has the UseServiceFactoryProvider method: |
Beta Was this translation helpful? Give feedback.
I am not sure about this problem, because HostBuilder still has the UseServiceFactoryProvider method:
https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.hosting.hostbuilder.useserviceproviderfactory?view=dotnet-plat-ext-5.0#Microsoft_Extensions_Hosting_HostBuilder_UseServiceProviderFactory__1_Microsoft_Extensions_DependencyInjection_IServiceProviderFactory___0__
so you may return
new DryIocServiceProviderFactory(...)
.