增加Prism 框架

This commit is contained in:
chfei committed 2026-08-31 16:28:23 +08:00
1 parent 2cd6b8db86
commit 726eb6de16
99 files changed
+12527

No files matched your search

@@ -0,0 +1,15 @@
using MAX.Core.Autofac;
using MAX.Core.DependencyInjection;
namespace MAX.Core.Infrastructure;
/// <summary>
/// 启动器:实现 <see cref="IDependencyRegistrar"/>,由宿主项目统一发现并按 <see cref="Priority"/> 排序执行。
/// </summary>
public interface IStartup : IDependencyRegistrar, IPriority
{
/// <summary>
/// 初始化
/// </summary>
void Initialize();
}
@@ -0,0 +1,42 @@
using System;
using System.Reflection;
namespace MAX.Core.Infrastructure;
/// <summary>
/// 单例,需要在当前类中定义
/// </summary>
/// <typeparam name="T"></typeparam>
public class SingleInstance<T> where T : class
{
private static readonly object lockObj = new();
private static T mySelf;//= default(T);
public static T Instance
{
get
{
lock (lockObj)
{
mySelf ??= InstanceCreator.CreateInstance<T>();
}
return mySelf;
}
}
}
public static class InstanceCreator
{
public static T CreateInstance<T>()
{
Type type = typeof(T);
try
{
return (T)type.Assembly.CreateInstance(type.FullName, true, BindingFlags.NonPublic | BindingFlags.Instance, null, null, null, null);
}
catch (MissingMethodException ex)
{
throw new Exception($"{ex.Message}\n(单例模式下,构造函数必须为 private)");
}
}
}