Ejemplo n.º 1
0
            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>());
            }