Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign up[WIP] Fluent API + Micosoft.Extensions.Hosting for initialization of Xamarin.Forms #8220
Conversation
This comment has been minimized.
This comment has been minimized.
@samhouts @jsuarezruiz @jfversluis Can I ask you to run the tests please? |
This comment has been minimized.
This comment has been minimized.
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 |
This comment has been minimized.
This comment has been minimized.
I added System.Threading.Tasks.Extensions @jfversluis can you run build please? |
This comment has been minimized.
This comment has been minimized.
@jfversluis can you run build one more time? sorry for this :( seems I found real error |
This comment has been minimized.
This comment has been minimized.
Maybe I need to do something with nuspec? @jfversluis |
This comment has been minimized.
This comment has been minimized.
Can you run the build again @jfversluis? I already added the link wherever possible. |
This comment has been minimized.
This comment has been minimized.
I added some tests, @jfversluis can you please run the build when you have time. |
This comment has been minimized.
This comment has been minimized.
Triggered another build. I don't think that adding another enhancement to this PR is really something we want though. This one is big enough as it is, no need to make it bigger. This will only make it harder for us to review and thus is will take longer. Please keep your PRs as small as possible :) |
This comment has been minimized.
This comment has been minimized.
Thanks @jfversluis :) this PR uses EmbeddedResourceLoader to load appsettings.json so this is part of this PR. |
This comment has been minimized.
This comment has been minimized.
this is strange, all errors remained, although I already added links to all projects. |
This comment has been minimized.
This comment has been minimized.
I added links to Nuget which were in error, @jfversluis can I ask you to run the build again? |
This comment has been minimized.
This comment has been minimized.
this is so strange, I added all package links :( |
This comment has been minimized.
This comment has been minimized.
If someone knows what is wrong with NuGet I will be happy for any help |
This comment has been minimized.
This comment has been minimized.
anaximander23
commented
Nov 19, 2019
I'd love something like this - in fact, I wrote my own mini-framework on top of Xamarin.Forms that does exactly this. It's on GitHub, and while it's still in its infancy, there's enough there for you to see the rough pattern. For example, this is how you initialise the app:
Seeing a syntax like this become part of Xamarin.Forms itself would be great. |
This comment has been minimized.
This comment has been minimized.
Basically, all the code is ready but I found that UWP is using .net standard 1.0 and for work I need .net standard 2.0 |
This comment has been minimized.
This comment has been minimized.
I think we're not going to drop netstandard1 anytime soon there #8570 |
This comment has been minimized.
This comment has been minimized.
@jfversluis Microsoft.Extensions.Hosting is only for .netstandard 2.0 so this is a problem. |
This comment has been minimized.
This comment has been minimized.
@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 commentedOct 25, 2019
•
edited
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