IsTypeRegisteredAsSingleton() public method

Determines whether the specified service type is registered as singleton.
public IsTypeRegisteredAsSingleton ( Type serviceType, object tag = null ) : bool
serviceType System.Type The service type.
tag object The tag to register the service with. The default value is null.
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);
                }
            }
        }
示例#2
0
            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));
            }
示例#3
0
            public void TheIsTypeRegisteredAsSingleton_RegisteredInstanceViaMissingTypeEvent()
            {
                var serviceLocator = new ServiceLocator();
                serviceLocator.MissingType += (sender, args) =>
                {
                    args.ImplementingInstance = new TestClass1();
                    // NOTE: This value will be ignored, read the docs.
                    args.RegistrationType = RegistrationType.Transient;
                };

                Assert.IsTrue(serviceLocator.IsTypeRegisteredAsSingleton(typeof(ITestInterface)));
            }
示例#4
0
 public void TheIsTypeRegisteredAsSingleton_RegisteredTypeViaMissingTypeEvent()
 {
     var serviceLocator = new ServiceLocator();
     serviceLocator.MissingType += (sender, args) =>
         {
             args.ImplementingType = typeof(TestClass1);
             args.RegistrationType = RegistrationType.Transient;
         };
     Assert.IsFalse(serviceLocator.IsTypeRegisteredAsSingleton(typeof(ITestInterface)));
 }
示例#5
0
 public void TheIsTypeRegisteredAsSingleton_UnRegisteredType()
 {
     var serviceLocator = new ServiceLocator();
     Assert.IsFalse(serviceLocator.IsTypeRegisteredAsSingleton(typeof(ITestInterface)));
 }
示例#6
0
 public void TheIsTypeRegisteredAsSingleton_NonSingleton()
 {
     var serviceLocator = new ServiceLocator();
     serviceLocator.RegisterType<ITestInterface, TestClass1>(registrationType: RegistrationType.Transient);
     Assert.IsFalse(serviceLocator.IsTypeRegisteredAsSingleton(typeof(ITestInterface)));
 }
示例#7
0
 public void TheIsTypeRegisteredAsSingleton_Generic()
 {
     var serviceLocator = new ServiceLocator();
     serviceLocator.RegisterType<ITestInterface, TestClass1>();
     Assert.IsTrue(serviceLocator.IsTypeRegisteredAsSingleton<ITestInterface>());
 }