OpenGenericRegistration
Describes an open-generic service registration.
using Stashbox.Utils;
using Stashbox.Utils.Data.Immutable;
using System;
using System.Runtime.CompilerServices;
namespace Stashbox.Registration
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public class OpenGenericRegistration : ServiceRegistration
{
private ImmutableTree<Type, ServiceRegistration> closedGenericRegistrations = ImmutableTree<Type, ServiceRegistration>.Empty;
internal OpenGenericRegistration(ServiceRegistration serviceRegistration)
: base(serviceRegistration.ImplementationType, serviceRegistration.Name, serviceRegistration.Lifetime, serviceRegistration.IsDecorator, serviceRegistration.Options, serviceRegistration.RegistrationId, serviceRegistration.RegistrationOrder)
{
}
internal ServiceRegistration ProduceClosedRegistration(Type requestedType)
{
ServiceRegistration orDefaultByRef = closedGenericRegistrations.GetOrDefaultByRef(requestedType);
if (orDefaultByRef != null)
return orDefaultByRef;
ServiceRegistration serviceRegistration = new ServiceRegistration(base.ImplementationType.MakeGenericType(requestedType.GetGenericArguments()), null, base.Lifetime, IsDecorator, Options, null, null);
if (!Swap.SwapValue<Type, ServiceRegistration, byte, byte, ImmutableTree<Type, ServiceRegistration>>(ref closedGenericRegistrations, (Type t1, ServiceRegistration t2, byte _, byte _, ImmutableTree<Type, ServiceRegistration> items) => items.AddOrUpdate(t1, t2, true, null), requestedType, serviceRegistration, 0, 0))
return closedGenericRegistrations.GetOrDefaultByRef(requestedType);
return serviceRegistration;
}
}
}