Stashbox by Peter Csajtai

<PackageReference Include="Stashbox" Version="2.9.0-preview-523" />

 ScopedLifetime

Represents a scoped lifetime.
using Stashbox.BuildUp; using Stashbox.Registration; using Stashbox.Resolution; using Stashbox.Utils; using System; using System.Linq.Expressions; namespace Stashbox.Lifetime { public class ScopedLifetime : ScopedLifetimeBase { public override ILifetime Create() { return new ScopedLifetime(); } public override Expression GetExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, IObjectBuilder objectBuilder, ResolutionContext resolutionContext, Type resolveType) { ParameterExpression knownVariableOrDefault = resolutionContext.GetKnownVariableOrDefault(ScopeId); if (knownVariableOrDefault != null) return knownVariableOrDefault; Expression factoryExpression = GetFactoryExpression(containerContext, serviceRegistration, objectBuilder, resolutionContext, resolveType); if (factoryExpression == null) return null; Expression expression = resolutionContext.CurrentScopeParameter.CallMethod(Constants.GetOrAddScopedItemMethod, ScopeId.AsConstant(), Sync.AsConstant(), factoryExpression).ConvertTo(resolveType); return StoreExpressionIntoLocalVariable(expression, resolutionContext, resolveType); } } }