예제 #1
0
        protected override void Dispose(bool disposing)
        {
            if (disposing && this.manager != null)
            {
                // EndLifetimeScope should not be called from a different thread than where it was started.
                // Calling this method from another thread could remove the wrong scope.
                if (this.initialThreadId != Thread.CurrentThread.ManagedThreadId)
                {
                    throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture,
                                                                      "It is not safe to use a LifetimeScope instance across threads. Make sure the " +
                                                                      "complete operation that the lifetime scope surrounds gets executed within the " +
                                                                      "same thread and make sure that the LifetimeScope instance gets disposed on the " +
                                                                      "same thread as it gets created. Dispose was called on thread with ManagedThreadId " +
                                                                      "{0}, but was created on thread with id {1}.", Thread.CurrentThread.ManagedThreadId,
                                                                      this.initialThreadId));
                }

                try
                {
                    base.Dispose(disposing);
                }
                finally
                {
                    try
                    {
                        this.manager.RemoveLifetimeScope(this);
                    }
                    finally
                    {
                        this.manager = null;
                    }
                }
            }
        }
예제 #2
0
        protected override void Dispose(bool disposing)
        {
            if (disposing && this.manager != null)
            {
                // EndLifetimeScope should not be called from a different thread than where it was started.
                // Calling this method from another thread could remove the wrong scope.
                if (this.initialThreadId != Thread.CurrentThread.ManagedThreadId)
                {
                    throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture,
                                                                      "It is not safe to use a LifetimeScope instance across threads. The LifetimeScope " +
                                                                      "instance was disposed on thread id {0} but was created on thread id {1}. " +
                                                                      "Make sure the complete operation that the lifetime scope surrounds gets executed " +
                                                                      "within the same thread and make sure that the LifetimeScope instance gets " +
                                                                      "disposed on the same thread as it gets created. In case your intention is to " +
                                                                      "create a scope that flows with the logical flow of control of asynchronous " +
                                                                      "methods, please switch to the ExecutionContextScopeLifestyle. Please goto " +
                                                                      "https://simpleinjector.org/await" + " for more information on this lifestyle.",
                                                                      Thread.CurrentThread.ManagedThreadId, this.initialThreadId));
                }
            }

            try
            {
                base.Dispose(disposing);
            }
            finally
            {
                if (disposing && this.manager != null)
                {
                    try
                    {
                        this.manager.RemoveLifetimeScope(this);
                    }
                    finally
                    {
                        this.manager = null;
                    }
                }
            }
        }
예제 #3
0
 internal LifetimeScope(LifetimeScopeManager manager, LifetimeScope parentScope) : base(manager.Container)
 {
     this.manager = manager;
     this.ParentScope = parentScope;
 }
        protected override void Dispose(bool disposing)
        {
            if (disposing && this.manager != null)
            {
                // EndLifetimeScope should not be called from a different thread than where it was started.
                // Calling this method from another thread could remove the wrong scope.
                if (this.initialThreadId != Thread.CurrentThread.ManagedThreadId)
                {
                    throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture,
                        "It is not safe to use a LifetimeScope instance across threads. Make sure the " +
                        "complete operation that the lifetime scope surrounds gets executed within the " +
                        "same thread and make sure that the LifetimeScope instance gets disposed on the " +
                        "same thread as it gets created. Dispose was called on thread with ManagedThreadId " +
                        "{0}, but was created on thread with id {1}.", Thread.CurrentThread.ManagedThreadId,
                        this.initialThreadId));
                }
            }

            try
            {
                base.Dispose(disposing);
            }
            finally
            {
                if (disposing && this.manager != null)
                {
                    try
                    {
                        this.manager.RemoveLifetimeScope(this);
                    }
                    finally
                    {
                        this.manager = null;
                    }
                }
            }
        }
 internal LifetimeScope(LifetimeScopeManager manager, LifetimeScope parentScope)
 {
     this.manager = manager;
     this.ParentScope = parentScope;
     this.initialThreadId = Thread.CurrentThread.ManagedThreadId;
 }
예제 #6
0
 internal LifetimeScope(LifetimeScopeManager manager, LifetimeScope parentScope)
 {
     this.manager = manager;
     this.ParentScope = parentScope;
 }
예제 #7
0
 internal LifetimeScope(LifetimeScopeManager manager, LifetimeScope parentScope)
 {
     this.manager     = manager;
     this.ParentScope = parentScope;
 }
예제 #8
0
 internal LifetimeScope(LifetimeScopeManager manager, LifetimeScope parentScope)
 {
     this.manager         = manager;
     this.ParentScope     = parentScope;
     this.initialThreadId = Thread.CurrentThread.ManagedThreadId;
 }
예제 #9
0
        protected override void Dispose(bool disposing)
        {
            if (disposing && this.manager != null)
            {
                // EndLifetimeScope should not be called from a different thread than where it was started.
                // Calling this method from another thread could remove the wrong scope.
                if (this.initialThreadId != Thread.CurrentThread.ManagedThreadId)
                {
                    throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture,
                        "It is not safe to use a LifetimeScope instance across threads. The LifetimeScope " +
                        "instance was disposed on thread id {0} but was created on thread id {1}. " +
                        "Make sure the complete operation that the lifetime scope surrounds gets executed " +
                        "within the same thread and make sure that the LifetimeScope instance gets " +
                        "disposed on the same thread as it gets created. In case your intention is to " +
                        "create a scope that flows with the logical flow of control of asynchronous " +
                        "methods, please switch to the ExecutionContextScopeLifestyle. Please goto " +
                        "https://simpleinjector.org/await" + " for more information on this lifestyle.",
                        Thread.CurrentThread.ManagedThreadId, this.initialThreadId));
                }
            }

            try
            {
                base.Dispose(disposing);
            }
            finally
            {
                if (disposing && this.manager != null)
                {
                    try
                    {
                        this.manager.RemoveLifetimeScope(this);
                    }
                    finally
                    {
                        this.manager = null;
                    }
                }
            }
        }
예제 #10
0
 internal LifetimeScope(LifetimeScopeManager manager, LifetimeScope parentScope) : base(manager.Container)
 {
     this.manager     = manager;
     this.ParentScope = parentScope;
 }