using Microsoft.Extensions.DependencyInjection; namespace StabilityMatrix.Core.Helper; /// /// Lazy instance of a DI service. /// public class LazyInstance : Lazy where T : notnull { public LazyInstance(IServiceProvider serviceProvider) : base(serviceProvider.GetRequiredService) { } } public static class LazyInstanceServiceExtensions { /// /// Register to be used when resolving instances. /// public static IServiceCollection AddLazyInstance(this IServiceCollection services) { services.AddTransient(typeof(Lazy<>), typeof(LazyInstance<>)); return services; } }