Example #1
0
 protected void Application_Start()
 {
     AreaRegistration.RegisterAllAreas();
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     AutoMapperConfig.RegisterMaps();
     FilterConfig.RegisterFilters(GlobalFilters.Filters);
 }
Example #2
0
        protected void Application_Start()
        {
            var builder = new ContainerBuilder();

            builder.RegisterControllers(typeof(MvcApplication).Assembly).PropertiesAutowired(); //注册当前程序集的controllers

            var service_assemblies = new Assembly[] { Assembly.Load("Weixin.Service") };        //获取service程序集的类库

            builder.RegisterAssemblyTypes(service_assemblies)                                   //注册刚刚获取的service程序集
            .Where(type => !type.IsAbstract &&  //过滤要注册哪些程序集
                   typeof(IserviceSupport).IsAssignableFrom(type))
            .AsImplementedInterfaces().PropertiesAutowired();            //只注册实现了IserviceSupport接口的

            var container = builder.Build();

            //注册系统级别的DependencyResolver,这样当MVC框架创建Controller等对象的时候都是管Autofac要对象。
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            Senparc.Weixin.Threads.ThreadUtility.Register();

            //MvcApplication不是autofac创建,所以不会自动属性注入
            var baseConfigService = (IBaseConfigService)DependencyResolver.Current.GetService(typeof(IBaseConfigService));
            var configs           = baseConfigService.GetAll().Result;

            foreach (var config in configs) //应用程序初始化时注册所有accesstoken
            {
                Senparc.Weixin.MP.Containers.AccessTokenContainer.Register(config.Appid, config.Appsecret, config.WeixinName);
            }
            Senparc.Weixin.Config.IsDebug = true;//开启日志记录状态
            FilterConfig.RegisterFilters(GlobalFilters.Filters);
        }
 protected void Application_Start()
 {
     UnityConfig.RegisterComponents();
     GlobalConfiguration.Configure(WebApiConfig.Register);
     GlobalConfiguration.Configure(WebApiODataConfig.RegisterOData);
     //MappingConfig.RegisterMaps();
     EntityMapper.RegisterMapper();
     FilterConfig.RegisterFilters(new HttpFilterCollection());
 }
Example #4
0
        // This code configures Web API. The Startup class is specified as a type
        // parameter in the WebApp.Start method.
        public void Configuration(IAppBuilder appBuilder)
        {
            // Configure Web API for self-host.
            HttpConfiguration config = new HttpConfiguration();

            WebApiConfig.Register(config);

            // Registrating ninject IOC
            config.DependencyResolver = new NinjectResolver(NinjectConfig.CreateKernel());

            // Registrating filters
            FilterConfig.RegisterFilters(config.Filters);

            appBuilder.UseWebApi(config);

            config.EnsureInitialized();
        }
Example #5
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            //依赖注入
            AutofacConfig.Register();

            //注册logNet配置
            Log4NetConfig.LogConfig();

            //注册过滤器
            FilterConfig.RegisterFilters(GlobalFilters.Filters);

            //实体模型映射
            Mapper.Initialize(x => { x.AddProfile <SourceProfile>(); });
        }
Example #6
0
        protected void Application_Start()
        {
            log4net.Config.XmlConfigurator.Configure();
            ModelBinders.Binders.Add(typeof(string), new TrimToDBCModelBinder());
            ModelBinders.Binders.Add(typeof(int), new TrimToDBCModelBinder());
            ModelBinders.Binders.Add(typeof(long), new TrimToDBCModelBinder());
            ModelBinders.Binders.Add(typeof(double), new TrimToDBCModelBinder());



            var builder = new ContainerBuilder();

            builder.RegisterControllers(typeof(MvcApplication).Assembly)
            .PropertiesAutowired();    //把当前程序集中的Controller都注册                                                                                               //不要忘了.PropertiesAutowired()
                                       // 获取所有相关类库的程序集
            Assembly[] assemblies = new Assembly[] { Assembly.Load("PalmRent.Service") };
            builder.RegisterAssemblyTypes(assemblies)
            .Where(type => !type.IsAbstract &&
                   typeof(IServiceSupport).IsAssignableFrom(type))
            .AsImplementedInterfaces().PropertiesAutowired();
            //Assign:赋值
            //type1.IsAssignableFrom(type2);type1类型的变量是否可以指向type2类型的对象
            //换一种说法:type2是否实现了type1接口/type2是否继承自type1
            //typeof(IServiceSupport).IsAssignableFrom(type)只注册实现了IServiceSupport的类
            //避免其他无关的类注册到AutoFac中

            var container = builder.Build();

            //注册系统级别的DependencyResolver,这样当MVC框架创建Controller等对象的时候都是管Autofac要对象。
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));//!!!
            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            /*
             * GlobalFilters.Filters.Add(new PalmRentExceptionFilter());
             * GlobalFilters.Filters.Add(new JsonNetActionFilter());
             * GlobalFilters.Filters.Add(new PalmRentAuthorizeFilter());
             */
            FilterConfig.RegisterFilters(GlobalFilters.Filters);

            //执行以下方法将定时给老板发邮件
            //startQuartz();
        }
Example #7
0
 public static void ApplicationStart()
 {
     try
     {
         StructureMapConfig.RegisterStructureMap();
         MvcConfig.RegisterMvc();
         //EntityFrameworkProfilerConfig.RegisterEntityFrameworkProfiler();
         AreaRegistration.RegisterAllAreas();
         RouteConfig.RegisterRoutes(RouteTable.Routes);
         BundleConfig.RegisterBundles(BundleTable.Bundles);
         FilterConfig.RegisterFilters(GlobalFilters.Filters);
         //RazorGeneratorConfig.RegisterRazorGenerator();
         EntityFrameworkConfig.RegisterEntityFramework();
         AutoMapperConfig.RegisterAutoMapper();
         StartupConfig.Configuration();
         Configuration();
     }
     catch
     {
         // سبب ری استارت برنامه و آغاز مجدد آن با درخواست بعدی می‌شود
         HttpRuntime.UnloadAppDomain();
         throw;
     }
 }
Example #8
0
 protected override void RegisterFilters(HttpFilterCollection filters)
 {
     FilterConfig.RegisterFilters(filters);
 }