-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[WIP] Fluent API + Micosoft.Extensions.Hosting for initialization of Xamarin.Forms #8220
Conversation
@samhouts @jsuarezruiz @jfversluis Can I ask you to run the tests please? |
I don't like t have 2 APIs to achieve the same goal. If you prefer having everything fluent, feel free to pack that in a separate nuget, as extensions methods, use it and share it |
@jfversluis Microsoft.Extensions.Hosting is only for .netstandard 2.0 so this is a problem. |
@jfversluis Or maybe we can make our own analogue? With the same api, but with support .net standard 1? And call it Xamarin.Forms.Hosting |
@KSemenenko : Compared with Asp.net Core that deliberately has no Seriously, I love your idea. I really want your work above to be one of Xamarin.Forms project templates in .net core SDK. I also made a request How to implement DI in Xamarin.Forms. |
Hi @pstricks-fans, this was done for quick implementation. |
@KSemenenko Would this allow me access and swap out XF infrastructure? Factories and resolvers etc. |
Yes yes yes please! Xamarin.Forms feels so klunky without proper DI support. Prism helps, but anyone tried doing a hamburger menu with prism? Yikes. Shell is nice, but you give up viewmodel-first navigation and DI...not worth it. |
Let's work on this on #12460 12460 |
Description of Change
What if we were to add a "Fluent API" for initialization of Xamarin.Forms? Instead of calling several Init methods that are not very intuitive or discoverable, we can use a fluent mechanism.
Based on @jamesmontemagno post
https://montemagno.com/add-asp-net-cores-dependency-injection-into-xamarin-apps-with-hostbuilder/
@nickrandolph thanks for the idea with the article.
Issues Resolved
API Changes
new property in Application
new interfaces:
Xamarin Forms Init part:
now we can write extensions for pre init:
and we can write extensions for post init:
DI + HostBuilder part:
We can create Startup.cs, and use it
.UseStartup<Startup>()
minimal call
or just Init for backward compatibility
We can use the service provider to get instances of the class.
EmbeddedResourceLoader for load embedded resources.
An important condition is set the calling assembly by calling
SetExecutingAssembly
this is done in the Build method in the FormsBuild class
Platforms Affected
.NET Standards 2.0 required.
Links to the following NuGet are required.
Settings file should be added to the Forms project
Testing Procedure
Make sure that all test projects are launched as before.
PR Checklist