示例#1
0
        internal static UnityContainerElement GetContainer(string containerName)
        {
            if (_containers.ContainsKey(containerName))
            {
                return(_containers[containerName]);
            }

            UnityContainerElement unityContainerElement = null;

            UnityHelper.InitializeContainer();
            lock (UnityHelper._resolvedContainers)
            {
                IDictionary <string, UnityContainerElement> resolvedContainers = UnityHelper._resolvedContainers;
                if (!resolvedContainers.ContainsKey(containerName))
                {
                    Boolean bContainerFound = false;
                    UnityConfigurationSection unityConfigurationSection = null;
                    foreach (UnityConfigurationSection section in UnityHelper._unityConfigurationSections.Values)
                    {
                        if (section.Containers[containerName] != null)
                        {
                            bContainerFound           = true;
                            unityConfigurationSection = section;
                            break;
                        }
                        else
                        {
                            continue;
                        }
                    }

                    //IUnityContainer unityContainer = null;
                    if (bContainerFound)
                    {
                        unityContainerElement = unityConfigurationSection.Containers[containerName];
                        resolvedContainers.Add(containerName, unityContainerElement);
                    }
                    else
                    {
                        //unityContainer = UnityHelper._unityContainers[containerName];
                        unityContainerElement = resolvedContainers[containerName];
                    }
                }
                else
                {
                    unityContainerElement = resolvedContainers[containerName];
                }
            }

            _containers.Add(containerName, unityContainerElement);

            return(unityContainerElement);
        }
示例#2
0
        /// <summary>
        /// Resolves the container.
        /// </summary>
        /// <param name="containerName">Name of the container.</param>
        static public void ResolveContainer(string containerName)
        {
            UnityHelper.InitializeContainer();
            lock (UnityHelper._resolvedContainers)
            {
                IDictionary <string, UnityContainerElement> resolvedContainers = UnityHelper._resolvedContainers;
                if (!resolvedContainers.ContainsKey(containerName))
                {
                    Boolean bContainerFound = false;
                    UnityConfigurationSection unityConfigurationSection = null;
                    foreach (UnityConfigurationSection section in UnityHelper._unityConfigurationSections.Values)
                    {
                        if (section.Containers[containerName] != null)
                        {
                            bContainerFound           = true;
                            unityConfigurationSection = section;
                            break;
                        }
                        else
                        {
                            continue;
                        }
                    }

                    UnityContainerElement unityContainerElement = null;
                    IUnityContainer       unityContainer        = null;
                    if (bContainerFound)
                    {
                        unityContainerElement = unityConfigurationSection.Containers[containerName];
                        unityContainer        = new UnityContainer();
                        unityContainerElement.Configure(unityContainer);
                        UnityHelper._unityContainers.Add(containerName, unityContainer);
                        resolvedContainers.Add(containerName, unityContainerElement);
                    }
                    else
                    {
                        unityContainer        = UnityHelper._unityContainers[containerName];
                        unityContainerElement = resolvedContainers[containerName];
                        unityContainerElement.Configure(unityContainer);
                    }
                }
            }
        }