Exemple #1
0
        public override object GetValue()
        {
            object result = _baseManager.GetValue();

            if (result == null)
            {
                result = _resolveDelegate();

                if (_baseManager != null)
                {
                    _baseManager.SetValue(result);
                }
            }

            return(result);
        }
Exemple #2
0
        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;
        }
Exemple #5
0
 public override void SetValue(object newValue, ILifetimeContainer container)
 => innerLifetime.SetValue(newValue);
Exemple #6
0
 public override void SetValue(object newValue)
 {
     innerLifetime.SetValue(newValue);
 }