添加项目文件。
This commit is contained in:
1 parent
6a017c9547
commit
58abbb5b4f
86 files changed
+8729
No files matched your search
@@ -0,0 +1,13 @@
|
||||
namespace MAX.Core.DependencyInjection;
|
||||
|
||||
/// <summary>
|
||||
/// 依赖注册器:把当前模块的服务注册到 <see cref="IServiceRegistrar"/>。
|
||||
/// 底层使用哪个容器由宿主项目决定,MAX.Core 不引用任何容器。
|
||||
/// </summary>
|
||||
public interface IDependencyRegistrar
|
||||
{
|
||||
/// <summary>
|
||||
/// 注册服务
|
||||
/// </summary>
|
||||
void Register(IServiceRegistrar registrar);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace MAX.Core.DependencyInjection;
|
||||
|
||||
/// <summary>
|
||||
/// 作用域(每个 Scope/请求一个实例)
|
||||
/// </summary>
|
||||
public interface IScopedDependency
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
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,37 @@
|
||||
//using MAX.Core.Autofac;
|
||||
//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;
|
||||
// }
|
||||
//}
|
||||
Reference in new issue
Block a user