From 9f94699bcbc03b3c8ddbddaae0738f89600ea712 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Fri, 10 Jun 2022 10:27:12 +0800 Subject: [PATCH] Update template --- .../MyCompanyName.MyProjectName/MainPage.xaml.cs | 10 +++++----- .../MyCompanyName.MyProjectName/MauiProgram.cs | 15 ++++++++++++--- .../MyCompanyName.MyProjectName.csproj | 10 ++++++++++ .../MyProjectNameModule.cs | 4 ---- .../MyCompanyName.MyProjectName/appsettings.json | 2 +- 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/templates/maui/src/MyCompanyName.MyProjectName/MainPage.xaml.cs b/templates/maui/src/MyCompanyName.MyProjectName/MainPage.xaml.cs index dfed23030a..4cd6345c7f 100644 --- a/templates/maui/src/MyCompanyName.MyProjectName/MainPage.xaml.cs +++ b/templates/maui/src/MyCompanyName.MyProjectName/MainPage.xaml.cs @@ -1,6 +1,8 @@ -namespace MyCompanyName.MyProjectName; +using Volo.Abp.DependencyInjection; -public partial class MainPage : ContentPage +namespace MyCompanyName.MyProjectName; + +public partial class MainPage : ContentPage, ISingletonDependency { private readonly HelloWorldService _helloWorldService; @@ -18,8 +20,7 @@ public partial class MainPage : ContentPage { HelloLab.Text = _helloWorldService.SayHello(); } - - + private void OnCounterClicked(object sender, EventArgs e) { count++; @@ -32,4 +33,3 @@ public partial class MainPage : ContentPage SemanticScreenReader.Announce(CounterBtn.Text); } } - diff --git a/templates/maui/src/MyCompanyName.MyProjectName/MauiProgram.cs b/templates/maui/src/MyCompanyName.MyProjectName/MauiProgram.cs index 1a5bddae0e..a0f1dd1cdf 100644 --- a/templates/maui/src/MyCompanyName.MyProjectName/MauiProgram.cs +++ b/templates/maui/src/MyCompanyName.MyProjectName/MauiProgram.cs @@ -1,6 +1,8 @@ using System.Reflection; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.FileProviders; using Volo.Abp; +using Volo.Abp.Autofac; namespace MyCompanyName.MyProjectName; @@ -8,7 +10,6 @@ public static class MauiProgram { public static MauiApp CreateMauiApp() { - var builder = MauiApp.CreateBuilder(); builder .UseMauiApp() @@ -16,11 +17,13 @@ public static class MauiProgram { fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold"); - }); + }) + .ConfigureContainer(new AbpAutofacServiceProviderFactory(new Autofac.ContainerBuilder())); + ConfigureConfiguration(builder); + builder.Services.AddApplication(options => { - options.UseAutofac(); options.Services.ReplaceConfiguration(builder.Configuration); }); @@ -30,4 +33,10 @@ public static class MauiProgram return app; } + + private static void ConfigureConfiguration(MauiAppBuilder builder) + { + var assembly = typeof(App).GetTypeInfo().Assembly; + builder.Configuration.AddJsonFile(new EmbeddedFileProvider(assembly), "appsettings.json", optional: false,false); + } } \ No newline at end of file diff --git a/templates/maui/src/MyCompanyName.MyProjectName/MyCompanyName.MyProjectName.csproj b/templates/maui/src/MyCompanyName.MyProjectName/MyCompanyName.MyProjectName.csproj index 7362d06897..7b0ed79b69 100644 --- a/templates/maui/src/MyCompanyName.MyProjectName/MyCompanyName.MyProjectName.csproj +++ b/templates/maui/src/MyCompanyName.MyProjectName/MyCompanyName.MyProjectName.csproj @@ -18,6 +18,7 @@ com.mycompanyname.myprojectname + 27317750-B571-4690-B433-B358B2480E01 1.0 @@ -34,6 +35,10 @@ + + + + @@ -52,5 +57,10 @@ + + + + + diff --git a/templates/maui/src/MyCompanyName.MyProjectName/MyProjectNameModule.cs b/templates/maui/src/MyCompanyName.MyProjectName/MyProjectNameModule.cs index 4506249857..2f8321f74f 100644 --- a/templates/maui/src/MyCompanyName.MyProjectName/MyProjectNameModule.cs +++ b/templates/maui/src/MyCompanyName.MyProjectName/MyProjectNameModule.cs @@ -6,8 +6,4 @@ namespace MyCompanyName.MyProjectName; [DependsOn(typeof(AbpAutofacModule))] public class MyProjectNameModule : AbpModule { - public override void ConfigureServices(ServiceConfigurationContext context) - { - context.Services.AddTransient(); - } } diff --git a/templates/maui/src/MyCompanyName.MyProjectName/appsettings.json b/templates/maui/src/MyCompanyName.MyProjectName/appsettings.json index 077404aaa4..f3b49375f5 100644 --- a/templates/maui/src/MyCompanyName.MyProjectName/appsettings.json +++ b/templates/maui/src/MyCompanyName.MyProjectName/appsettings.json @@ -1,3 +1,3 @@ { - + "AppName": "MyProjectName" } \ No newline at end of file