Example #1
0
        /// <summary>
        /// Creates <see cref="IServiceContainer"/> by its configuration.
        /// </summary>
        /// <param name="section">IoC configuration section.</param>
        /// <param name="name">The name of container configuration to create container for.</param>
        /// <param name="parent">The parent container.</param>
        /// <returns>
        /// <see cref="IServiceContainer"/> for the specified named configuration.
        /// </returns>
        public static IServiceContainer Create(ConfigurationSection section, string name, IServiceContainer parent)
        {
            if (name.IsNullOrEmpty())
            {
                name = string.Empty;
            }

            ContainerElement configuration = section == null ? null : section.Containers[name];

            if (configuration == null)
            {
                configuration = new ContainerElement();
            }

            var registrations = new List <ServiceRegistration>();
            var typeRegistry  = new TypeRegistry(new ServiceTypeRegistrationProcessor());

            foreach (var typeRegistrationElement in configuration.Auto)
            {
                typeRegistry.Register(typeRegistrationElement.ToNative());
            }
            foreach (var type in typeRegistry)
            {
                registrations.AddRange(ServiceRegistration.CreateAll(type));
            }
            foreach (var serviceRegistrationElement in configuration.Explicit)
            {
                registrations.Add(serviceRegistrationElement.ToNative());
            }

            var currentParent = configuration.Parent.IsNullOrEmpty()
        ? parent
        : Create(section, configuration.Parent, parent);

            var containerType = configuration.Type.IsNullOrEmpty() ?
                                typeof(ServiceContainer) :
                                Type.GetType(configuration.Type);

            return(Create(containerType, registrations, currentParent));
        }
Example #2
0
 /// <summary>
 /// Creates <see cref="IServiceContainer"/> by its configuration.
 /// </summary>
 /// <param name="section">IoC configuration section.</param>
 /// <param name="name">The name of container configuration to create container for.</param>
 /// <returns>
 /// <see cref="IServiceContainer"/> for the specified named configuration.
 /// </returns>
 public static IServiceContainer Create(ConfigurationSection section, string name)
 {
     return(Create(section, name, null));
 }