PerRequestLifetime
Represents a per-request lifetime.
using Stashbox.Registration;
using Stashbox.Resolution;
using Stashbox.Utils;
using System;
using System.Linq.Expressions;
using System.Runtime.CompilerServices;
namespace Stashbox.Lifetime
{
public class PerRequestLifetime : FactoryLifetimeDescriptor
{
internal override bool StoreResultInLocalVariable => true;
[System.Runtime.CompilerServices.NullableContext(1)]
protected override Expression ApplyLifetime(Func<IResolutionScope, IRequestContext, object> factory, ServiceRegistration serviceRegistration, ResolutionContext resolutionContext, TypeInformation typeInformation)
{
resolutionContext.RequestConfiguration.RequiresRequestContext = true;
return resolutionContext.RequestContextParameter.ConvertTo(TypeCache<IInternalRequestContext>.Type).CallMethod(Constants.GetOrAddInstanceMethod, serviceRegistration.GetDiscriminator(typeInformation, resolutionContext.CurrentContainerContext.ContainerConfiguration).AsConstant(), factory.AsConstant(), resolutionContext.CurrentScopeParameter);
}
}
}