コード例 #1
0
ファイル: Global.asax.cs プロジェクト: yangwen27/moonlit
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            var builder = new ContainerBuilder();
            builder.RegisterType<MemoryCacheManager>().As<ICacheManager>().SingleInstance();
            builder.RegisterType<SessionCachingFlash>().As<IFlash>();
            builder.RegisterType<TestUserLoader>().As<IUserLoader>();
            builder.RegisterType<Authenticate>().AsSelf();

            var controllerAssemblies = new[] { typeof(MvcApplication).Assembly };
            builder.RegisterControllers(controllerAssemblies).PropertiesAutowired();
            // OPTIONAL: Register model binders that require DI.
            builder.RegisterModelBinders(controllerAssemblies);
            builder.RegisterModelBinderProvider();

            // OPTIONAL: Register web abstractions like HttpContextBase.
            builder.RegisterModule<AutofacWebTypesModule>();

            // OPTIONAL: Enable property injection in view pages.
            builder.RegisterSource(new ViewRegistrationSource());

            // OPTIONAL: Enable property injection into action filters.
            builder.RegisterFilterProvider();

            // Set the dependency resolver to be Autofac.

            var clipOneTheme = new ClipOneTheme();
            Themes themes = new Themes();
            themes.Register(clipOneTheme);
            builder.Register(context => new DefaultThemeLoader("clip-one", themes)).As<IThemeLoader>();

            builder.RegisterType<ReflectionSitemapsLoader>().As<ISitemapsLoader>();
            builder.RegisterType<MyTaskLoader>().As<ITaskLoader>();
            builder.RegisterType<MyNoticeLoader>().As<INoticeLoader>();
            builder.RegisterType<MyMessageLoader>().As<IMessageLoader>();
            builder.RegisterType<TestUserLoader>().As<IUserLoader>();

            RequestMappings.Current.Register(RouteTable.Routes);
            var container = builder.Build();
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }