public bool HasResolvedLifetime(Type type, string name) { NamedTypeBuildKey key = new NamedTypeBuildKey(type, name); ILifetimePolicy lifetimePolicy = Context.Policies.Get <ILifetimePolicy>(key); if (lifetimePolicy != null) { return(lifetimePolicy.GetValue() != null); } return(false); }
public override void PreBuildUp(IBuilderContext context) { Guard.ArgumentNotNull(context, "context"); if (context.Existing == null) { ILifetimePolicy lifetimePolicy = GetLifetimePolicy(context); IRequiresRecovery recovery = lifetimePolicy as IRequiresRecovery; if (recovery != null) { context.RecoveryStack.Add(recovery); } object existing = lifetimePolicy.GetValue(); if (existing != null) { context.Existing = existing; context.BuildComplete = true; } } }
/// <summary> /// Called during the chain of responsibility for a build operation. The /// PreBuildUp method is called when the chain is being executed in the /// forward direction. /// </summary> /// <param name="context">Context of the build operation.</param> // FxCop suppression: Validation is done by Guard class public override void PreBuildUp(IBuilderContext context) { Guard.ArgumentNotNull(context, "context"); if (context.Existing != null) { return; } IPolicyList containingPolicyList; ILifetimePolicy lifetimePolicy = GetLifetimePolicy(context, out containingPolicyList); var scope = lifetimePolicy as IScopeLifetimePolicy; if (null != scope && !ReferenceEquals(containingPolicyList, context.PersistentPolicies)) { lifetimePolicy = scope.CreateScope() as ILifetimePolicy; context.PersistentPolicies.Set(lifetimePolicy, context.BuildKey); context.Lifetime.Add(lifetimePolicy); } IRequiresRecovery recovery = lifetimePolicy as IRequiresRecovery; if (recovery != null) { context.RecoveryStack.Add(recovery); } object existing = lifetimePolicy.GetValue(); if (existing != null) { context.Existing = existing; context.BuildComplete = true; } }