示例#1
0
            public void ExportInstancesToExternalContainers_ExternalContainerHasNoInstanceRegistered()
            {
                var serviceLocator = new ServiceLocator();
                serviceLocator.AutomaticallyKeepContainersSynchronized = false;

                var ninjectContainer = new StandardKernel();

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

                serviceLocator.RegisterExternalContainer(ninjectContainer);

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

                serviceLocator.ExportInstancesToExternalContainers();

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