using DotNetDDI.Integrations.Kea; using DotNetDDI.Options; using Microsoft.Extensions.DependencyInjection; namespace DotNetDDI.Services.Dhcp; public static class DhcpWatcherFactoryServices { public static IServiceCollection AddDhcpWatcherFactory(this IServiceCollection services) { services.AddTransient(); return services; } private class DhcpWatcherFactory(IServiceProvider services) : IDhcpWatcherFactory { private ObjectFactory? _cachedKeaService; KeaService IDhcpWatcherFactory.KeaService(KeaDhcpOptions options) { _cachedKeaService ??= ActivatorUtilities.CreateFactory([typeof(KeaDhcpOptions)]); return _cachedKeaService(services, [options]); } } }