Dispenser/DispenserCommon/Lazy/ServiceCollectionLazyExtend...

21 lines
542 B
C#
Raw Permalink Normal View History

2024-08-16 07:20:09 +00:00
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>)
{
}
}
}