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
{{ message }}
Repository navigation
We can create plugin that do not need to call Plugin.Init() to each plaform.. #293
in xamarin form we need to call pluginsInit() in app start.. I hope Maui.net the user do not need to write it app start Init PlugIn(). like flutter it automatically generate Init plugins when building by tools...
It will make it easier for people to use the framework. Even if you have experience with XAML/C#/ the .NET ecosystem, this whole plugin initialization system is something quite unique to Xamarin. In all other frameworks, you add the package and then you just use it. In Xamarin, no, you first need to go to some file - in the happy case it's just App.xaml.cs, in the unhappy case you might need to go into the iOS/Android projects - and call some initialization method.
Removing this requirement for the developers, makes it easier for people new to the framework to onboard / get going using existing knowledge, without needing to know quirks for even the simplest of plugins.
Today, on the XF project you don't need the Plugin.Init() stuff, to avoid that you, as a lib maintainer, need to care about linker and make tests to see when linker remove a piece of code and make sure to keep that code. You can see the XamarinCommunityToolkit for it, we don't use the Plugin.Init() approach (:
Update
If the lib needs to do some init configuration or get the Activity, so the Init pattern is still needed for it.
Glad to hear that, I must admit I don't have much experience on the plugin development side and my experience as an app developer with almost - if not all - plugins is that you need to make some sort of initialization call. Not sure if the plugin developers are just lazy (for the lack of a better word) or it's some sort of limitations they are hitting.
Just to give one example - FFImageLoading - in their Xamarin.Forms getting started guide, in Step 2 they have you add FFImageLoading.Forms.Platform.CachedImageRenderer.Init(); in each of the platform-specific projects.
Not that I know for certain, but the Init call has to be made because there are no static hooks for application initialization and .net does not have an assembly entry-point-like (main) that can be used to initialize the plugin.
If MAUI offers a HostBuilder-like application model, plugins could be hooked and initialized that way
I can see that some plugins may opt to initialize that way, but I think that there will be scenarios where that is not possible, like requiring a reference to some application context.
Just to be clear, having to call an Init method for each plugin is not an issue for me.
Is MAUI getting a HostBuilder-like application model?
I work on flutter app.. the plugin initialization is automatically generated.. I know that some package need to call in context...
I just think maybe there will event that we can register the plugin on that context... so the user does not need to write pluginInit(),, this means it will be automatically added to. here is my screenshot in flutter app... this is automatically generated to register the call Init(). Plugins that downloaded from pub.packages.
@nextcodelab and if the plugin needs to do a custom initialization? Like an Init(Action<Provider> customConfig), how flutter handle with that? Or doesn't exist this scenario?
Activity
GeraudFabien commentedon Dec 31, 2020
What problem would it solve? Except add a new useless black box that will make a lot of problem.
marius-bughiu commentedon Dec 31, 2020
It will make it easier for people to use the framework. Even if you have experience with XAML/C#/ the .NET ecosystem, this whole plugin initialization system is something quite unique to Xamarin. In all other frameworks, you add the package and then you just use it. In Xamarin, no, you first need to go to some file - in the happy case it's just
App.xaml.cs, in the unhappy case you might need to go into the iOS/Android projects - and call some initialization method.Removing this requirement for the developers, makes it easier for people new to the framework to onboard / get going using existing knowledge, without needing to know quirks for even the simplest of plugins.
pictos commentedon Dec 31, 2020
Today, on the XF project you don't need the
Plugin.Init()stuff, to avoid that you, as a lib maintainer, need to care about linker and make tests to see when linker remove a piece of code and make sure to keep that code. You can see the XamarinCommunityToolkit for it, we don't use thePlugin.Init()approach (:Update
If the lib needs to do some init configuration or get the Activity, so the Init pattern is still needed for it.
marius-bughiu commentedon Dec 31, 2020
Glad to hear that, I must admit I don't have much experience on the plugin development side and my experience as an app developer with almost - if not all - plugins is that you need to make some sort of initialization call. Not sure if the plugin developers are just lazy (for the lack of a better word) or it's some sort of limitations they are hitting.
Just to give one example - FFImageLoading - in their Xamarin.Forms getting started guide, in Step 2 they have you add
FFImageLoading.Forms.Platform.CachedImageRenderer.Init();in each of the platform-specific projects.REscobar commentedon Dec 31, 2020
Not that I know for certain, but the
Initcall has to be made because there are no static hooks for application initialization and .net does not have an assembly entry-point-like (main) that can be used to initialize the plugin.If MAUI offers a
HostBuilder-like application model, plugins could be hooked and initialized that waybadcel commentedon Dec 31, 2020
@REscobar with .net 5 there are module initializers.
REscobar commentedon Jan 1, 2021
Thanks good to know, somehow that escaped me.
I can see that some plugins may opt to initialize that way, but I think that there will be scenarios where that is not possible, like requiring a reference to some application context.
Just to be clear, having to call an
Initmethod for each plugin is not an issue for me.Is MAUI getting a
HostBuilder-like application model?nextcodelab commentedon Jan 1, 2021
I work on flutter app.. the plugin initialization is automatically generated.. I know that some package need to call in context...

I just think maybe there will event that we can register the plugin on that context... so the user does not need to write pluginInit(),, this means it will be automatically added to. here is my screenshot in flutter app... this is automatically generated to register the call Init(). Plugins that downloaded from pub.packages.
pictos commentedon Jan 1, 2021
@nextcodelab and if the plugin needs to do a custom initialization? Like an
Init(Action<Provider> customConfig), how flutter handle with that? Or doesn't exist this scenario?REscobar commentedon Jan 1, 2021
Remember that the concepts of plugins as they are in Flutter doesn't exist in Xamarin or Maui.
workgroupengineering commentedon Jan 2, 2021
I think it is not necessary to invent something new but just use Module Initializers of C # 9.0.
nextcodelab commentedon Jan 29, 2021
Call Global Context