Register() public static method

public static Register ( System.Web.Http.HttpConfiguration config ) : void
config System.Web.Http.HttpConfiguration
return void
Esempio n. 1
0
        public void Configuration(IAppBuilder app)
        {
            HttpConfiguration config = new HttpConfiguration();

            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);

            RouteConfig.RegisterRoutes(RouteTable.Routes);

            HttpConfiguration httpConfig = new HttpConfiguration();

            WebApiConfig.Register(httpConfig);

            BundleConfig.RegisterBundles(BundleTable.Bundles);

            ConfigureAuth(app);
            app.UseWebApi(httpConfig);
        }
Esempio n. 2
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            log4net.Config.XmlConfigurator.Configure();

            var builder = new ContainerBuilder();//把当前程序集中的 Controller 都注册,不要忘了.PropertiesAutowired()

            builder.RegisterControllers(typeof(MvcApplication).Assembly).PropertiesAutowired();
            builder.RegisterApiControllers(typeof(MvcApplication).Assembly).PropertiesAutowired();

            Assembly[] assemblies = new Assembly[] { Assembly.Load("IMS.Service") };// 获取所有相关类库的程序集
            builder.RegisterAssemblyTypes(assemblies).
            Where(type => !type.IsAbstract && typeof(IServiceSupport).IsAssignableFrom(type)).AsImplementedInterfaces().PropertiesAutowired();
            //type1.IsAssignableFrom(type2):Assign赋值,type1类型的变量是否可以指向type2类型的对象。也就是type2是否实现type1接口/type2是否继承自type1

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

            // Set the dependency resolver for MVC.
            var resolver = new AutofacDependencyResolver(container);

            DependencyResolver.SetResolver(resolver);

            // Set the dependency resolver for Web API.
            var webApiResolver = new AutofacWebApiDependencyResolver(container);

            GlobalConfiguration.Configuration.DependencyResolver = webApiResolver;

            GlobalFilters.Filters.Add(new JsonNetActionFilter());
            GlobalFilters.Filters.Add(new SYSExceptionFilter());
            GlobalFilters.Filters.Add(new SYSAuthorizationFilter());

            // StartQuartz();
        }
Esempio n. 3
0
        protected void Application_Start()
        {
            EFConfig.Initialize();

            AreaRegistration.RegisterAllAreas();
            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            //DependencyResolver.SetResolver(new StructureMapDependencyResolver(()=> Container ?? ObjectFactory.Container));



            //ObjectFactory.Configure(cfg =>
            //{

            //    cfg.AddRegistry(new StandardRegistry());
            //    cfg.AddRegistry(new ControllerRegistry());
            //    cfg.AddRegistry(new ActionFilterRegistry(
            //        () => Container ?? ObjectFactory.Container));
            //    cfg.AddRegistry(new MvcRegistry());
            //});
        }