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
We are using the generic host already together with FreshMvvm in a project, but it was a pain to create a custom IServiceProviderFactory that works with TinyIoC. We found some bugs and many limitations in TinyIoC.
The first plan was to use only M.E.DI and implement the IFreshIOC interface to make it work with FreshMvvm. But then I noticed that FreshMvmm registers and unregisters services after the startup. This is something that is not supported by M.E.DI and many other DI systems.
As a first step, I suggest changing the code to register services only at the startup (and never unregister anything). As far as I see there are only a few places where services get replaced in the container. And there are other ways to accomplish the same.
After these changes, it will be possible (but optional) to use the generic host with M.E.DI and without TinyIoC.
In the long term, IFreshIOC (and TinyIoC) can be removed from this project. I think it's not needed anymore because the generic host has a better default DI system and also better support for 3rd party libraries.
What do you think about it? Do you already have such plans? Will you accept PRs for this?
The text was updated successfully, but these errors were encountered:
@libin85 sorry, I missed your comment. I wrote a custom implementation of IServiceProviderFactory<FreshTinyIoCContainer> to use the generic host together with TinyIoC. The problem is that FreshMvvm modifies the container after the startup. M.E.DI builds the container once at the startup and then it can't be changed anymore.
My solution works in one of our production apps, but some hacks were needed.
I also think that the generic host and M.E.DI are the way to go for the future. Especially if FreshMvvm wants to support MAUI. And if I remember correctly, FreshMvvm was mentioned to be one of the MVVM frameworks that will support MAUI.
Maybe @rid00z can provide an update on the future of FreshMvvm and MAUI?
FreshMvvm support for MAUI was confirmed in #325. I am closing this issue because I think it makes no sense to introduce this change in the current version for Xamarin.Forms and for MAUI it will be required anyway.
I suggest using the .NET Generic Host and replacing TinyIoC with Microsoft.Extensions.DependencyInjection (the link is for ASP.NET Core, but it works the same way with the generic host).
Using the generic host has multiple advantages. Some of them are:
James Montemagno wrote already some time ago how to Add ASP.NET Core's Dependency Injection into Xamarin Apps with HostBuilder.
We are using the generic host already together with FreshMvvm in a project, but it was a pain to create a custom
IServiceProviderFactory
that works with TinyIoC. We found some bugs and many limitations in TinyIoC.The first plan was to use only M.E.DI and implement the
IFreshIOC
interface to make it work with FreshMvvm. But then I noticed that FreshMvmm registers and unregisters services after the startup. This is something that is not supported by M.E.DI and many other DI systems.As a first step, I suggest changing the code to register services only at the startup (and never unregister anything). As far as I see there are only a few places where services get replaced in the container. And there are other ways to accomplish the same.
After these changes, it will be possible (but optional) to use the generic host with M.E.DI and without TinyIoC.
In the long term, IFreshIOC (and TinyIoC) can be removed from this project. I think it's not needed anymore because the generic host has a better default DI system and also better support for 3rd party libraries.
What do you think about it? Do you already have such plans? Will you accept PRs for this?
The text was updated successfully, but these errors were encountered: