21 lines
542 B
C#
21 lines
542 B
C#
|
using Microsoft.Extensions.DependencyInjection;
|
||
|
|
||
|
namespace DispenserCommon.Lazy;
|
||
|
|
||
|
public static class IServiceCollectionExtendtions
|
||
|
{
|
||
|
public static IServiceCollection AddLazyResolution(this IServiceCollection services)
|
||
|
{
|
||
|
return services.AddTransient(
|
||
|
typeof(Lazy<>),
|
||
|
typeof(LazilyResolved<>));
|
||
|
}
|
||
|
|
||
|
private class LazilyResolved<T> : Lazy<T>
|
||
|
{
|
||
|
public LazilyResolved(IServiceProvider serviceProvider)
|
||
|
: base(serviceProvider.GetRequiredService<T>)
|
||
|
{
|
||
|
}
|
||
|
}
|
||
|
}
|