public IsTypeRegistered ( |
||
serviceType | The type of the service. | |
tag | object | The tag to register the service with. The default value is |
return | bool |
public void InitializeServiceLocatorFromNonDefaultConfiguration() { Configuration openExeConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); var configurationSection = openExeConfiguration.GetSection<IoCConfigurationSection>("ioc", "catel"); var serviceLocatorConfiguration = configurationSection.GetServiceLocatorConfiguration("test"); Assert.IsNotNull(serviceLocatorConfiguration); var serviceLocator = new ServiceLocator(); serviceLocatorConfiguration.Configure(serviceLocator); Assert.AreEqual(serviceLocatorConfiguration.SupportDependencyInjection, serviceLocator.SupportDependencyInjection); foreach (Registration registration in serviceLocatorConfiguration) { serviceLocator.IsTypeRegistered(registration.InterfaceType); if (registration.RegistrationType == RegistrationType.Singleton) { serviceLocator.IsTypeRegisteredAsSingleton(registration.InterfaceType); } } }
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 ResolveType_UnregisteredType() { var serviceLocator = new ServiceLocator(); Assert.IsFalse(serviceLocator.IsTypeRegistered<ITestInterface>()); ExceptionTester.CallMethodAndExpectException<NotSupportedException>(() => serviceLocator.ResolveType(typeof(ITestInterface))); }
public void ResolveType_Generic() { var serviceLocator = new ServiceLocator(); serviceLocator.RegisterType<ITestInterface, TestClass1>(); Assert.IsTrue(serviceLocator.IsTypeRegistered<ITestInterface>()); Assert.IsInstanceOfType(serviceLocator.ResolveType<ITestInterface>(), typeof(TestClass1)); }
public void ResoleType_Generic_SingletonLifestyle() { var serviceLocator = new ServiceLocator(); serviceLocator.RegisterType<ITestInterface, TestClass1>(); Assert.IsTrue(serviceLocator.IsTypeRegistered<ITestInterface>()); var firstInstance = serviceLocator.ResolveType<ITestInterface>(); Assert.IsInstanceOfType(firstInstance, typeof(TestClass1)); var secondInstance = serviceLocator.ResolveType<ITestInterface>(); Assert.IsInstanceOfType(secondInstance, typeof(TestClass1)); Assert.AreSame(firstInstance, secondInstance); }
public void AllowsTheSameInterfaceDefinedTwiceWithDifferentTags() { var serviceLocator = new ServiceLocator(); serviceLocator.RegisterType(typeof(ITestInterface), typeof(TestClass1), "1"); serviceLocator.RegisterType(typeof(ITestInterface), typeof(TestClass1), "2"); Assert.IsFalse(serviceLocator.IsTypeRegistered(typeof(ITestInterface))); Assert.IsTrue(serviceLocator.IsTypeRegistered(typeof(ITestInterface), "1")); Assert.IsTrue(serviceLocator.IsTypeRegistered(typeof(ITestInterface), "2")); }
public void DoesNotRegisterTheImplementationTypesAsTheInterfaceTypesByDefault() { var serviceLocator = new ServiceLocator(); Assert.IsFalse(serviceLocator.IsTypeRegistered<IFooService>()); Assert.IsFalse(serviceLocator.IsTypeRegistered<IFooService2>()); }
public void RegistersTheImplementationTypesAsInterfaceTypesIfIsSetToTrue() { var serviceLocator = new ServiceLocator { AutoRegisterTypesViaAttributes = true }; Assert.IsTrue(serviceLocator.IsTypeRegistered<IFooService>()); Assert.IsTrue(serviceLocator.IsTypeRegisteredAsSingleton<IFooService>()); Assert.IsTrue(serviceLocator.IsTypeRegistered<IFooService2>()); Assert.IsFalse(serviceLocator.IsTypeRegisteredAsSingleton<IFooService2>()); var resolveType = serviceLocator.ResolveType<IFooService>(); Assert.IsInstanceOfType(resolveType, typeof(FooService)); var resolveType2 = serviceLocator.ResolveType<IFooService2>(); Assert.IsInstanceOfType(resolveType2, typeof(FooService2)); }
public void RegisterInstance_Valid() { var serviceLocator = new ServiceLocator(); serviceLocator.RegisterInstance<ITestInterface>(new TestClass1 { Name = "My Instance" }); Assert.IsTrue(serviceLocator.IsTypeRegistered<ITestInterface>()); var instance = serviceLocator.ResolveType<ITestInterface>(); Assert.AreEqual("My Instance", instance.Name); }
public void IsTypeRegistered_UnregisteredTypeRegisteredViaMissingTypeEvent() { var serviceLocator = new ServiceLocator(); Assert.IsFalse(serviceLocator.IsTypeRegistered(typeof(ITestInterface))); serviceLocator.MissingType += (sender, e) => e.ImplementingType = typeof(TestClass1); Assert.IsTrue(serviceLocator.IsTypeRegistered(typeof(ITestInterface))); }
public void IsTypeRegistered_RegisteredAsTypeInServiceLocator() { var serviceLocator = new ServiceLocator(); serviceLocator.RegisterType<ITestInterface, TestClass1>(); Assert.IsTrue(serviceLocator.IsTypeRegistered(typeof(ITestInterface))); }
public void IsTypeRegistered_RegisteredAsInstanceInServiceLocator() { var serviceLocator = new ServiceLocator(); serviceLocator.RegisterInstance<ITestInterface>(new TestClass1()); Assert.IsTrue(serviceLocator.IsTypeRegistered(typeof(ITestInterface))); }
public void IsTypeRegistered_UnregisteredTypeRegisteredInstanceViaMissingType() { var serviceLocator = new ServiceLocator(); serviceLocator.MissingType += (sender, args) => { args.ImplementingInstance = new TestClass1(); }; Assert.IsTrue(serviceLocator.IsTypeRegistered(typeof(ITestInterface))); }
public void IsTypeRegistered_UnregisteredType() { var serviceLocator = new ServiceLocator(); Assert.IsFalse(serviceLocator.IsTypeRegistered(typeof(ITestInterface))); }
public void IsTypeRegistered_Null() { var serviceLocator = new ServiceLocator(); ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => serviceLocator.IsTypeRegistered(null)); }
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 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 RegisterType_Valid() { var serviceLocator = new ServiceLocator(); serviceLocator.RegisterType<ITestInterface, TestClass1>(); Assert.IsTrue(serviceLocator.IsTypeRegistered<ITestInterface>()); }
public void DoesNotRegisterTheImplementationTypesAsTheInterfaceTypesIfIsSetToFalse() { var serviceLocator = new ServiceLocator { AutoRegisterTypesViaAttributes = false }; Assert.IsFalse(serviceLocator.IsTypeRegistered<IFooService>()); Assert.IsFalse(serviceLocator.IsTypeRegistered<IFooService2>()); }
public void ResoleType_Of_Non_Registered_Non_Abstract_Class_Without_Registration() { var serviceLocator = new ServiceLocator(); var dependencyInjectionTestClass = serviceLocator.ResolveType<DependencyInjectionTestClass>(); Assert.IsNotNull(dependencyInjectionTestClass); Assert.IsFalse(serviceLocator.IsTypeRegistered(typeof(DependencyInjectionTestClass))); }
public void DoesNotRegisterAModuleIfModuleManagerDoesNotNotifyThe100PercentOfLoadProgress() { var serviceLocator = new ServiceLocator(); var moduleManagerMock = new Mock<IModuleManager>(); moduleManagerMock.Setup(manager => manager.Run()).Raises(manager => manager.ModuleDownloadProgressChanged += null, new ModuleDownloadProgressChangedEventArgs(new ModuleInfo("FooModule", typeof(FooModule).FullName), 100, 50)); serviceLocator.RegisterInstance<IModuleManager>(moduleManagerMock.Object); new FooBootstrapper(serviceLocator).Run(); Assert.IsFalse(serviceLocator.IsTypeRegistered<FooModule>()); }
public void ResoleType_Generic_TransientLifestyle() { var serviceLocator = new ServiceLocator(); serviceLocator.RegisterType<ITestInterface, TestClass1>(registrationType: RegistrationType.Transient); Assert.IsTrue(serviceLocator.IsTypeRegistered<ITestInterface>()); var firstInstance = serviceLocator.ResolveType<ITestInterface>(); Assert.IsInstanceOfType(firstInstance, typeof(TestClass1)); var secondInstance = serviceLocator.ResolveType<ITestInterface>(); Assert.IsInstanceOfType(secondInstance, typeof(TestClass1)); Assert.AreNotSame(firstInstance, secondInstance); }