Too much to name... but damn, it got where we are needed
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace Hyperbar;
|
||||
|
||||
public class ServiceScopeFactory<TService>(IServiceScopeFactory serviceScopeFactory,
|
||||
ConcurrentDictionary<TService, IServiceScope> services) :
|
||||
IServiceScopeFactory<TService>
|
||||
where TService : notnull
|
||||
{
|
||||
public TService? Create(params object?[] parameters)
|
||||
{
|
||||
if (serviceScopeFactory.CreateScope() is IServiceScope serviceScope)
|
||||
{
|
||||
if (serviceScope.ServiceProvider.GetService<IServiceFactory>() is IServiceFactory serviceFactory)
|
||||
{
|
||||
if (serviceFactory.Create<TService>(parameters) is TService service)
|
||||
{
|
||||
services.TryAdd(service, serviceScope);
|
||||
return service;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user