예제 #1
0
        internal IServiceManager GetServiceManager(
            IServiceConfiguration configuration,
            Type[] generics)
        {
            var key     = configuration.TypeFactory.MutateKey(configuration.Key, generics);
            var compKey = new ServiceConfigurationServiceConfigurationKey(configuration, key);

            IServiceManager manager;

            if (!_activeServices.TryGetValue(compKey, out manager))
            {
                manager = configuration.BuildServiceManager(this, generics);

                _activeServices.Add(compKey, manager);

                // Cache the primary service key if neccessary
                if (!_primaryActiveService.ContainsKey(key))
                {
                    _primaryActiveService.Add(key, manager);
                }

                // Attempt to cache all configuration cache keys. These must succeed. If an overlap is detected an exception will be thrown.
                foreach (ServiceConfigurationKey cacheKey in configuration.TypeFactory.MutateKeys(configuration.DefaultCacheKeys, generics))
                {
                    _primaryActiveService.Add(cacheKey, manager);
                }
            }

            return(manager);
        }