Files
2026-08-14 18:00:58 +08:00

81 lines
3.2 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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;
}