Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

We can create plugin that do not need to call Plugin.Init() to each plaform.. #293

Closed
nextcodelab opened this issue Dec 31, 2020 · 12 comments

Comments

@nextcodelab
Copy link

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...

@GeraudFabien
Copy link

What problem would it solve? Except add a new useless black box that will make a lot of problem.

@marius-bughiu
Copy link

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
Copy link
Contributor

pictos commented 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 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.

@marius-bughiu
Copy link

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
Copy link

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

@badcel
Copy link

badcel commented Dec 31, 2020

@REscobar with .net 5 there are module initializers.

@REscobar
Copy link

REscobar commented 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 Init method for each plugin is not an issue for me.

Is MAUI getting a HostBuilder-like application model?

@nextcodelab
Copy link
Author

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.
Screenshot 2021-01-01 174703

@pictos
Copy link
Contributor

pictos commented 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
Copy link

REscobar commented Jan 1, 2021

Remember that the concepts of plugins as they are in Flutter doesn't exist in Xamarin or Maui.

@workgroupengineering
Copy link
Contributor

I think it is not necessary to invent something new but just use Module Initializers of C # 9.0.

@nextcodelab
Copy link
Author

Call Global Context

Context context = Application.Context;

@PureWeen PureWeen closed this as completed Feb 1, 2021
@dotnet dotnet locked and limited conversation to collaborators Feb 1, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

8 participants