惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
Google Developers Blog
Google DeepMind News
Google DeepMind News
Microsoft Security Blog
Microsoft Security Blog
Martin Fowler
Martin Fowler
MyScale Blog
MyScale Blog
The GitHub Blog
The GitHub Blog
I
InfoQ
A
About on SuperTechFans
GbyAI
GbyAI
宝玉的分享
宝玉的分享
爱范儿
爱范儿
博客园 - 【当耐特】
博客园 - 司徒正美
博客园 - 聂微东
P
Proofpoint News Feed
WordPress大学
WordPress大学
云风的 BLOG
云风的 BLOG
Last Week in AI
Last Week in AI
阮一峰的网络日志
阮一峰的网络日志
B
Blog RSS Feed
Jina AI
Jina AI
aimingoo的专栏
aimingoo的专栏
J
Java Code Geeks
博客园 - 叶小钗

博客园 - 毛毛虫

[Maui] Windows部署 [Maui] 造轮子——LoggerSqlite [Maui] 造轮子——Exception处理 [Maui] 造轮子——MessageBox [Maui] 造轮子——前言、本地化 [C#] 日积月累 [.net10] 极简数据库对象关系映射 [C#] 扩展Enumerable,实现类似Sqlserver的窗口函数lag [Blazor] 学习随笔——呈现约定 [Blazor] 学习随笔——生命周期 [Blazor] 学习随笔——RZ10012警告的处理 [Blazor WebAssembly] 学习随笔——组件1.微信弹框(WXDialog) [Blazor WebAssembly] 学习随笔——身份验证 Asp.net Help ASP.NET Web 应用 Docker踩坑历程——续 [Net6]自己写个消息推送 Docker批处理笔记 Asp.net6.0 Swagger使用备忘 ASP.NET Web 应用 Docker踩坑历程
[Maui] 轮子——插件式开发
毛毛虫 · 2026-03-10 · via 博客园 - 毛毛虫

想法是主程序尽量的简单,其他的尽量按需调用。

所以把Demo这个主程序的内容大部分移到LunZi.Common项目去了。

  1. Demo的MauiProgram
      public static MauiApp CreateMauiApp()
      {
    
          try
          {
              var assembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(@"C:\Plugin\windows\LunZi.Common.dll");
    
              var type = assembly.GetType("LunZi.Common.MauiProgram");
              var method = type!.GetMethod("CreateMauiApp", BindingFlags.Static | BindingFlags.Public);
              var app = (MauiApp)method!.Invoke(null, null)!;
              return app;
          }
          catch (Exception ex)
          {
    
              var builder = MauiApp.CreateBuilder();
              builder.UseMauiApp<App>();
    
              var msg = ex.Message + "\r\n" + ex.StackTrace;
              if (ex.InnerException != null)
                  msg += "\r\n-----------InnerException--------------------\r\n" + ex.InnerException.ToString();
    
              builder.Services.AddSingleton(ii => new MainPage(msg));
              return builder.Build();
          }
      }
    
    
  2. LunZi.Common的MauiProgram
      public static class MauiProgram
      {
          public static List<string> AssemblyNames { get; set; } = new();
          public static MauiApp CreateMauiApp()
          {
              AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
    
              return Create();
          }
    
          private static MauiApp Create()
          {
              var builder = MauiApp.CreateBuilder();
              builder
                  .UseMauiApp<App>()
                  .UseMauiCommunityToolkit()
                  .UseMauiCommunityToolkitMarkup()
              .ConfigureFonts(fonts =>
              {
                  fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
                  fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
              });
    
    
              builder.AddLunZiService();
              var app = builder.Build();
              app.InitializeLunZi();
              return app;
          }
    
    
          private static Assembly? CurrentDomain_AssemblyResolve(object? sender, ResolveEventArgs args)
          {
              var name = args.Name.Split(',')[0].Trim();
    
              string fullName = Path.Combine(@"c:\plugin\packages", name.EndsWith(".resources") ? Thread.CurrentThread.CurrentCulture.Name : "", name + ".dll");
              if (File.Exists(fullName))
              {
                  AssemblyNames.Add(name);
                  return AssemblyLoadContext.Default.LoadFromAssemblyPath(fullName);
              }
              else
                  return default;
          }
      }
    
    

以后Demo将基本不动,只要修改LunZi.Common,增加其他类库。想着公司刚好要开发Maui的程序,接一下就以公司产品为例,折腾折腾这个插件开发。

哦,我公司是开发酒店自助入住程序的,所以将会有这么一些插件

image