27 lines
749 B
C#
27 lines
749 B
C#
|
|
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]);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|