Migrate existing code
This commit is contained in:
parent
384ff4a6f3
commit
9b49f880a2
30 changed files with 1789 additions and 5 deletions
39
Integrations/Kea/KeaFactoryServices.cs
Normal file
39
Integrations/Kea/KeaFactoryServices.cs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
using DotNetDDI.Options;
|
||||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace DotNetDDI.Integrations.Kea;
|
||||
|
||||
public static class KeaFactoryServices
|
||||
{
|
||||
public static IServiceCollection AddKeaFactory(this IServiceCollection services)
|
||||
{
|
||||
services.AddTransient<IKeaFactory, KeaFactory>();
|
||||
return services;
|
||||
}
|
||||
|
||||
private class KeaFactory(IServiceProvider services) : IKeaFactory
|
||||
{
|
||||
private ObjectFactory<KeaDhcp4LeaseHandler>? _cachedCreateHandler4;
|
||||
private ObjectFactory<KeaDhcp6LeaseHandler>? _cachedCreateHandler6;
|
||||
private ObjectFactory<KeaDhcpLeaseWatcher>? _cachedCreateWatcher;
|
||||
|
||||
KeaDhcp4LeaseHandler IKeaFactory.CreateHandler4()
|
||||
{
|
||||
_cachedCreateHandler4 ??= ActivatorUtilities.CreateFactory<KeaDhcp4LeaseHandler>([]);
|
||||
return _cachedCreateHandler4(services, null);
|
||||
}
|
||||
|
||||
KeaDhcp6LeaseHandler IKeaFactory.CreateHandler6()
|
||||
{
|
||||
_cachedCreateHandler6 ??= ActivatorUtilities.CreateFactory<KeaDhcp6LeaseHandler>([]);
|
||||
return _cachedCreateHandler6(services, null);
|
||||
}
|
||||
|
||||
KeaDhcpLeaseWatcher IKeaFactory.CreateWatcher(IKeaDhcpLeaseHandler handler, KeaDhcpServerOptions options)
|
||||
{
|
||||
_cachedCreateWatcher ??= ActivatorUtilities.CreateFactory<KeaDhcpLeaseWatcher>([typeof(IKeaDhcpLeaseHandler), typeof(KeaDhcpServerOptions)]);
|
||||
return _cachedCreateWatcher(services, [handler, options]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue