Пример #1
0
         public virtual void DisposeService2Test()
         {
             bool disposed = false;
             
             using (var ioc = new Container())
             {
                 var registration = ioc.As<ITestDisposable>().Use<MockDisposableClass>(ioc); //as singleton /* AccordConatiner implements IPersunScope*/
                 registration.BeforeRelease += (sender, args) => {args.RunDispose = false;}; //=externě vlastněná

                 ITestDisposable a = ioc.GetService<ITestDisposable>();
                 a.BeforeDisposeAction =
                     delegate
                     {
                         disposed = true;
                     };

                 Assert.IsTrue(ioc.IsConfiguredFor(typeof(ITestDisposable)));

                 ioc.DisposeService(typeof(ITestDisposable));

                 Assert.IsFalse(disposed); //nesmí být disposnuta, i byl plugin zrušen
                 Assert.IsFalse(ioc.IsConfiguredFor(typeof(ITestDisposable)));
             }
            
         }
Пример #2
0
        public virtual void DisposeServiceTest()
        {
            bool disposed = false;
            using (var ioc = new Container())
            {
                ioc.As<ITestDisposable>().Use<MockDisposableClass>(ioc); //as singleton /* AccordConatiner implements IPersunScope*/
                var a = ioc.GetService<ITestDisposable>();
                a.BeforeDisposeAction = 
                    delegate 
                    { 
                        disposed = true; 
                    };

                Assert.IsTrue(ioc.IsConfiguredFor(typeof(ITestDisposable)));

                ioc.DisposeService(typeof(ITestDisposable));

                Assert.IsTrue(disposed);
                Assert.IsFalse(ioc.IsConfiguredFor(typeof(ITestDisposable)));
            }
        }