-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Using the Controls Application #550
Conversation
@@ -6,6 +6,15 @@ namespace Microsoft.Maui.Controls.Compatibility | |||
{ | |||
public static class AppHostBuilderExtensions | |||
{ | |||
public static IAppHostBuilder RegisterCompatibilityForms(this IAppHostBuilder builder) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the special place for now since we used to init things like Device.Info
and PlatformServices
in the Forms.Init
but that is currently running inside the Activity
. However, we are now creating apps form the Application
area.
Once we split all this stuff out of Forms
and into services then this can be removed.
{ | ||
public class MyApp : MauiApp | ||
public class MyApp : IApplication |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now the "pure" MAUI app that requires nothing from controls. It works, but we don't get the XAML and the resources and things.
if (UseXamlApp) | ||
{ | ||
appBuilder = appBuilder | ||
.RegisterCompatibilityForms() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The call here to fix the Android case with the early init requirements.
x:Class="MauiSampleApp.XamlApp"> | ||
<Application.Resources> | ||
<ResourceDictionary> | ||
<maui:Color x:Key="DotNetPurple">#512BD4</maui:Color> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is the XAML and Resources that David wanted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the maui namespace b/c we haven't updated the base xmlns yet?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we going to have both no? Add a new one for MAUI, but the old one also points to Maui.Controls
|
||
Services = services; | ||
|
||
Console.WriteLine($"The .NET Purple color is {Resources["DotNetPurple"]}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using XAML init and the Resources
prop.
if (ServiceProviderType.IsAssignableFrom(type)) | ||
return this; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hax for the IServiceProvider
in the ctor. Works for now, but might need a revist later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How will this work if you are using a factory to provide Other container, like for example the default Microsoft.Extensions.DependencyInjection ServiceCollection and ServiceProvider implementation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just did a test with the Microsoft.Extensions.DependencyInjection package and it also got injected. Was there a specific case that failed?
@@ -40,4 +36,18 @@ void ConfigureNativeServices(HostBuilderContext ctx, IServiceCollection services | |||
{ | |||
} | |||
} | |||
|
|||
public abstract class MauiApplication : Android.App.Application |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the real magic. Once the services and application is created, we set the statics here since there can ever only be a single running Android app. We need a non-generic base type because we need a way to get the Current
property. If we had a generic, then we also will need to pass the TStartup
everywhere.
Current = this; | ||
} | ||
|
||
public static MauiApplication Current { get; private set; } = null!; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Black magic with null!
where we swear that null
is not null
XD. But, in the real world this will always have a value since the app only can ever access this property once it has been set.
x:Class="MauiSampleApp.XamlApp"> | ||
<Application.Resources> | ||
<ResourceDictionary> | ||
<maui:Color x:Key="DotNetPurple">#512BD4</maui:Color> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the maui namespace b/c we haven't updated the base xmlns yet?
{ | ||
Forms.Init(state); | ||
Forms.Init(activationState); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this remain in the dev's code? I thought the HostBuilder took care of all this and we wouldn't see "Forms" anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I imagine once we get all the code inside Init
reorganized into better places this will go away. This is mainly here to make the shims and old code happy for the time being.
Though we'll probably want to give some guidance where users put 3rd party Init's for the time being
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also something that we can do if we have a way to register delegates for a pre build and post build run. Then also a delegate to run each activity. Users may want to do things when those events happen. This is all very likely covered by the lifecycle things already that @jsuarezruiz is doing in the #495 PR. We can hook into the various events and do this for the users. And then that can be the recommendation for library authors or the user can do manual init in there for old libs.
Description of Change
Merging application concepts and removing the
Services
property on the app instance.