Catel.IoC.ServiceLocator.IsTypeRegisteredAsSingleton C# (CSharp) Method

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 bool IsTypeRegisteredAsSingleton(Type serviceType, object tag = null)
        {
            lock (_lockObject)
            {
                // Required to support the MissingTypeEventArgs
                if (!IsTypeRegistered(serviceType, tag))
                {
                    return false;
                }

                var serviceInfo = new ServiceInfo(serviceType, tag);


                if (_registeredInstances.ContainsKey(serviceInfo))
                {
                    return _registeredInstances[serviceInfo].RegistrationType == RegistrationType.Singleton;
                }

                if (_registeredTypes.ContainsKey(serviceInfo))
                {
                    return _registeredTypes[serviceInfo].RegistrationType == RegistrationType.Singleton;
                }
            }

            return false;
        }

Usage Example

コード例 #1
0
        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);
                }
            }
        }
All Usage Examples Of Catel.IoC.ServiceLocator::IsTypeRegisteredAsSingleton