Stashbox by Peter Csajtai

<PackageReference Include="Stashbox" Version="5.0.1" />

 PerRequestLifetime

Represents a per-request lifetime.
using Stashbox.Registration; using Stashbox.Resolution; using Stashbox.Utils; using System; using System.Linq.Expressions; namespace Stashbox.Lifetime { public class PerRequestLifetime : FactoryLifetimeDescriptor { private protected override bool StoreResultInLocalVariable => true; protected override Expression ApplyLifetime(Func<IResolutionScope, IRequestContext, object> factory, ServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type resolveType) { resolutionContext.RequestConfiguration.RequiresRequestContext = true; return resolutionContext.RequestContextParameter.ConvertTo(Constants.PerRequestInstanceHolderType).CallMethod(Constants.GetOrAddInstanceMethod, serviceRegistration.RegistrationId.AsConstant(), factory.AsConstant(), resolutionContext.CurrentScopeParameter).ConvertTo(resolveType); } } }