1
0
Fork 0
netddi/Services/Dhcp/DhcpWatcherFactoryServices.cs

27 lines
749 B
C#
Raw Normal View History

2025-01-29 23:53:57 +01:00
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<IDhcpWatcherFactory, DhcpWatcherFactory>();
return services;
}
private class DhcpWatcherFactory(IServiceProvider services) : IDhcpWatcherFactory
{
private ObjectFactory<KeaService>? _cachedKeaService;
KeaService IDhcpWatcherFactory.KeaService(KeaDhcpOptions options)
{
_cachedKeaService ??= ActivatorUtilities.CreateFactory<KeaService>([typeof(KeaDhcpOptions)]);
return _cachedKeaService(services, [options]);
}
}
}