Skip to content
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

Merged
merged 32 commits into from
Mar 23, 2021
Merged

Using the Controls Application #550

merged 32 commits into from
Mar 23, 2021

Conversation

mattleibow
Copy link
Member

Description of Change

Merging application concepts and removing the Services property on the app instance.

@@ -6,6 +6,15 @@ namespace Microsoft.Maui.Controls.Compatibility
{
public static class AppHostBuilderExtensions
{
public static IAppHostBuilder RegisterCompatibilityForms(this IAppHostBuilder builder)
Copy link
Member Author

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

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()
Copy link
Member Author

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

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.

Copy link
Contributor

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?

Copy link
Member

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"]}");
Copy link
Member Author

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.

Comment on lines +134 to +135
if (ServiceProviderType.IsAssignableFrom(type))
return this;
Copy link
Member Author

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.

Copy link
Member

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

Copy link
Member Author

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

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!;
Copy link
Member Author

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

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?

src/Controls/src/Core/Registrar.cs Outdated Show resolved Hide resolved
{
Forms.Init(state);
Forms.Init(activationState);
Copy link
Contributor

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.

Copy link
Member

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

Copy link
Member Author

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.

Base automatically changed from startup to main March 22, 2021 14:45
@mattleibow mattleibow marked this pull request as ready for review March 22, 2021 18:05
@rmarinho rmarinho merged commit a47b35d into main Mar 23, 2021
@rmarinho rmarinho deleted the dev/new-applications branch March 23, 2021 12:03
@samhouts samhouts added area-core-hosting Extensions / Hosting / AppBuilder / Startup platform/android 🤖 platform/iOS 🍎 labels Jul 11, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Dec 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants