Esempio n. 1
0
        private void configureDependency(IAppBuilder app)
        {
            var builder = new ContainerBuilder();

            builder.RegisterControllers(Assembly.GetExecutingAssembly()).PropertiesAutowired();
            // 注册数据访问上下文
            builder.Register <Lvwei8MySqlEntities>(f =>
            {
                var efDB = new Lvwei8MySqlEntities();
                return(efDB);
            }).As <Lvwei8MySqlEntities>().InstancePerLifetimeScope().PropertiesAutowired();
            //var x = new eXiuMySqlEntities();
            //x.Database.Log = s => efSqlLogger.Debug(s);
            builder.Register <Lvwei8MySqlReadOnlyEntities>(f =>
            {
                var efDB = new Lvwei8MySqlReadOnlyEntities();
                return(efDB);
            }).As <Lvwei8MySqlReadOnlyEntities>().InstancePerLifetimeScope().PropertiesAutowired();
            builder.RegisterControllers(Assembly.GetExecutingAssembly()).PropertiesAutowired();
            var Dbassemblys = AppDomain.CurrentDomain.GetAssemblies();
            var assemblys   = Dbassemblys.Where(e => e.FullName.Contains("lvwei8")).ToList();

            //注册仓储
            builder.RegisterAssemblyTypes(assemblys.ToArray()).Where(t => t.Name.EndsWith("RepositoryImpl")).AsImplementedInterfaces().InstancePerLifetimeScope().PropertiesAutowired();
            builder.RegisterGeneric(typeof(RepositoryImpl <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope().PropertiesAutowired();
            builder.RegisterGeneric(typeof(ReadOnlyRepositoryImpl <>)).As(typeof(IReadOnlyRepository <>)).InstancePerLifetimeScope().PropertiesAutowired();

            //注册服务
            builder.RegisterAssemblyTypes(assemblys.ToArray()).Where(t => t.Name.EndsWith("ServiceImpl")).AsImplementedInterfaces().InstancePerLifetimeScope().PropertiesAutowired(PropertyWiringOptions.AllowCircularDependencies);

            var container = builder.Build();

            DependencyResolver.SetResolver(new Autofac.Integration.Mvc.AutofacDependencyResolver(container));
        }
Esempio n. 2
0
        private void configureDependency(IAppBuilder app)
        {
            var builder = new ContainerBuilder();

            builder.RegisterControllers(Assembly.GetExecutingAssembly()).PropertiesAutowired();
            // 注册数据访问上下文
            builder.Register <Lvwei8MySqlEntities>(f =>
            {
                var efDB = new Lvwei8MySqlEntities();
                return(efDB);
            }).As <Lvwei8MySqlEntities>().InstancePerLifetimeScope().PropertiesAutowired();
            //var x = new eXiuMySqlEntities();
            //x.Database.Log = s => efSqlLogger.Debug(s);
            builder.Register <Lvwei8MySqlReadOnlyEntities>(f =>
            {
                var efDB = new Lvwei8MySqlReadOnlyEntities();
                return(efDB);
            }).As <Lvwei8MySqlReadOnlyEntities>().InstancePerLifetimeScope().PropertiesAutowired();
            builder.RegisterControllers(Assembly.GetExecutingAssembly()).PropertiesAutowired();
            var Dbassemblys = AppDomain.CurrentDomain.GetAssemblies();
            var assemblys   = Dbassemblys.Where(e => e.FullName.Contains("lvwei8")).ToList();

            //注册仓储
            builder.RegisterAssemblyTypes(assemblys.ToArray()).Where(t => t.Name.EndsWith("RepositoryImpl")).AsImplementedInterfaces().InstancePerLifetimeScope().PropertiesAutowired();
            builder.RegisterGeneric(typeof(RepositoryImpl <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope().PropertiesAutowired();
            builder.RegisterGeneric(typeof(ReadOnlyRepositoryImpl <>)).As(typeof(IReadOnlyRepository <>)).InstancePerLifetimeScope().PropertiesAutowired();

            //注册服务
            builder.RegisterAssemblyTypes(assemblys.ToArray()).Where(t => t.Name.EndsWith("ServiceImpl")).AsImplementedInterfaces().InstancePerLifetimeScope().PropertiesAutowired(PropertyWiringOptions.AllowCircularDependencies);

            builder.Register <BackendUserStore <user_backend_Iuser> >(c => new BackendUserStore <user_backend_Iuser>()).AsImplementedInterfaces().MyPropertiesAutowired().InstancePerRequest();
            builder.RegisterType <RoleBackend>();
            builder.Register <RoleStore <RoleBackend> >(c => new RoleStore <RoleBackend>()).AsImplementedInterfaces();
            builder.Register <IdentityFactoryOptions <ApplicationUserManager> >(c => new IdentityFactoryOptions <ApplicationUserManager>()
            {
                DataProtectionProvider = new Microsoft.Owin.Security.DataProtection.DpapiDataProtectionProvider("ApplicationName")
            });
            builder.RegisterType <ApplicationUserManager>().MyPropertiesAutowired();//.InstancePerRequest();
            builder.RegisterType <ApplicationRoleManager>().MyPropertiesAutowired();

            var container = builder.Build();

            DependencyResolver.SetResolver(new Autofac.Integration.Mvc.AutofacDependencyResolver(container));
        }
Esempio n. 3
0
        public static Dictionary <string, string> getAllAreas()
        {
            ObjectCache cache = MemoryCache.Default;
            Dictionary <string, string> allAreas = cache["AllAreas"] as Dictionary <string, string>;

            if (allAreas == null)
            {
                CacheItemPolicy policy          = new CacheItemPolicy();
                string          monitorFilePath = HttpContext.Current.Server.MapPath("~/CacheFileDependency/AreaList.cache");
                policy.ChangeMonitors.Add(new HostFileChangeMonitor(new List <String> {
                    monitorFilePath
                }));

                var dbContext = new Lvwei8MySqlReadOnlyEntities();
                allAreas = dbContext.Areas.OrderBy(e => e.Code).ToList().ToDictionary(i => i.Code, i => i.Name);
                cache.Set("AllAreas", allAreas, policy);
            }
            return(allAreas);
        }