当前位置: 首页>>代码示例>>C#>>正文


C# ContainerBuilder.RegisterControllers方法代码示例

本文整理汇总了C#中Autofac.ContainerBuilder.RegisterControllers方法的典型用法代码示例。如果您正苦于以下问题:C# ContainerBuilder.RegisterControllers方法的具体用法?C# ContainerBuilder.RegisterControllers怎么用?C# ContainerBuilder.RegisterControllers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Autofac.ContainerBuilder的用法示例。


在下文中一共展示了ContainerBuilder.RegisterControllers方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BuildAutoFacContainer

        private static IContainer BuildAutoFacContainer()
        {
            var builder = new ContainerBuilder();

            //注册Controls
            builder.RegisterControllers(Assembly.GetExecutingAssembly());
            builder.RegisterControllers(new Assembly[] { Assembly.Load("YOYO.HRMS.Web.SystemManagement") });

            builder.RegisterType<PetaPocoDBFactory>().As<IDBFactory>().InstancePerHttpRequest();
            builder.RegisterType<PetaPocoUnitOfWork>().As<IUnitOfWork>();
            builder.RegisterType<NlogLogger>().As<ILogger>();

            builder.RegisterAssemblyTypes(typeof(LocalizedViewRepository).Assembly)
                .Where(t => t.Name.EndsWith("Repository")).AsImplementedInterfaces();

            builder.RegisterAssemblyTypes(typeof(LocalizedViewService).Assembly)
                .Where(t => t.Name.EndsWith("Service")).AsImplementedInterfaces();

            var container = builder.Build();

            // register all your components with the container here
            // it is NOT necessary to register your controllers

            // e.g. container.RegisterType<ITestService, TestService>();
            //container.RegisterType<IDBFactory, PetaPocoDBFactory>(new HierarchicalLifetimeManager());
            //container.RegisterType<IUnitOfWork,PetaPocoUnitOfWork>();
            //container.RegisterType<IEmployeeRepository, EmployeeRepository>();
            //container.RegisterType<IEmployeeService, EmployeeService>();

            return container;
        }
开发者ID:paulzhousz,项目名称:YOYOHRMS,代码行数:31,代码来源:Bootstrapper.cs

示例2: Configure

        public static void Configure()
        {
            var builder = new ContainerBuilder();

            builder.RegisterType<EFStoredGrantManager>().As<IStoredGrantManager>();

            builder.RegisterType<DefaultAssertionGrantValidator>().As<IAssertionGrantValidation>();

            builder.RegisterType<EFAuthorizationServerConfiguration>().As<IAuthorizationServerConfiguration>();
            builder.RegisterType<EFAuthorizationServerAdministration>().As<IAuthorizationServerAdministration>();
            builder.RegisterType<EFAuthorizationServerAdministratorsService>().As<IAuthorizationServerAdministratorsService>();
            builder.RegisterType<AuthorizationServerContext>().InstancePerHttpRequest();

            builder.RegisterType<TokenService>().AsSelf();
            
            builder.RegisterModule(new ConfigurationSettingsReader("autofac"));

            builder.RegisterControllers(typeof(AuthorizeController).Assembly);
            builder.RegisterControllers(typeof(AutofacConfig).Assembly);
            builder.RegisterApiControllers(typeof(TokenController).Assembly);
            builder.RegisterApiControllers(typeof(AutofacConfig).Assembly);

            var container = builder.Build(); 
            
            // MVC
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            // Web API
            var resolver = new AutofacWebApiDependencyResolver(container);
            GlobalConfiguration.Configuration.DependencyResolver = resolver;
        }
开发者ID:Griimm,项目名称:Thinktecture.AuthorizationServer,代码行数:31,代码来源:AutoFacConfig.cs

示例3: Configure

        public static void Configure()
        {
            var builder = new ContainerBuilder();
            builder.RegisterType<EFStoredGrantManager>().As<IStoredGrantManager>();
            builder.RegisterType<EFAuthorizationServerConfiguration>().As<IAuthorizationServerConfiguration>();
            builder.RegisterType<EFAuthorizationServerAdministration>().As<IAuthorizationServerAdministration>();
            builder.RegisterType<EFAuthorizationServerAdministratorsService>()
                   .As<IAuthorizationServerAdministratorsService>();

            //builder.RegisterType<Thinktecture.Samples.AssertionGrantValidator>().As<IAssertionGrantValidation>();

            builder.RegisterType<DefaultAssertionGrantValidator>().As<IAssertionGrantValidation>();
            builder.RegisterType<AuthorizationServerContext>().InstancePerHttpRequest();

            builder.Register(x => CreateCredentialAuthorizationResource()).As<ICredentialAuthorizationResource>();
            builder.RegisterType<WSTrustResourceOwnerCredentialValidation>().As<IResourceOwnerCredentialValidation>();

            builder.RegisterModule(new AutofacWebTypesModule());

            builder.RegisterControllers(typeof (AuthorizeController).Assembly);
            builder.RegisterControllers(typeof (AutofacConfig).Assembly);
            builder.RegisterApiControllers(typeof (TokenController).Assembly);
            builder.RegisterApiControllers(typeof (AutofacConfig).Assembly);

            var container = builder.Build();

            // MVC
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            // Web API
            var resolver = new AutofacWebApiDependencyResolver(container);
            GlobalConfiguration.Configuration.DependencyResolver = resolver;
        }
开发者ID:piblinedev,项目名称:Thinktecture.AuthorizationServer,代码行数:33,代码来源:AutoFacConfig.cs

示例4: AutoFacInit

        public static void AutoFacInit()
        {
            var builder = new ContainerBuilder();

            //注册DomainServices
            var services = Assembly.Load("AutofacMvcPluginDemo.Services");
            builder.RegisterAssemblyTypes(services, services)
              .Where(t => t.Name.EndsWith("Service"))
              .AsImplementedInterfaces().PropertiesAutowired();

            //实现插件Controllers注入
            var assemblies = new DirectoryInfo(
                     HttpContext.Current.Server.MapPath("~/Plugins/"))
               .GetFiles("*.dll")
               .Select(r => Assembly.LoadFrom(r.FullName)).ToArray();
            foreach (var assembly in assemblies)
            {
                builder.RegisterControllers(assembly).PropertiesAutowired().InstancePerRequest();
            }

            //注册主项目的Controllers
            builder.RegisterControllers(Assembly.GetExecutingAssembly()).PropertiesAutowired();

            var container = builder.Build();

            var beginLifetimeScope = container.BeginLifetimeScope();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
开发者ID:jango2015,项目名称:-AutofacMvcPluginDemo,代码行数:29,代码来源:AutoFacBootStrapper.cs

示例5: BuildMvcContainer

        /// <summary>
        /// 创建 MVC容器(包含Filter)
        /// </summary>
        public static void BuildMvcContainer()
        {
            var builder = new ContainerBuilder();
            //注册Module方法2 在Web.config中配制方式
            builder.RegisterModule(new ConfigurationSettingsReader("autofacMvc"));
            //加载 *.Controllers 层的控制器,否则无法在其他层控制器构造注入,只能在web层注入
            Assembly[] asm = GetAllAssembly("*.Controllers.dll").ToArray();
            builder.RegisterAssemblyTypes(asm);
            //注册仓储
            Assembly[] asmRepository = GetAllAssembly("*.Repository.dll").ToArray();
            builder.RegisterAssemblyTypes(asmRepository)
               .Where(t => t.Name.EndsWith("Repository"))
               .AsImplementedInterfaces();

            builder.RegisterControllers(Assembly.GetExecutingAssembly());
            builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
            builder.RegisterModelBinderProvider();


            //注册过滤器 
            builder.RegisterFilterProvider();
            builder.RegisterType<OperateAttribute>().PropertiesAutowired();//非global filter  属性注入
            builder.RegisterType<GlobalFilterAttribute>().SingleInstance();//global filter 注入
            builder.RegisterControllers(typeof(MvcApplication).Assembly);

            var container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
开发者ID:ciker,项目名称:201509LoginDemo,代码行数:32,代码来源:AutofacRegistion.cs

示例6: SetUpContainer

        private void SetUpContainer()
        {
            var builder = new ContainerBuilder();
            builder.RegisterControllers(typeof(MvcApplication).Assembly);

            builder.RegisterControllers(Assembly.GetExecutingAssembly());
            builder.RegisterModule(new AutofacWebTypesModule());
            RegisterCustomServices(builder);

            _container = builder.Build();
            DependencyResolver.SetResolver(new AutofacDependencyResolver(_container));
        }
开发者ID:BasiaFusinska,项目名称:LetsGoOut,代码行数:12,代码来源:Global.asax.cs

示例7: OnApplicationStarting

        public void OnApplicationStarting(UmbracoApplicationBase umbracoApplication,
            ApplicationContext applicationContext)
        {
            var viewPaths = new List<string>()
            {
                "~/Views/{0}.cshtml",
                "~/Views/{0}/{1}.cshtml",
                "~/Views/Shared/{0}.cshtml",
                "~/Views/Partials/{0}.cshtml",
                "~/Views/Region/{0}.cshtml",
                "~/Views/Widget/{0}.cshtml"
            };
            var catalog = new AggregateCatalog();

            var curentAssembly = new AssemblyCatalog(Assembly.GetExecutingAssembly());

            catalog.Catalogs.Add(curentAssembly);
            var builder = new ContainerBuilder();
            builder.Register(c => UmbracoContext.Current).AsSelf();
            builder.RegisterControllers(Assembly.GetExecutingAssembly());
            builder.RegisterApiControllers(typeof(UmbracoApplication).Assembly);

            foreach (var path in Directory.EnumerateDirectories(AppDomain.CurrentDomain.BaseDirectory + "\\Plugins", "*Widget*", SearchOption.TopDirectoryOnly))
            {
                catalog.Catalogs.Add(new DirectoryCatalog(path));
                var pluginName = path.Split('\\');
                viewPaths.Add(String.Format("~/Plugins/{0}/Views/{1}.cshtml", pluginName[pluginName.Length - 1], "{0}"));
                var pluginAssembly = Assembly.Load(pluginName[pluginName.Length - 1]);
                builder.RegisterControllers(pluginAssembly);
                
                //ToDo: Add routes to view engine for none umbraco ones (below errors with No Tempalte
                //RouteTable.Routes.MapRoute(pluginName[pluginName.Length - 1], "{controller}/{action}", new
                //{
                //    controller = pluginName[pluginName.Length - 1],
                //    action = "RenderWidget",
                //    id = UrlParameter.Optional
                //});
            }

            ViewEngines.Engines.Add(new UmbracoToolboxViewEngine(viewPaths.ToArray()));
            builder.RegisterComposablePartCatalog(catalog);

           
            var container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            var resolver = new AutofacWebApiDependencyResolver(container);
            GlobalConfiguration.Configuration.DependencyResolver = resolver;

            
        }
开发者ID:CodeChronicler,项目名称:UmbracoToolbox,代码行数:52,代码来源:ApplicationStartEventHandler.cs

示例8: Application_Start

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);

            var builder = new ContainerBuilder();
            builder.RegisterControllers(typeof(MvcApplication).Assembly);
            var container = builder.Build();
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            builder.RegisterControllers(Assembly.GetExecutingAssembly());
        }
开发者ID:mdljohnston,项目名称:AutoFacExample,代码行数:14,代码来源:Global.asax.cs

示例9: RegisterAutofac

        public static void RegisterAutofac()
        {
            var builder = new ContainerBuilder();

            // Register your MVC controllers.
            builder.RegisterControllers(typeof(MvcApplication).Assembly);

            // OPTIONAL: Register model binders that require DI.
            builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
            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();

            // Register services
            RegisterServices(builder);

            // Set the dependency resolver to be Autofac.
            var container = builder.Build();
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
开发者ID:AndrewMitev,项目名称:Telerik-Academy,代码行数:27,代码来源:AutofacConfig.cs

示例10: Configure

        public static void Configure()
        {
            var assemblies = BuildManager.GetReferencedAssemblies().Cast<Assembly>().ToArray();
            var builder = new ContainerBuilder();

            builder.RegisterAssemblyTypes(assemblies)
                .Where(t => typeof(IStartable).IsAssignableFrom(t))
                .As<IStartable>()
                .SingleInstance();

            builder.RegisterAssemblyModules(assemblies);

            builder.RegisterControllers(Assembly.GetExecutingAssembly());
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());

            var container = builder.Build();

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

            // Set the dependency resolver for MVC.
            var mvcResolver = new AutofacDependencyResolver(container);
            DependencyResolver.SetResolver(mvcResolver);
        }
开发者ID:desflan,项目名称:RiskAnalysis,代码行数:25,代码来源:IocConfig.cs

示例11: Setup

        public static void Setup()
        {
            var builder = new ContainerBuilder();
            builder.RegisterControllers(typeof(MvcApplication).Assembly);
            builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
            builder.RegisterModelBinderProvider();
            builder.RegisterModule<AutofacWebTypesModule>();
            builder.RegisterSource(new ViewRegistrationSource());
            builder.RegisterFilterProvider();
            builder.RegisterType<PremiumCalculationService>().As<IPremiumCalculationService>();
            builder.Register(context => new MapperConfiguration(configuration =>
            {
                configuration.AddProfile(new AutoMapperProfile());
            }))
               .AsSelf()
               .SingleInstance();

            builder.Register(context => context.Resolve<MapperConfiguration>()
                .CreateMapper(context.Resolve))
                .As<IMapper>()
                .InstancePerLifetimeScope();

            var container = builder.Build();
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
开发者ID:CarloHagens,项目名称:RelayMotorInsuranceCalculator,代码行数:25,代码来源:AutoFacConfig.cs

示例12: SetIocContainer

        private static void SetIocContainer()
        {
            //Implement Autofac

            var configuration = GlobalConfiguration.Configuration;
            var builder = new ContainerBuilder();

            // Register MVC controllers using assembly scanning.
            builder.RegisterControllers(Assembly.GetExecutingAssembly());

            // Register MVC controller and API controller dependencies per request.
            builder.RegisterType<UnitOfWork>().As<IUnitOfWork>().InstancePerDependency();
            builder.RegisterType<DatabaseFactory>().As<IDatabaseFactory>().InstancePerLifetimeScope();

            // Register service
            builder.RegisterAssemblyTypes(typeof(ProfileService).Assembly)
            .Where(t => t.Name.EndsWith("Service"))
            .AsImplementedInterfaces().InstancePerDependency();

            // Register repository
            builder.RegisterAssemblyTypes(typeof(ProfileRepository).Assembly)
            .Where(t => t.Name.EndsWith("Repository"))
            .AsImplementedInterfaces().InstancePerDependency();

            var container = builder.Build();

            //for MVC Controller Set the dependency resolver implementation.
            var resolverMvc = new AutofacDependencyResolver(container);
            System.Web.Mvc.DependencyResolver.SetResolver(resolverMvc);
        }
开发者ID:raselbappigit,项目名称:properties-management,代码行数:30,代码来源:Bootstrapper.cs

示例13: RegisterContainer

        public static void RegisterContainer()
        {
            // Create the container builder.
            var builder = new ContainerBuilder();

            builder.RegisterControllers(Assembly.GetExecutingAssembly());
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());

            builder.Register(db =>
            {
                var dbName = ConfigurationManager.AppSettings["dbName"];
                return new MongoClient().GetServer().GetDatabase(dbName);
            }).As<MongoDatabase>().InstancePerHttpRequest();

            builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>)).InstancePerHttpRequest();

            builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
                .Where(t => t.Name.EndsWith("Service"))
                .AsSelf().InstancePerHttpRequest();

            // Build the container.
            var container = builder.Build();

            // Create the depenedency resolver.
            var resolver = new AutofacWebApiDependencyResolver(container);

            // Configure Web API with the dependency resolver.
            GlobalConfiguration.Configuration.DependencyResolver = resolver;

            // Configure MVC with the dependency resolver.
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
开发者ID:Myslik,项目名称:opencat,代码行数:32,代码来源:ContainerConfig.cs

示例14: RegisterTypes

        private static void RegisterTypes(ContainerBuilder builder)
        {
            builder.RegisterControllers(typeof(IlaroAdmin).Assembly);

            builder.RegisterType<Notificator>().AsSelf().InstancePerLifetimeScope();

            builder.RegisterType<SystemClock>().As<IKnowTheTime>();
            builder.RegisterType<EntityService>().As<IEntityService>();
            builder.RegisterType<EntityValidator>().As<IValidatingEntities>();
            builder.RegisterType<FileValidator>().As<IValidatingFiles>();
            builder.RegisterType<ConfigurationProvider>().As<IConfigurationProvider>();
            builder.RegisterType<Core.Configuration>().As<IConfiguration>();
            builder.RegisterType<RecordsSource>().As<IFetchingRecords>();
            builder.RegisterType<RecordsHierarchySource>().As<IFetchingRecordsHierarchy>();
            builder.RegisterType<DbCommandExecutor>().As<IExecutingDbCommand>();
            builder.RegisterType<RecordsCreator>().As<ICreatingRecords>();
            builder.RegisterType<RecordsUpdater>().As<IUpdatingRecords>();
            builder.RegisterType<RecordsDeleter>().As<IDeletingRecords>();
            builder.RegisterType<RecordsComparer>().As<IComparingRecords>();
            builder.RegisterType<ChangesDescriber>().As<IDescribingChanges>();
            builder.RegisterType<HttpContextUserProvider>().As<IProvidingUser>();
            builder.RegisterType<FileNameCreator>().As<ICreatingNameFiles>();
            builder.RegisterType<FileDeleter>().As<IDeletingFiles>();
            builder.RegisterType<FileHandler>().As<IHandlingFiles>();
            builder.RegisterType<ImageResizer>().As<IResizingImages>();
            builder.RegisterType<FileSaver>().As<ISavingFiles>();
            builder.RegisterType<FilterFactory>().As<IFilterFactory>();
            builder.RegisterType<RecordsService>().As<IRecordsService>();

            builder.RegisterType<IlaroAdmin>().As<IIlaroAdmin>().SingleInstance();
        }
开发者ID:rgonek,项目名称:Ilaro.Admin,代码行数:31,代码来源:Bootstrapper.cs

示例15: Register

        public static void Register(HttpConfiguration config)
        {
            // Create the container builder.
            var builder = new ContainerBuilder();

            // Register MVC 4 Contrrollers
            builder.RegisterControllers(Assembly.GetExecutingAssembly());

            // Register the Web API controllers.
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());

            //register Domain Depedencies
            builder.RegisterModule(new Domain.AutofacModule());

            // Build the container.
            var container = builder.Build();

            // SET Web API resolver
            // Create the depenedency resolver.
            var resolver = new AutofacWebApiDependencyResolver(container);
            // Configure Web API with the dependency resolver.
            config.DependencyResolver = resolver;

            //set MVC4 resolver
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
开发者ID:kkurni,项目名称:KK-DemoMVC,代码行数:26,代码来源:AutofacConfig.cs


注:本文中的Autofac.ContainerBuilder.RegisterControllers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。