forked from ddrilling/AsbCloudServer
CS2-127 Add lazy service registration.
This commit is contained in:
parent
04052af874
commit
5c63c086ad
@ -8,6 +8,7 @@ using AsbCloudInfrastructure.Services.WellOperationService;
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace AsbCloudInfrastructure
|
namespace AsbCloudInfrastructure
|
||||||
{
|
{
|
||||||
@ -66,5 +67,17 @@ namespace AsbCloudInfrastructure
|
|||||||
|
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IServiceCollection AddTransientLazy<TService, TImplementation>(this IServiceCollection services)
|
||||||
|
where TService : class
|
||||||
|
where TImplementation : class, TService
|
||||||
|
=> services.AddTransient<TService, TImplementation>()
|
||||||
|
.AddTransient(provider => new Lazy<TService>(provider.GetService<TService>));
|
||||||
|
|
||||||
|
public static IServiceCollection AddTransientLazy<TService, TImplementation>(this IServiceCollection services, Func<IServiceProvider, TImplementation> implementationFactory)
|
||||||
|
where TService : class
|
||||||
|
where TImplementation : class, TService
|
||||||
|
=> services.AddTransient<TService, TImplementation>(implementationFactory)
|
||||||
|
.AddTransient(provider => new Lazy<TService>(() => implementationFactory(provider)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user