Exemplo n.º 1
0
        private object Activate(IEnumerable <Parameter> parameters)
        {
            ComponentRegistration.RaisePreparing(this, ref parameters);

            try
            {
                _newInstance = ComponentRegistration.Activator.ActivateInstance(this, parameters);
            }
            catch (Exception ex)
            {
                throw new DependencyResolutionException(String.Format(CultureInfo.CurrentCulture, ComponentActivationResources.ErrorDuringActivation, this.ComponentRegistration), ex);
            }

            if (ComponentRegistration.Ownership == InstanceOwnership.OwnedByLifetimeScope)
            {
                // The fact this adds instances for disposal agnostic of the activator is
                // important. The ProvidedInstanceActivator will NOT dispose of the provided
                // instance once the instance has been activated - assuming that it will be
                // done during the lifetime scope's Disposer executing.
                var instanceAsDisposable = _newInstance as IDisposable;
                if (instanceAsDisposable != null)
                {
                    _activationScope.Disposer.AddInstanceForDisposal(instanceAsDisposable);
                }
            }

            ComponentRegistration.RaiseActivating(this, parameters, ref _newInstance);

            return(_newInstance);
        }
Exemplo n.º 2
0
        private object Activate(IEnumerable <Parameter> parameters, out object decoratorTarget)
        {
            ComponentRegistration.RaisePreparing(this, ref parameters);

            var resolveParameters = parameters as Parameter[] ?? parameters.ToArray();

            try
            {
                decoratorTarget = _newInstance = ComponentRegistration.Activator.ActivateInstance(this, resolveParameters);

                ComponentRegistration.RaiseActivating(this, resolveParameters, ref _newInstance);

                _newInstance = InstanceDecorator.TryDecorateRegistration(
                    _service,
                    ComponentRegistration,
                    _newInstance,
                    _activationScope,
                    resolveParameters);
            }
            catch (ObjectDisposedException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw PropagateActivationException(this.ComponentRegistration.Activator, ex);
            }

            if (ComponentRegistration.Ownership == InstanceOwnership.OwnedByLifetimeScope)
            {
                // The fact this adds instances for disposal agnostic of the activator is
                // important. The ProvidedInstanceActivator will NOT dispose of the provided
                // instance once the instance has been activated - assuming that it will be
                // done during the lifetime scope's Disposer executing.
                if (decoratorTarget is IDisposable instanceAsDisposable)
                {
                    _activationScope.Disposer.AddInstanceForDisposal(instanceAsDisposable);
                }
                else if (decoratorTarget is IAsyncDisposable asyncDisposableInstance)
                {
                    _activationScope.Disposer.AddInstanceForAsyncDisposal(asyncDisposableInstance);
                }
            }

            if (_newInstance != decoratorTarget)
            {
                ComponentRegistration.RaiseActivating(this, resolveParameters, ref _newInstance);
            }

            return(_newInstance);
        }
Exemplo n.º 3
0
        private object Activate(IEnumerable <Parameter> parameters)
        {
            ComponentRegistration.RaisePreparing(this, ref parameters);

            _newInstance = ComponentRegistration.Activator.ActivateInstance(this, parameters);

            if (ComponentRegistration.Ownership == InstanceOwnership.OwnedByLifetimeScope)
            {
                // The fact this adds instances for disposal agnostic of the activator is
                // important. The ProvidedInstanceActivator will NOT dispose of the provided
                // instance once the instance has been activated - assuming that it will be
                // done during the lifetime scope's Disposer executing.
                var instanceAsDisposable = _newInstance as IDisposable;
                if (instanceAsDisposable != null)
                {
                    _activationScope.Disposer.AddInstanceForDisposal(instanceAsDisposable);
                }
            }

            ComponentRegistration.RaiseActivating(this, parameters, ref _newInstance);

            return(_newInstance);
        }