public void ResolvesInstancesOfTypeRegisteredWithSingletonParameterToFalseFromNinjectContainer() { var serviceLocator = new ServiceLocator(); var standardKernel = new StandardKernel(); serviceLocator.RegisterExternalContainer(standardKernel); serviceLocator.RegisterType<ITestInterface, TestClass1>(registrationType: RegistrationType.Transient); Assert.AreNotSame(standardKernel.Get<ITestInterface>(), standardKernel.Get<ITestInterface>()); }
public void ResolvesInstancesOfTypeRegisteredWithSingletonParameterToTrueFromWindsorContainer() { var serviceLocator = new ServiceLocator(); var windsorContainer = new WindsorContainer(); serviceLocator.RegisterExternalContainer(windsorContainer); serviceLocator.RegisterType<ITestInterface, TestClass1>(); Assert.AreSame(windsorContainer.Resolve<ITestInterface>(), windsorContainer.Resolve<ITestInterface>()); }
public void ResolvesInstancesOfTypeRegisteredWithSingletonParameterToFalseFromUnityContainer() { var serviceLocator = new ServiceLocator(); var unityContainer = new UnityContainer(); serviceLocator.RegisterExternalContainer(unityContainer); serviceLocator.RegisterType<ITestInterface, TestClass1>(registrationType: RegistrationType.Transient); Assert.AreNotSame(unityContainer.Resolve<ITestInterface>(), unityContainer.Resolve<ITestInterface>()); }
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>()); }
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>()); }
public void ResolvesSameInstanceFromBothContainers() { var unityContainer = new UnityContainer(); var serviceLocator = new ServiceLocator(); serviceLocator.AutomaticallyKeepContainersSynchronized = true; serviceLocator.RegisterExternalContainer(unityContainer); serviceLocator.RegisterTypeIfNotYetRegistered<IMessageService, MessageService>(); var ns1 = unityContainer.Resolve<IMessageService>(); var ns2 = serviceLocator.ResolveType<IMessageService>(); Assert.AreEqual(ns1, ns2); }
public void AutomaticSynchronization_ResolveType() { var serviceLocator = new ServiceLocator(); serviceLocator.AutomaticallyKeepContainersSynchronized = false; serviceLocator.RegisterType<ITestInterface, TestClass1>(); var ninjectContainer = new StandardKernel(); serviceLocator.RegisterExternalContainer(ninjectContainer); serviceLocator.AutomaticallyKeepContainersSynchronized = true; serviceLocator.ResolveType<ITestInterface>(); Assert.IsTrue(ninjectContainer.GetBindings(typeof(ITestInterface)).Any()); }
public void AutomaticSynchronization_RegisterIfTypeNotYetRegistered() { var serviceLocator = new ServiceLocator(); var ninjectContainer = new StandardKernel(); serviceLocator.RegisterExternalContainer(ninjectContainer); serviceLocator.RegisterTypeIfNotYetRegistered<ITestInterface, TestClass1>(); Assert.IsTrue(ninjectContainer.GetBindings(typeof(ITestInterface)).Any()); }
public void AutomaticSynchronization_RegisterInstance() { var serviceLocator = new ServiceLocator(); var ninjectContainer = new StandardKernel(); serviceLocator.RegisterExternalContainer(ninjectContainer); serviceLocator.RegisterInstance<ITestInterface>(new TestClass1()); Assert.IsTrue(ninjectContainer.GetBindings(typeof(ITestInterface)).Any()); }
public void RegisterExternalContainer_ValidContainerAndTestTypeRetrieval() { var serviceLocator = new ServiceLocator(); var ninjectContainer = new StandardKernel(); serviceLocator.RegisterExternalContainer(ninjectContainer); ninjectContainer.Bind<ITestInterface>().To<TestClass1>(); Assert.IsTrue(serviceLocator.IsTypeRegistered(typeof(ITestInterface))); }
public void RegisterExternalContainer_ExternalContainerNull() { var serviceLocator = new ServiceLocator(); ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => serviceLocator.RegisterExternalContainer(null)); }
public void ResolveType_RegisteredInExternalContainer() { var serviceLocator = new ServiceLocator(); var ninjectContainer = new StandardKernel(); serviceLocator.RegisterExternalContainer(ninjectContainer); ninjectContainer.Bind<ITestInterface>().To<TestClass1>(); var instance = serviceLocator.ResolveType<ITestInterface>(); Assert.IsInstanceOfType(instance, typeof(TestClass1)); }