SingletonLifetime
Represents a singleton lifetime manager.
using Stashbox.Registration;
using Stashbox.Resolution;
using System;
using System.Linq.Expressions;
namespace Stashbox.Lifetime
{
public class SingletonLifetime : FactoryLifetimeDescriptor
{
protected override int LifeSpan { get; } = 20;
protected override Expression ApplyLifetime(Func<IResolutionScope, object> factory, ServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type resolveType)
{
return resolutionContext.CurrentContainerContext.RootScope.GetOrAddScopedObject(serviceRegistration.RegistrationId, serviceRegistration.SynchronizationObject, factory).AsConstant();
}
}
}