public override object GetValue() { object result = _baseManager.GetValue(); if (result == null) { result = _resolveDelegate(); if (_baseManager != null) { _baseManager.SetValue(result); } } return(result); }
public override void PostBuildUp(ref BuilderContext context) { LifetimeManager policy = null; if (context.Registration is ContainerRegistration registration) { policy = registration.LifetimeManager; } if (null == policy || policy is PerResolveLifetimeManager) { policy = (LifetimeManager)context.Get(typeof(LifetimeManager)); } policy?.SetValue(context.Existing, context.Lifetime); }
public InstanceRegistration(UnityContainer owner, Type?type, string?name, object?instance, LifetimeManager manager) : base(owner, name, instance?.GetType() ?? type) { // If Disposable register with the container if (manager is IDisposable disposableManager) { owner.Context.Lifetime.Add(disposableManager); } // Setup Manager manager.InUse = true; manager.SetValue(instance, owner.Context.Lifetime); LifetimeManager = manager; ResolveDelegate <PipelineContext> resolver = (ref PipelineContext context) => throw new InvalidOperationException("Instance value no longer available"); Set(typeof(ResolveDelegate <PipelineContext>), resolver); }
public InstanceRegistration(UnityContainer owner, Type?type, string?name, object?instance, LifetimeManager manager) : base(owner, name, instance?.GetType() ?? type) { // If Disposable register with the container if (manager is IDisposable disposableManager) { owner.Context.Lifetime.Add(disposableManager); } // Setup Manager manager.InUse = true; manager.SetValue(instance, owner.Context.Lifetime); Pipeline = (ref BuilderContext context) => throw new InvalidOperationException("Instance value no longer available"); //Pipeline = manager switch //{ // ExternallyControlledLifetimeManager _ => ExternalLifetime, // _ => (ResolveDelegate<BuilderContext>)OtherLifetime //}; LifetimeManager = manager; }
public override void SetValue(object newValue, ILifetimeContainer container) => innerLifetime.SetValue(newValue);
public override void SetValue(object newValue) { innerLifetime.SetValue(newValue); }