public static void Initialize(Assembly assembly, Type dbContextType, MapperConfiguration autoMapperConfig = default(MapperConfiguration), params Autofac.Module[] additionalModules)
        {
            ContainerBuilder containerBuilder = new ContainerBuilder();

            Autofac.Integration.Mvc.RegistrationExtensions.RegisterControllers(containerBuilder, Assembly.GetExecutingAssembly()).PropertiesAutowired();
            ModuleRegistrationExtensions.RegisterModule(containerBuilder, new RepositoryModule(assembly));
            ModuleRegistrationExtensions.RegisterModule(containerBuilder, new ServiceModule(assembly));
            ModuleRegistrationExtensions.RegisterModule(containerBuilder, new EntityFrameworkModule(assembly, dbContextType));

            if (additionalModules != null)
            {
                foreach (var module in additionalModules)
                {
                    ModuleRegistrationExtensions.RegisterModule(containerBuilder, module);
                }
            }
            if (autoMapperConfig == default(IMapperConfigurationExpression))
            {
                autoMapperConfig = new MapperConfiguration(cfg => { cfg.CreateMissingTypeMaps = true; });
                IMapper mapper = autoMapperConfig.CreateMapper();
            }
            ModuleRegistrationExtensions.RegisterModule(containerBuilder, new AutoMapperModule(autoMapperConfig));
            var reslover = containerBuilder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(reslover));
        }
Example #2
0
        protected override void Load(ContainerBuilder builder)
        {
            NameValueCollection appSettings = ConfigurationManager.AppSettings;

            string[] allKeys = appSettings.AllKeys;
            string[] array   = allKeys;
            for (int i = 0; i < array.Length; i++)
            {
                string text = array[i];
                if (text.Count((char c) => c == '.') == 1)
                {
                    string[] array2 = text.Split(new char[]
                    {
                        '.'
                    });
                    string moduleName = array2[0];
                    string name       = array2[1];
                    string value      = appSettings[text];
                    Module module     = this._modules.FirstOrDefault((Module m) => m.GetType().Name == moduleName + "Module");
                    if (module != null)
                    {
                        PropertyInfo property = module.GetType().GetProperty(name);
                        object       value2   = TypeManipulation.ChangeToCompatibleType(value, property.PropertyType, property);
                        property.SetValue(module, value2, null);
                    }
                }
            }
            foreach (Module current in this._modules)
            {
                ModuleRegistrationExtensions.RegisterModule(builder, current);
            }
        }
Example #3
0
 protected override void Load(ContainerBuilder builder)
 {
     ModuleRegistrationExtensions.RegisterModule(builder, new RepositoryModule(this.assembly));
     Autofac.RegistrationExtensions.InstancePerRequest <object, ConcreteReflectionActivatorData, SingleRegistrationStyle>(Autofac.RegistrationExtensions.RegisterType(builder, this.dbContextType).As(new Type[1]
     {
         typeof(DbContext)
     }), new object[0]);
     builder.RegisterType(typeof(UnitOfWork)).As(typeof(IUnitOfWork)).InstancePerRequest();
 }
Example #4
0
        protected sealed override void Configure()
        {
            ContainerBuilder containerBuilder = new ContainerBuilder();

            RegistrationExtensions.RegisterType <WindowManager>(containerBuilder).As <IWindowManager>().SingleInstance();
            RegistrationExtensions.RegisterType <EventAggregator>(containerBuilder).As <IEventAggregator>().SingleInstance();
            ModuleRegistrationExtensions.RegisterModule <EventAggregationAutoSubscriptionModule>(containerBuilder);
            this.ConfigureContainer(containerBuilder);
            this.Container = containerBuilder.Build(0);
        }
Example #5
0
 protected BuilderBase(params IModule[] modules)
 {
     if (modules == null || modules.Length <= 0)
     {
         return;
     }
     foreach (IModule module in modules)
     {
         ModuleRegistrationExtensions.RegisterModule(this.ContainerBuilder, module);
     }
 }
Example #6
0
 protected virtual void RegisterConfiguredModules(ContainerBuilder builder, SectionHandler configurationSection)
 {
     if (builder == null)
     {
         throw new ArgumentNullException("builder");
     }
     if (configurationSection == null)
     {
         throw new ArgumentNullException("configurationSection");
     }
     foreach (ModuleElement current in configurationSection.Modules)
     {
         Type    type   = this.LoadType(current.Type, configurationSection.DefaultAssembly);
         IModule module = null;
         using (ReflectionActivator reflectionActivator = new ReflectionActivator(type, new DefaultConstructorFinder(), new MostParametersConstructorSelector(), current.Parameters.ToParameters(), current.Properties.ToParameters()))
         {
             module = (IModule)reflectionActivator.ActivateInstance(new ContainerBuilder().Build(0), Enumerable.Empty <Parameter>());
         }
         ModuleRegistrationExtensions.RegisterModule(builder, module);
     }
 }
 protected void Load(ContainerBuilder builder)
 {
     //IL_0000: Unknown result type (might be due to invalid IL or missing references)
     //IL_000c: Unknown result type (might be due to invalid IL or missing references)
     //IL_0012: Unknown result type (might be due to invalid IL or missing references)
     //IL_0019: Unknown result type (might be due to invalid IL or missing references)
     //IL_0031: Unknown result type (might be due to invalid IL or missing references)
     //IL_003c: Unknown result type (might be due to invalid IL or missing references)
     //IL_0042: Unknown result type (might be due to invalid IL or missing references)
     //IL_004d: Unknown result type (might be due to invalid IL or missing references)
     //IL_0065: Unknown result type (might be due to invalid IL or missing references)
     //IL_0070: Unknown result type (might be due to invalid IL or missing references)
     ModuleRegistrationExtensions.RegisterModule(builder, new RepositoryModule(this.assembly));
     RegistrationExtensions.InstancePerRequest <object, ConcreteReflectionActivatorData, SingleRegistrationStyle>(RegistrationExtensions.RegisterType(builder, this.dbContextType).As(new Type[1]
     {
         typeof(DbContext)
     }), new object[0]);
     RegistrationExtensions.InstancePerRequest <object, ConcreteReflectionActivatorData, SingleRegistrationStyle>(RegistrationExtensions.RegisterType(builder, typeof(UnitOfWork)).As(new Type[1]
     {
         typeof(IUnitOfWork)
     }), new object[0]);
 }
Example #8
0
 protected override void ConfigureContainer(ContainerBuilder builder)
 {
     base.ConfigureContainer(builder);
     ModuleRegistrationExtensions.RegisterModule <LegacyModule>(ModuleRegistrationExtensions.RegisterModule <UIModule>(ModuleRegistrationExtensions.RegisterModule <AppServicesModule>(ModuleRegistrationExtensions.RegisterModule <VpnModule>(ModuleRegistrationExtensions.RegisterModule <CoreModule>(ModuleRegistrationExtensions.RegisterModule <InfrastructureModule>(builder))))));
 }
 public static void RegisterModule(this BuilderBase builder, IModule module)
 {
     ModuleRegistrationExtensions.RegisterModule(builder.ContainerBuilder, module);
 }
 public static void RegisterModule <TModule>(this BuilderBase builder) where TModule : IModule, new()
 {
     ModuleRegistrationExtensions.RegisterModule <TModule>(builder.ContainerBuilder);
 }