Beispiel #1
0
        public static IUnityContainer Initialize(
            string configFileName = DefaultConfigurationFileName,
            string configSection  = DefaultConfigurationSectionName,
            string containerName  = DefaultContainerName,
            Func <string, string, UnityConfigurationSection> getConfigFileSection = null)
        {
            if (!_latch.Latched())
            {
                return(_root);
            }

            try
            {
                lock (_root)
                {
                    var unityConfigSection = getConfigFileSection != null
                                                ? getConfigFileSection(configFileName, configSection)
                                                : GetUnityConfigurationSection(configFileName, configSection);

                    // file was not specified or does not exist - try loading from web/app.config then
                    if (unityConfigSection == null)
                    {
                        unityConfigSection = ConfigurationManager.GetSection(configSection) as UnityConfigurationSection;
                    }

                    if (unityConfigSection != null)
                    {
                        if (string.IsNullOrWhiteSpace(containerName))
                        {
                            _root.LoadConfiguration(unityConfigSection);
                        }
                        else
                        {
                            _root.LoadConfiguration(unityConfigSection, containerName);
                        }
                    }

                    // initialize the CSL with Unity service location
                    if (!ServiceLocator.IsLocationProviderSet)
                    {
                        ServiceLocator.SetLocatorProvider(() => new UnityServiceLocator(_root));
                    }

                    // prepare for interception and policy injection (AOP)
                    _root.AddNewExtension <Interception>();

                    VmAspectsEventSource.Log.Trace("The DIContainer was initialized.", EventLevel.Verbose);
                    return(_root);
                }
            }
            catch (Exception x)
            {
                VmAspectsEventSource.Log.Exception(x, EventLevel.Critical);
                throw;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Initializes the repository.
        /// </summary>
        /// <returns>IRepository.</returns>
        public IRepository Initialize(Action query = null)
        {
            if (!_latch.Latched())
            {
                return(this);
            }

            Reset();
            query?.Invoke();
            _event.Set();
            return(this);
        }