コード例 #1
0
ファイル: ServiceLocatorFacts.cs プロジェクト: pars87/Catel
            public void ExportsBothInstancesAndTypes()
            {
                var serviceLocator = new ServiceLocator();
                serviceLocator.AutomaticallyKeepContainersSynchronized = false;

                var ninjectContainer = new StandardKernel();

                serviceLocator.RegisterExternalContainer(ninjectContainer);
                serviceLocator.RegisterInstance<ITestInterface>(new TestClass1());
                serviceLocator.RegisterType<INotifyPropertyChanged, TestClass1>();

                serviceLocator.RegisterExternalContainer(ninjectContainer);

                Assert.IsFalse(ninjectContainer.GetBindings(typeof(INotifyPropertyChanged)).Any());
                Assert.IsFalse(ninjectContainer.GetBindings(typeof(ITestInterface)).Any());
                Assert.IsTrue(serviceLocator.IsTypeRegistered<ITestInterface>());

                serviceLocator.ExportToExternalContainers();

                Assert.IsTrue(ninjectContainer.GetBindings(typeof(INotifyPropertyChanged)).Any());
                Assert.IsTrue(ninjectContainer.GetBindings(typeof(ITestInterface)).Any());
                Assert.IsTrue(serviceLocator.IsTypeRegistered<ITestInterface>());
            }