IContainer ConfigureContainer(string configFile)
 {
     var fullFilename =  @"Configuration\" + configFile + ".config";
     var csr = new ConfigurationSettingsReader(ConfigurationSettingsReader.DefaultSectionName, fullFilename);
     var builder = new ContainerBuilder();
     builder.RegisterModule(csr);
     return builder.Build();
 }
        /// <summary>
        /// Override to add registrations to the container.
        /// </summary>
        /// <param name="builder">The builder.</param>
        protected override void Load(ContainerBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }

            Assembly defaultAssembly = null;

            if (!string.IsNullOrEmpty(_sectionHandler.DefaultAssembly))
            {
                defaultAssembly = Assembly.Load(_sectionHandler.DefaultAssembly);
            }

            foreach (ModuleElement moduleElement in _sectionHandler.Modules)
            {
                var moduleType      = LoadType(moduleElement.Type, defaultAssembly);
                var moduleActivator = new ReflectionActivator(
                    moduleType,
                    new BindingFlagsConstructorFinder(BindingFlags.Public),
                    new MostParametersConstructorSelector(),
                    moduleElement.Parameters.ToParameters(),
                    moduleElement.Properties.ToParameters());
                var module = (IModule)moduleActivator.ActivateInstance(Container.Empty, Enumerable.Empty <Parameter>());
                builder.RegisterModule(module);
            }

            foreach (ComponentElement component in _sectionHandler.Components)
            {
                var registrar = builder.RegisterType(LoadType(component.Type, defaultAssembly));

                IList <Service> services = new List <Service>();
                if (!string.IsNullOrEmpty(component.Service))
                {
                    var serviceType = LoadType(component.Service, defaultAssembly);
                    if (!string.IsNullOrEmpty(component.Name))
                    {
                        services.Add(new KeyedService(component.Name, serviceType));
                    }
                    else
                    {
                        services.Add(new TypedService(serviceType));
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(component.Name))
                    {
                        throw new ConfigurationErrorsException(string.Format(
                                                                   ConfigurationSettingsReaderResources.ServiceTypeMustBeSpecified, component.Name));
                    }
                }

                foreach (ServiceElement service in component.Services)
                {
                    var serviceType = LoadType(service.Type, defaultAssembly);
                    if (!string.IsNullOrEmpty(service.Name))
                    {
                        services.Add(new KeyedService(service.Name, serviceType));
                    }
                    else
                    {
                        services.Add(new TypedService(serviceType));
                    }
                }

                foreach (var service in services)
                {
                    registrar.As(service);
                }

                foreach (var param in component.Parameters.ToParameters())
                {
                    registrar.WithParameter(param);
                }

                foreach (var prop in component.Properties.ToParameters())
                {
                    registrar.WithProperty(prop);
                }

                foreach (var ep in component.Metadata)
                {
                    registrar.WithMetadata(
                        ep.Name, TypeManipulation.ChangeToCompatibleType(ep.Value, Type.GetType(ep.Type)));
                }

                if (!string.IsNullOrEmpty(component.MemberOf))
                {
                    registrar.MemberOf(component.MemberOf);
                }

                SetScope(component, registrar);
                SetOwnership(component, registrar);
                SetInjectProperties(component, registrar);
            }

            foreach (FileElement file in _sectionHandler.Files)
            {
                var section = DefaultSectionName;
                if (!string.IsNullOrEmpty(file.Section))
                {
                    section = file.Section;
                }

                var reader = new ConfigurationSettingsReader(section, file.Name);
                builder.RegisterModule(reader);
            }
        }
 static ContainerBuilder ConfigureContainer(string configFile)
 {
     var cb = new ContainerBuilder();
     var fullFilename = "Files/" + configFile + ".config";
     var csr = new ConfigurationSettingsReader(SectionHandler.DefaultSectionName, fullFilename);
     cb.RegisterModule(csr);
     return cb;
 }
 private static IContainer ConfigureContainer()
 {
     var cb = new ContainerBuilder();
     var csr = new ConfigurationSettingsReader(SectionHandler.DefaultSectionName, "Files/TypeManipulation.config");
     cb.RegisterModule(csr);
     return cb.Build();
 }