public object Resolve(Type type, ILifeTimeScope lifeTimeScope)
        {
            lock (_lockObject)
            {
                var previousLifeTimeScope = _currentLifeTimeScope;
                try
                {
                    _currentLifeTimeScope = lifeTimeScope as AutofacLifeTimeScope;

                    if (_currentLifeTimeScope == null)
                    {
                        // We should be getting only life time scopes that were created by this class.
                        var errorMessage = string.Format("The value of parameter '{0}' is invalid in '{1}.{2}()'. Expected an object of type '{3}'. Actual type of the object is '{4}'.",
                                                         nameof(lifeTimeScope), GetType().FullName, nameof(Resolve),
                                                         typeof(AutofacLifeTimeScope), lifeTimeScope.GetType());

                        LogHelper.Context.Log.Error(errorMessage);

                        throw new ArgumentException(errorMessage, nameof(lifeTimeScope));
                    }

                    return(_currentLifeTimeScope.Resolve(type));
                }
                finally
                {
                    _currentLifeTimeScope = previousLifeTimeScope;
                }
            }
        }
Exemple #2
0
        public object Resolve(Type type, ILifeTimeScope lifeTimeScope)
        {
            // TODO (future improvement): Log resolutions based on configuration in new element
            // <diagnostics><logTypeResolutions>
            // Also, use an interceptor for IDiContainer (wrapper), which will do additional diagnostics, such us storing the time of the last
            // type that we tried to resolve (and which is still being resolved), and will show a warning, if the object was being resolved for more than couple
            // of seconds (along with the thread Id, and possibly the stack trace)
            //if (LogHelper.Context.Log.IsDebugEnabled)
            //    LogHelper.Context.Log.Debug($"Resolving type {type.FullName}. Thread Id is {Thread.CurrentThread.ManagedThreadId}.");

            lock (_lockObject)
            {
                var previousLifeTimeScope = CurrentLifeTimeScope;
                try
                {
                    CurrentLifeTimeScope = lifeTimeScope;
                    return(Kernel.Get(type));
                }
                finally
                {
                    CurrentLifeTimeScope = previousLifeTimeScope;
                    //if (LogHelper.Context.Log.IsDebugEnabled)
                    //    LogHelper.Context.Log.Debug($"Did resolve type {type.FullName}. Thread Id is {Thread.CurrentThread.ManagedThreadId}.");
                }
            }
        }
 public T Resolve <T>(ILifeTimeScope lifeTimeScope) where T : class
 {
     return((T)Resolve(typeof(T), lifeTimeScope));
 }
 public JobPerformer(ILifeTimeScope scope)
 {
     _scope = scope;
 }
 public LifeTimeScopeTerminatedEventArgs([NotNull] ILifeTimeScope lifeTimeScope)
 {
     LifeTimeScope = lifeTimeScope;
 }