Repository navigation
Updating .NET MAUI to use MauiApp/MauiAppBuilder pattern and use MS.Extensions.DependencyInjection - #2137
Conversation
7504f56 to
cf42e28
Compare
a997838 to
c36fd0a
Compare
|
All the stuff I said was un-done is now done. Support for IHost, IHostBuilder, custom DI, config is all done (by copying stuff from AspNetCore). I believe that all tests pass because they did pass locally not long ago, and CI seems fairly happy, aside from things that are flaky even in main. There is likely still some bug in the code anyway, which I will continue to hunt down. What's left now?
@Redth / @PureWeen / @rmarinho / @mattleibow / @davidfowl - I would love your feedback on what we've got here so that we can get this into RC1. |
|
And for fun I just tried using Autofac as the DI container and it seems to work great when I run in Android! I referred to the Autofac docs for ASP.NET Core because that's the pattern in this PR for .NET MAUI. I added a reference to this Autofac package: <PackageReference Include="Autofac.Extensions.DependencyInjection" Version="7.1.0" />And here's what I changed in Startup.cs to make use of Autofac: using Autofac;
using Autofac.Extensions.DependencyInjection;
...
public static MauiAppBuilder CreateAppBuilder()
{
var appBuilder = MauiApp.CreateBuilder();
// Before (with Microsoft.Extensions.DependencyInjection registration):
//appBuilder.Services.AddSingleton<ITextService, TextService>();
//appBuilder.Services.AddTransient<MainViewModel>();
appBuilder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory(containerBuilder =>
{
// After (with Autofac registration):
containerBuilder.RegisterType<TextService>().As<ITextService>().SingleInstance();
containerBuilder.RegisterType<MainViewModel>().AsSelf().InstancePerDependency();
}));
...
}And all the rest of the registrations in the app were done using MS.Ext.DI registration because it's mostly various .NET MAUI and Blazor stuff. |
|
@Eilon you can run device test by just launching those apps. It is just a normal maui app with a UI and everything. There is a "Run All" button. |
|
I just had a great meeting with @halter73 from the ASP.NET Core team to review some of the patterns here. These are my notes to investigate and implement from the feedback in this PR from various folks and also from my meeting with @halter73 .
|
|
Great things in that last comment! For the name we should at least have One thing that needs to be handled is the case on Android there are 2 parts: |
e015b40 to
13c0772
Compare
|
@mattleibow can we go with MauiNativeApplication => AppDelegate, Android.App.Application, Application for everything? Possibly even drop the Maui prefix? |
|
This is great. I love the more straightforward imperative feel. This gave me an idea for using top level statements. If the body of |
YES! YES! and maybe! We may want the Maui prefix to avoid clashes with other things the libraries do "Native" is very generic. But this is just my obsession with prefixes :) NativeApplication is actually fine. I just had to write out that my deep-rooted, but still light (I hope), OCD wants things. |
|
Not a fan of. the "Native" in the namings.. I think the most used api should be MauiApplication and MauiWindow in all platforms |
@mhutch Yes, this would be awesome! The idea was always to source gen the Activity/AppDelegate/etc parts eventually... Last I looked at the top level statements, I don't think that source gen has access to know its namespace/type/method to be able to call it? I had thought the same once this PR was started - it would be really nice to have a top level statements file be called from the Activity/AppDelegate/etc entry points... |
IIRC the generated main method cannot be called from C#, but I assumed (maybe incorrectly) that source generators could inspect the syntax tree of top level statements like they can other code. If a source generator can inspect the top level statements, it can generate a new method with those same statements (and appropriate Another aspect to consider is how we would return the user-created app object from the top level statements so the generated One way would be to generate a "return method" - a method the user must call on the app as the last toplevel statement. This could look like a mainloop, such as an |
…lder pattern - Support Min/Max Height/Width on IView (dotnet#2265) - Updating .NET MAUI to use MauiApp/MauiAppBuilder pattern and use MS.Extensions.DependencyInjection (dotnet#2137)
…lder pattern - Support Min/Max Height/Width on IView (dotnet#2265) - Updating .NET MAUI to use MauiApp/MauiAppBuilder pattern and use MS.Extensions.DependencyInjection (dotnet#2137)
…lder pattern - Support Min/Max Height/Width on IView (dotnet#2265) - Updating .NET MAUI to use MauiApp/MauiAppBuilder pattern and use MS.Extensions.DependencyInjection (dotnet#2137)
…lder pattern - Support Min/Max Height/Width on IView (dotnet#2265) - Updating .NET MAUI to use MauiApp/MauiAppBuilder pattern and use MS.Extensions.DependencyInjection (dotnet#2137)
…lder pattern - Support Min/Max Height/Width on IView (dotnet#2265) - Updating .NET MAUI to use MauiApp/MauiAppBuilder pattern and use MS.Extensions.DependencyInjection (dotnet#2137)
…lder pattern - Support Min/Max Height/Width on IView (dotnet#2265) - Updating .NET MAUI to use MauiApp/MauiAppBuilder pattern and use MS.Extensions.DependencyInjection (dotnet#2137)
…lder pattern - Support Min/Max Height/Width on IView (dotnet#2265) - Updating .NET MAUI to use MauiApp/MauiAppBuilder pattern and use MS.Extensions.DependencyInjection (dotnet#2137)
…lder pattern - Support Min/Max Height/Width on IView (dotnet#2265) - Updating .NET MAUI to use MauiApp/MauiAppBuilder pattern and use MS.Extensions.DependencyInjection (dotnet#2137)
…lder pattern - Support Min/Max Height/Width on IView (dotnet#2265) - Updating .NET MAUI to use MauiApp/MauiAppBuilder pattern and use MS.Extensions.DependencyInjection (dotnet#2137)
…lder pattern - Support Min/Max Height/Width on IView (dotnet#2265) - Updating .NET MAUI to use MauiApp/MauiAppBuilder pattern and use MS.Extensions.DependencyInjection (dotnet#2137)
…lder pattern - Support Min/Max Height/Width on IView (dotnet#2265) - Updating .NET MAUI to use MauiApp/MauiAppBuilder pattern and use MS.Extensions.DependencyInjection (dotnet#2137)
…lder pattern - Support Min/Max Height/Width on IView (dotnet#2265) - Updating .NET MAUI to use MauiApp/MauiAppBuilder pattern and use MS.Extensions.DependencyInjection (dotnet#2137)
…lder pattern - Support Min/Max Height/Width on IView (dotnet#2265) - Updating .NET MAUI to use MauiApp/MauiAppBuilder pattern and use MS.Extensions.DependencyInjection (dotnet#2137)
…lder pattern - Support Min/Max Height/Width on IView (dotnet#2265) - Updating .NET MAUI to use MauiApp/MauiAppBuilder pattern and use MS.Extensions.DependencyInjection (dotnet#2137)
…lder pattern - Support Min/Max Height/Width on IView (dotnet#2265) - Updating .NET MAUI to use MauiApp/MauiAppBuilder pattern and use MS.Extensions.DependencyInjection (dotnet#2137)
…lder pattern - Support Min/Max Height/Width on IView (dotnet#2265) - Updating .NET MAUI to use MauiApp/MauiAppBuilder pattern and use MS.Extensions.DependencyInjection (dotnet#2137)
…lder pattern - Support Min/Max Height/Width on IView (dotnet#2265) - Updating .NET MAUI to use MauiApp/MauiAppBuilder pattern and use MS.Extensions.DependencyInjection (dotnet#2137)
…lder pattern - Support Min/Max Height/Width on IView (dotnet#2265) - Updating .NET MAUI to use MauiApp/MauiAppBuilder pattern and use MS.Extensions.DependencyInjection (dotnet#2137)
…lder pattern - Support Min/Max Height/Width on IView (dotnet#2265) - Updating .NET MAUI to use MauiApp/MauiAppBuilder pattern and use MS.Extensions.DependencyInjection (dotnet#2137)
…lder pattern - Support Min/Max Height/Width on IView (dotnet#2265) - Updating .NET MAUI to use MauiApp/MauiAppBuilder pattern and use MS.Extensions.DependencyInjection (dotnet#2137)
…lder pattern - Support Min/Max Height/Width on IView (dotnet#2265) - Updating .NET MAUI to use MauiApp/MauiAppBuilder pattern and use MS.Extensions.DependencyInjection (dotnet#2137)
…lder pattern - Support Min/Max Height/Width on IView (dotnet#2265) - Updating .NET MAUI to use MauiApp/MauiAppBuilder pattern and use MS.Extensions.DependencyInjection (dotnet#2137)
…lder pattern - Support Min/Max Height/Width on IView (dotnet#2265) - Updating .NET MAUI to use MauiApp/MauiAppBuilder pattern and use MS.Extensions.DependencyInjection (dotnet#2137)
…lder pattern - Support Min/Max Height/Width on IView (dotnet#2265) - Updating .NET MAUI to use MauiApp/MauiAppBuilder pattern and use MS.Extensions.DependencyInjection (dotnet#2137)
…lder pattern - Support Min/Max Height/Width on IView (dotnet#2265) - Updating .NET MAUI to use MauiApp/MauiAppBuilder pattern and use MS.Extensions.DependencyInjection (dotnet#2137)
…lder pattern - Support Min/Max Height/Width on IView (dotnet#2265) - Updating .NET MAUI to use MauiApp/MauiAppBuilder pattern and use MS.Extensions.DependencyInjection (dotnet#2137)
…lder pattern - Support Min/Max Height/Width on IView (dotnet#2265) - Updating .NET MAUI to use MauiApp/MauiAppBuilder pattern and use MS.Extensions.DependencyInjection (dotnet#2137)
…lder pattern - Support Min/Max Height/Width on IView (dotnet#2265) - Updating .NET MAUI to use MauiApp/MauiAppBuilder pattern and use MS.Extensions.DependencyInjection (dotnet#2137)
…lder pattern - Support Min/Max Height/Width on IView (dotnet#2265) - Updating .NET MAUI to use MauiApp/MauiAppBuilder pattern and use MS.Extensions.DependencyInjection (dotnet#2137)
…lder pattern - Support Min/Max Height/Width on IView (dotnet#2265) - Updating .NET MAUI to use MauiApp/MauiAppBuilder pattern and use MS.Extensions.DependencyInjection (dotnet#2137)


What's new/different:
protected abstract MauiAppBuilder CreateAppBuilder();that is overridden in the user's app to create and return aMauiAppBuilder.IStartupinterface is removed, and the user's app startup is in a conventionalMauiProgramclass with a static method that creates the app builder and returns the builtMauiApp.MauiAppBuilderis akin to ASP.NET Core's WebApplicationBuilder and has properties, methods, and extension methods for setting up the app. For example, registering services, fonts, handlers, etc.Before:
After:
Please share feedback in this PR, either in general, or on specific lines of code.