增加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,8 @@
namespace MAX.Core.DependencyInjection;
/// <summary>
/// 作用域(每个 Scope/请求一个实例)
/// </summary>
public interface IScopedDependency
{
}
@@ -0,0 +1,81 @@
//using System;
//namespace MAX.Core.DependencyInjection;
///// <summary>
///// 依赖注册抽象(由 MAX.Core 自己定义,不依赖任何第三方 DI 容器)。
///// 具体实现由宿主项目提供,内部适配外部容器(Autofac、Microsoft.Extensions.DependencyInjection 等)。
///// </summary>
//public interface IServiceRegistrar
//{
// /// <summary>
// /// 注册单例:<typeparamref name="TImplementation"/> 实现 <typeparamref name="TService"/>
// /// </summary>
// void RegisterSingleton<TService, TImplementation>() where TService : class where TImplementation : class, TService;
// /// <summary>
// /// 注册单例实例
// /// </summary>
// void RegisterSingleton<TService>(TService instance) where TService : class;
// /// <summary>
// /// 注册单例(匿名工厂)
// /// </summary>
// void RegisterSingleton<TService>(Func<IServiceProvider, TService> factory) where TService : class;
// /// <summary>
// /// 注册单例(key):<typeparamref name="TImplementation"/> 实现 <typeparamref name="TService"/>
// /// </summary>
// void RegisterSingleton<TService, TImplementation>(object? serviceKey) where TService : class where TImplementation : class, TService;
// /// <summary>
// /// 注册单例实例(key)
// /// </summary>
// void RegisterSingleton<TService>(object? serviceKey, TService instance) where TService : class;
// /// <summary>
// /// 注册单例(key + 匿名工厂)
// /// </summary>
// void RegisterSingleton<TService>(object? serviceKey, Func<IServiceProvider, object?, TService> factory) where TService : class;
// /// <summary>
// /// 注册作用域生命周期
// /// </summary>
// void RegisterScoped<TService, TImplementation>() where TService : class where TImplementation : class, TService;
// /// <summary>
// /// 注册作用域生命周期(匿名工厂)
// /// </summary>
// void RegisterScoped<TService>(Func<IServiceProvider, TService> factory) where TService : class;
// /// <summary>
// /// 注册作用域生命周期(key):<typeparamref name="TImplementation"/> 实现 <typeparamref name="TService"/>
// /// </summary>
// void RegisterScoped<TService, TImplementation>(object? serviceKey) where TService : class where TImplementation : class, TService;
// /// <summary>
// /// 注册作用域生命周期(key + 匿名工厂)
// /// </summary>
// void RegisterScoped<TService>(object? serviceKey, Func<IServiceProvider, object?, TService> factory) where TService : class;
// /// <summary>
// /// 注册瞬时生命周期
// /// </summary>
// void RegisterTransient<TService, TImplementation>() where TService : class where TImplementation : class, TService;
// /// <summary>
// /// 注册瞬时生命周期(匿名工厂)
// /// </summary>
// void RegisterTransient<TService>(Func<IServiceProvider, TService> factory) where TService : class;
// /// <summary>
// /// 注册瞬时生命周期(key):<typeparamref name="TImplementation"/> 实现 <typeparamref name="TService"/>
// /// </summary>
// void RegisterTransient<TService, TImplementation>(object? serviceKey) where TService : class where TImplementation : class, TService;
// /// <summary>
// /// 注册瞬时生命周期(key + 匿名工厂)
// /// </summary>
// void RegisterTransient<TService>(object? serviceKey, Func<IServiceProvider, object?, TService> factory) where TService : class;
//}
@@ -0,0 +1,8 @@
namespace MAX.Core.DependencyInjection;
/// <summary>
/// 单例
/// </summary>
public interface ISingletonDependency
{
}
@@ -0,0 +1,8 @@
namespace MAX.Core.DependencyInjection;
/// <summary>
/// 每次实例化
/// </summary>
public interface ITransientDependency
{
}
@@ -0,0 +1,36 @@
using MAX.Core.Infrastructure;
using System;
using System.Collections.Concurrent;
namespace MAX.Core.DependencyInjection;
public interface ILazyServiceProvider
{
object LazyGetService(Type serviceType);
T LazyGetService<T>();
}
public class LazyServiceProvider : SingleInstance<LazyServiceProvider>, ILazyServiceProvider
{
protected ConcurrentDictionary<Type, Lazy<object>> CachedServices { get; }
private LazyServiceProvider()
{
CachedServices = new ConcurrentDictionary<Type, Lazy<object>>();
}
public virtual T LazyGetService<T>()
{
return (T)LazyGetService(typeof(T));
}
public virtual object LazyGetService(Type serviceType)
{
return GetService(serviceType);
}
public virtual object GetService(Type serviceType)
{
return CachedServices.GetOrAdd(
serviceType,
_ => new Lazy<object>(() => IocManager.Resolve(serviceType))
).Value;
}
}