You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Turns out I cannot read and posted the issue here instead in the Prism samples repo. Im sorry for that. Nothing to see here, move along.
Original post
Is your feature request related to a problem? Please describe.
I am missing a sample or some documentation explaining the correct way to handle this. I want to set up a .NET Core WPF application which uses Prism and whose Lifetime / DI / Configuration is controlled (or supported) by a Generic Host.
In my case I am utilizing DryIoC as my ioc container of choice.
Right now WPF does not do a great job of using newer framework features, there are some open issues on GH like dotnet/wpf:499. So even if the WPF integration will not be perfect, some aspects can already be put to good use: IoC, Configuration and Hosted Services for background tasks.
Describe the solution you'd like
Clear guidelines for bootstrapping an application using a Generic Host, sample included.
I am having trouble finding definitive information on instantiating the IoC container myself. There is a hook that seems to be doing that - CreateContainerExtension(). Is this the correct way to go about it? If yes, is its intended use documented and if not - can we improve the documentation?
Describe alternatives you've considered
I managed to get things going with a couple of extra lines, but I'm sure that there are better ways to go about that (eg utilizing the aforementioned CreateContainerExtension method).
Additional dependencies:
Microsoft.Extensions.Hosting - this dependency is for the generic host feature.
DryIoc.Microsoft.DependencyInjection - package with extension methods for the dryioc adapter, usually used in the context of ASPNET Core.
The App.xaml.cs actually looks alright, services can be registered as usual and resolved via base.Container and via _host.Services since im basically just adding more registrations to the instantiated container.
// App.xaml.csprotectedoverridevoidRegisterTypes(IContainerRegistrycontainerRegistry){
containerRegistry.Register<ServiceA>();}protectedoverride Window CreateShell(){_host=new HostBuilder().ConfigureServices(x =>{ x.AddTransient<ServiceB>();}).UseServiceProviderFactory(new DryIocServiceProviderFactory(Container)).Build();
_host.Start();// ServiceA and ServiceB can be resolved here.return _host.Services.GetService<MainWindow>();}
While implementing the DryIoC Service Provider Factory it became obvious that I'm going down the wrong path. As you will see, I am taking the instantiated container and casting it to the known underlying type. Normally you would new up a container in CreateBuilder so this current implementation feels wrong.
// DryIocServiceProviderFactory.csinternalclassDryIocServiceProviderFactory:IServiceProviderFactory<IContainer>{privatereadonlyDryIocContainerExtension_containerProvider;publicDryIocServiceProviderFactory(IContainerProvidercontainerProvider){// I should not be doing this.._containerProvider= containerProvider as DryIocContainerExtension;}public IContainer CreateBuilder(IServiceCollectionservices){return _containerProvider.Instance.WithDependencyInjectionAdapter(services);}public IServiceProvider CreateServiceProvider(IContainercontainerBuilder){return containerBuilder.Resolve<IServiceProvider>();}}
Describe suggestions on how to achieve the feature
So if I am correct, I need to somehow use the CreateContainerExtension() method.
The following does not work, Prism services are missing from the container and cannot be resolved.
I thought that these would get registered in the container I return from this method.
Hopefully I did not miss anything obvious in the documentation, I searched but found nothing. I would love to contribute to the project and push such a sample, but before doing that I need a bit of hand holding. Thanks!
The text was updated successfully, but these errors were encountered:
Turns out I cannot read and posted the issue here instead in the Prism samples repo. Im sorry for that. Nothing to see here, move along.
Original post
Is your feature request related to a problem? Please describe.
I am missing a sample or some documentation explaining the correct way to handle this. I want to set up a .NET Core WPF application which uses Prism and whose Lifetime / DI / Configuration is controlled (or supported) by a Generic Host.
In my case I am utilizing DryIoC as my ioc container of choice.
Right now WPF does not do a great job of using newer framework features, there are some open issues on GH like dotnet/wpf:499. So even if the WPF integration will not be perfect, some aspects can already be put to good use: IoC, Configuration and Hosted Services for background tasks.
Describe the solution you'd like
Clear guidelines for bootstrapping an application using a Generic Host, sample included.
I am having trouble finding definitive information on instantiating the IoC container myself. There is a hook that seems to be doing that -
CreateContainerExtension()
. Is this the correct way to go about it? If yes, is its intended use documented and if not - can we improve the documentation?Describe alternatives you've considered
I managed to get things going with a couple of extra lines, but I'm sure that there are better ways to go about that (eg utilizing the aforementioned
CreateContainerExtension
method).Additional dependencies:
Microsoft.Extensions.Hosting
- this dependency is for the generic host feature.DryIoc.Microsoft.DependencyInjection
- package with extension methods for the dryioc adapter, usually used in the context of ASPNET Core.The App.xaml.cs actually looks alright, services can be registered as usual and resolved via
base.Container
and via_host.Services
since im basically just adding more registrations to the instantiated container.While implementing the DryIoC Service Provider Factory it became obvious that I'm going down the wrong path. As you will see, I am taking the instantiated container and casting it to the known underlying type. Normally you would new up a container in
CreateBuilder
so this current implementation feels wrong.Describe suggestions on how to achieve the feature
So if I am correct, I need to somehow use the
CreateContainerExtension()
method.The following does not work, Prism services are missing from the container and cannot be resolved.
I thought that these would get registered in the container I return from this method.
Hopefully I did not miss anything obvious in the documentation, I searched but found nothing. I would love to contribute to the project and push such a sample, but before doing that I need a bit of hand holding. Thanks!
The text was updated successfully, but these errors were encountered: