-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prism.Forms dependency injection IServiceCollection problem #1352
Comments
You can create your own IContainerExtension and use that instead. Also, using the MS DI abstractions is not an option. It is not compatible with the requirements of Prism. Our DI abstraction cannot be immutable, and requires the registration and resolution by name. These are non-negotiables. |
Sure thanks, one more question please: Are you using this particular line |
Its mainly for auto ViewModel registrations. Otherwise an exception would be thrown unless you manually registered the ViewModels separately. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Description
As you might already know Microsoft provides a DI abstraction and implementation in the Microsoft.Extensions.DependencyInjection package. Many other libraries have been already integrated with the
IServiceCollection
interface eg.: Entity Framework Core, Logging, (HttpClientFactory) etc. Currently I'm experimenting with the new Prism DI system to integrate with Microsoft'sIServiceCollection
. It's not so easy but I've figured out a workaround with some issues (tried withPrism.Forms.Autofac
):In the following code you can see, that I'm overriding the
CreateContainerExtension
to callContainerBuilder.Populate(IServiceCollection services);
method for the Autofac <--> MS.Ext.DI integration with logging and Entity Framework services.In my MainPageViewModel I've just try to resolve the AppDbContext and an ILogger.
So my first issue is maybe it was bad choice to not support
Microsoft.Extensions.DependencyInjection
but I know you don't want to change on this.Secondly the code above is not working currently because of this line of your codebase: Builder.RegisterSource(new AnyConcreteTypeNotAlreadyRegisteredSource()); In my case this messes up the service registrations regarding to Entity Framework's services. I think you are using this operation to resolve ViewModel types. Are there any other aspects of this? If not than we should register ViewModels in a different way. It will be more and more commonly to use MS.Ext.DI.
If I remove the
Builder.RegisterSource(new AnyConcreteTypeNotAlreadyRegisteredSource());
line and register ViewModel types by hand it works flawlessly.I've tested only in UWP because EFCore has some open issues with Android dotnet/efcore#8922
I will update my post with details of other DI providers.
Thanks.
Basic Information
The text was updated successfully, but these errors were encountered: