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


C# ContainerBuilder.ConfigureWebApi方法代码示例

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


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

示例1: Load

        protected override void Load(ContainerBuilder builder)
        {
            base.Load(builder);

            builder.ConfigureWebApi(GlobalConfiguration.Configuration);
            builder.RegisterApiControllers(_controllerAssembliesToScan);
        }
开发者ID:highwaychurch,项目名称:web,代码行数:7,代码来源:WebApiModule.cs

示例2: SetAutofacWebAPIServices

        private static void SetAutofacWebAPIServices()
        {
            var configuration = GlobalConfiguration.Configuration;
            var builder = new ContainerBuilder();

            // Configure the container with the integration implementations.
            builder.ConfigureWebApi(configuration);

            builder.RegisterType<DigitalAccountsUnitOfWork>()
                         .As<IDigitalAccountsUnitOfWork>()
                         .InstancePerLifetimeScope();

            builder.RegisterType<DigitalAccountsService>()
                         .As<IDigitalAccountsService>()
                         .InstancePerLifetimeScope();

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

            // Register API controllers using assembly scanning.
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());

            var container = builder.Build();
            // Set the dependency resolver implementation.
            var resolver = new AutofacWebApiDependencyResolver(container);

            configuration.ServiceResolver.SetResolver(resolver);

            AutofacServiceHostFactory.Container = container;
        }
开发者ID:ivpadim,项目名称:architecture,代码行数:32,代码来源:Bootstrapper.cs

示例3: Application_Start

        protected void Application_Start()
        {
            HibernatingRhinos.Profiler.Appender.NHibernate.NHibernateProfiler.Initialize();

            var configuration = GlobalConfiguration.Configuration;

            var builder = new ContainerBuilder();
            builder.ConfigureWebApi(configuration);
            builder.RegisterControllers(typeof(MvcApplication).Assembly);
            builder.Register(c => CreateSessionFactory()).As<ISessionFactory>().SingleInstance();
            builder.Register(c =>
                {
                    var sf = c.Resolve<ISessionFactory>();
                    var session = sf.OpenSession();
                    var export = new SchemaExport(SavedConfig);
                    export.Execute(true, true, false, session.Connection, null);
                    return session;
                }
                ).As<ISession>().SingleInstance();

            builder.RegisterType<UnitOfWork>().InstancePerHttpRequest();
            var container = builder.Build();
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            var resolver = new AutofacWebApiDependencyResolver(container);
            configuration.ServiceResolver.SetResolver(resolver);

            AreaRegistration.RegisterAllAreas();

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

            BundleTable.Bundles.RegisterTemplateBundles();
        }
开发者ID:adbrowne,项目名称:Samples,代码行数:34,代码来源:Global.asax.cs

示例4: Application_Start

        protected void Application_Start()
        {
            //autofac
            var configuration = GlobalConfiguration.Configuration;
            var builder = new ContainerBuilder();
            builder.RegisterControllers(typeof(MvcApplication).Assembly);
            builder.RegisterModule(new AutofacModule());
            builder.ConfigureWebApi(configuration);
            builder.RegisterApiControllers(typeof (MvcApplication).Assembly);
            var container = builder.Build();
            var resolver = new AutofacWebApiDependencyResolver(container);
            configuration.ServiceResolver.SetResolver(resolver);
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            AreaRegistration.RegisterAllAreas();
            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
            BundleTable.Bundles.RegisterTemplateBundles();
        }
开发者ID:mattoraptor,项目名称:jobwatcher,代码行数:19,代码来源:Global.asax.cs

示例5: SetAutofacWebAPIServices

 private static void SetAutofacWebAPIServices()
 {
     var configuration = GlobalConfiguration.Configuration;
     var builder = new ContainerBuilder();
     // Configure the container with the integration implementations.
     builder.ConfigureWebApi(configuration);
     // Register API controllers using assembly scanning.
     builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
     builder.RegisterType<DefaultCommandBus>().As<ICommandBus>().InstancePerApiRequest();
     builder.RegisterType<UnitOfWork>().As<IUnitOfWork>().InstancePerApiRequest();
     builder.RegisterType<DatabaseFactory>().As<IDatabaseFactory>().InstancePerApiRequest();
     builder.RegisterAssemblyTypes(typeof(CategoryRepository)
         .Assembly).Where(t => t.Name.EndsWith("Repository"))
     .AsImplementedInterfaces().InstancePerApiRequest();
     var services = Assembly.Load("EFMVC.Domain");
     builder.RegisterAssemblyTypes(services)
     .AsClosedTypesOf(typeof(ICommandHandler<>)).InstancePerApiRequest();
     builder.RegisterAssemblyTypes(services)
     .AsClosedTypesOf(typeof(IValidationHandler<>)).InstancePerApiRequest();
     var container = builder.Build();
     // Set the dependency resolver implementation.
     var resolver = new AutofacWebApiDependencyResolver(container);
     configuration.ServiceResolver.SetResolver(resolver);             
 }
开发者ID:amazedsaint,项目名称:EFMVC.Azure,代码行数:24,代码来源:Bootstrapper.cs


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