using DotNetDDI.Options; using Microsoft.Extensions.DependencyInjection; namespace DotNetDDI.Integrations.Kea; public static class KeaFactoryServices { public static IServiceCollection AddKeaFactory(this IServiceCollection services) { services.AddTransient(); return services; } private class KeaFactory(IServiceProvider services) : IKeaFactory { private ObjectFactory? _cachedCreateHandler4; private ObjectFactory? _cachedCreateHandler6; private ObjectFactory? _cachedCreateWatcher; KeaDhcp4LeaseHandler IKeaFactory.CreateHandler4() { _cachedCreateHandler4 ??= ActivatorUtilities.CreateFactory([]); return _cachedCreateHandler4(services, null); } KeaDhcp6LeaseHandler IKeaFactory.CreateHandler6() { _cachedCreateHandler6 ??= ActivatorUtilities.CreateFactory([]); return _cachedCreateHandler6(services, null); } KeaDhcpLeaseWatcher IKeaFactory.CreateWatcher(IKeaDhcpLeaseHandler handler, KeaDhcpServerOptions options) { _cachedCreateWatcher ??= ActivatorUtilities.CreateFactory([typeof(IKeaDhcpLeaseHandler), typeof(KeaDhcpServerOptions)]); return _cachedCreateWatcher(services, [handler, options]); } } }