添加项目文件。
This commit is contained in:
1 parent
6a017c9547
commit
58abbb5b4f
86 files changed
+8729
No files matched your search
@@ -0,0 +1,88 @@
|
||||
using MAX.Core.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace StoreHub.Framework.DependencyInjection
|
||||
{
|
||||
/// <summary>
|
||||
/// 将 <see cref="IServiceRegistrar"/> 适配到 Microsoft.Extensions.DependencyInjection
|
||||
/// </summary>
|
||||
internal sealed class ServiceRegistrarProxy : IServiceRegistrar
|
||||
{
|
||||
private readonly IServiceCollection _services;
|
||||
|
||||
public ServiceRegistrarProxy(IServiceCollection services)
|
||||
{
|
||||
_services = services;
|
||||
}
|
||||
|
||||
public void RegisterSingleton<TService, TImplementation>() where TService : class where TImplementation : class, TService
|
||||
{
|
||||
_services.AddSingleton<TService, TImplementation>();
|
||||
}
|
||||
|
||||
public void RegisterSingleton<TService>(TService instance) where TService : class
|
||||
{
|
||||
_services.AddSingleton(instance);
|
||||
}
|
||||
|
||||
public void RegisterSingleton<TService>(Func<IServiceProvider, TService> factory) where TService : class
|
||||
{
|
||||
_services.AddSingleton(factory);
|
||||
}
|
||||
|
||||
public void RegisterSingleton<TService, TImplementation>(object? serviceKey) where TService : class where TImplementation : class, TService
|
||||
{
|
||||
_services.AddKeyedSingleton<TService, TImplementation>(serviceKey);
|
||||
}
|
||||
|
||||
public void RegisterSingleton<TService>(object? serviceKey, TService instance) where TService : class
|
||||
{
|
||||
_services.AddKeyedSingleton(serviceKey, instance);
|
||||
}
|
||||
|
||||
public void RegisterSingleton<TService>(object? serviceKey, Func<IServiceProvider, object?, TService> factory) where TService : class
|
||||
{
|
||||
_services.AddKeyedSingleton(serviceKey, factory);
|
||||
}
|
||||
|
||||
public void RegisterScoped<TService, TImplementation>() where TService : class where TImplementation : class, TService
|
||||
{
|
||||
_services.AddScoped<TService, TImplementation>();
|
||||
}
|
||||
|
||||
public void RegisterScoped<TService>(Func<IServiceProvider, TService> factory) where TService : class
|
||||
{
|
||||
_services.AddScoped(factory);
|
||||
}
|
||||
|
||||
public void RegisterScoped<TService, TImplementation>(object? serviceKey) where TService : class where TImplementation : class, TService
|
||||
{
|
||||
_services.AddKeyedScoped<TService, TImplementation>(serviceKey);
|
||||
}
|
||||
|
||||
public void RegisterScoped<TService>(object? serviceKey, Func<IServiceProvider, object?, TService> factory) where TService : class
|
||||
{
|
||||
_services.AddKeyedScoped(serviceKey, factory);
|
||||
}
|
||||
|
||||
public void RegisterTransient<TService, TImplementation>() where TService : class where TImplementation : class, TService
|
||||
{
|
||||
_services.AddTransient<TService, TImplementation>();
|
||||
}
|
||||
|
||||
public void RegisterTransient<TService>(Func<IServiceProvider, TService> factory) where TService : class
|
||||
{
|
||||
_services.AddTransient(factory);
|
||||
}
|
||||
|
||||
public void RegisterTransient<TService, TImplementation>(object? serviceKey) where TService : class where TImplementation : class, TService
|
||||
{
|
||||
_services.AddKeyedTransient<TService, TImplementation>(serviceKey);
|
||||
}
|
||||
|
||||
public void RegisterTransient<TService>(object? serviceKey, Func<IServiceProvider, object?, TService> factory) where TService : class
|
||||
{
|
||||
_services.AddKeyedTransient(serviceKey, factory);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user