private void Secure(Action doSomething)
        {
            bool lockWasTaken = false;
            var  temp         = kernel.LockObj;
            var  before       = Container.Options.AllowOverridingRegistrations;

            try {
                Monitor.Enter(temp, ref lockWasTaken);
                {
                    if (kernel.IsLocked)
                    {
                        Container       = SimpleInjectorKernelCreator.Clone(Container);
                        kernel.IsLocked = false;
                    }
                    Container.Options.AllowOverridingRegistrations = allowOverride;
                    System.Diagnostics.Debug.Assert(!kernel.IsLocked);
                    doSomething();
                }
            }
            finally {
                if (lockWasTaken)
                {
                    Monitor.Exit(temp);
                }
                Container.Options.AllowOverridingRegistrations = before;
            }
        }
Exemple #2
0
        internal SimpleInjectorKernel(Container kernel)
        {
            kernel      = SimpleInjectorKernelCreator.Clone(kernel);
            this.kernel = kernel;
            var before = kernel.Options.AllowOverridingRegistrations;

            try
            {
                kernel.Options.AllowOverridingRegistrations = true;
                kernel.RegisterSingleton <IKernel>(this);
            }
            catch (ActivationException err)
            {
                throw WrapExn(err);
            }
            finally
            {
                kernel.Options.AllowOverridingRegistrations = before;
            }
        }