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


C# ContainerBuilder.RegisterHttpRequestMessage方法代码示例

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


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

示例1: Register

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

            var config = GlobalConfiguration.Configuration;

            builder.RegisterControllers(Assembly.GetExecutingAssembly()); //Register MVC Controllers
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly()); //Register WebApi Controllers
            builder.RegisterHttpRequestMessage(GlobalConfiguration.Configuration);


            builder.RegisterAssemblyTypes(typeof(StateRepository).Assembly)
             .Where(t => t.Name.EndsWith("Repository"))
             .AsImplementedInterfaces().InstancePerLifetimeScope();
            builder.RegisterType<EdLightEntities>().As<IDataContextAsync>().InstancePerRequest();


            builder.RegisterType<DateTimeHelper>().As<IDateTimeHelper>().InstancePerLifetimeScope();
            builder.RegisterType<WorkflowSetup>().As<IWorkflowSetup>().InstancePerLifetimeScope();
            builder.RegisterType<WorkflowService>().As<IWorkflowService>().InstancePerLifetimeScope();
            builder.RegisterType<WorkflowExpression>().As<IWorkflowExpression>().InstancePerLifetimeScope();

            builder.RegisterType<EntityFrameorkUnitOfWork>().As<IUnitOfWorkAsync>().InstancePerRequest();
            builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepositoryAsync<>)).InstancePerRequest();
            builder.RegisterAssemblyTypes(typeof(StateService).Assembly)
                .Where(t => t.Name.EndsWith("Service"))
                .AsImplementedInterfaces().InstancePerLifetimeScope();

            var container = builder.Build();

            config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
开发者ID:surifoll,项目名称:git-test,代码行数:33,代码来源:AutoFacConfig.cs

示例2: ConfigureAutofac

        private static void ConfigureAutofac(HttpConfiguration config, IIssueStore issueStore)
        {
            var builder = new ContainerBuilder();

            if (issueStore == null)
            {
                builder.RegisterType<InMemoryIssueStore>()
                    .As<IIssueStore>()
                    .InstancePerLifetimeScope();

            }
            else
            {
                builder.RegisterInstance(issueStore);
            }

            builder.RegisterType<IssueStateFactory>()
                .As<IStateFactory<Issue, IssueState>>()
                .InstancePerLifetimeScope();

            builder.RegisterType<IssueLinkFactory>()
                .InstancePerLifetimeScope();

            builder.RegisterHttpRequestMessage(config);
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
            var container = builder.Build();

            var resolver =
                new AutofacWebApiDependencyResolver(container);

            config.DependencyResolver = resolver;
        }
开发者ID:hgirish,项目名称:IssueTrackerApi,代码行数:32,代码来源:WebApiConfiguration.cs

示例3: Register

        /// <summary>
        ///     Registers the configuration
        /// </summary>
        public static IContainer Register(IAppBuilder app, HttpConfiguration configuration, IServiceFacade serviceFacade = null)
        {
            Condition.Requires(configuration, "configuration").IsNotNull();

            var builder = new ContainerBuilder();

            builder.RegisterModule(new ServiceModule(serviceFacade));

            // controllers
            builder.RegisterApiControllers(typeof (ControllerBase).Assembly);

            // request
            builder.RegisterHttpRequestMessage(configuration);

            // authorization
            builder.RegisterType<AuthorizationServerProvider>().As<IOAuthAuthorizationServerProvider>().SingleInstance();

            // set resolver
            var container = builder.Build();

            // set the dependency resolver for Web API
            var resolver = new AutofacWebApiDependencyResolver(container);
            configuration.DependencyResolver = resolver;
            app.UseAutofacMiddleware(container);
            app.UseAutofacWebApi(configuration);

            ConfigureOAuth(app, container);

            app.UseWebApi(configuration);

            return container;
        }
开发者ID:RMcD,项目名称:AngularSkeleton.NET,代码行数:35,代码来源:ContainerConfig.cs

示例4: UriMaker_is_ctor_injected_using_Autofac

        public async Task UriMaker_is_ctor_injected_using_Autofac()
        {
            var config = new HttpConfiguration();
            // Autofac
            var builder = new ContainerBuilder();
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());

            // Web API routes
            var uriMakerContext = config.MapHttpAttributeRoutesAndUseUriMaker();
            builder.RegisterInstance(uriMakerContext).ExternallyOwned();
            builder.RegisterHttpRequestMessage(config);
            builder.RegisterGeneric(typeof(UriMaker<>)).AsSelf().InstancePerRequest();

            var container = builder.Build();
            var resolver = new AutofacWebApiDependencyResolver(container);
            config.DependencyResolver = resolver;
            
            var client = new HttpClient(new HttpServer(config));
            var res = await client.GetAsync("http://www.example.net/api/autofac/resources");
            Assert.Equal(HttpStatusCode.OK,res.StatusCode);
            var body = await res.Content.ReadAsAsync<ResourceState>();
            Assert.Equal("http://www.example.net/api/autofac/resources", body.self.ToString());
            Assert.Equal("http://www.example.net/api/autofac/resources?page=1&count=10", body.next.ToString());
            Assert.Equal("http://www.example.net/api/autofac/resources/0", body.first.ToString());
            Assert.Equal("http://www.example.net/api/autofac/resources/0?detailed=True", body.first_alternative.ToString());

        }
开发者ID:modulexcite,项目名称:drum,代码行数:27,代码来源:InjectionUsingAutofacTests.cs

示例5: ConfigureDependencies

 private void ConfigureDependencies()
 {
     var builder = new ContainerBuilder();
     builder.RegisterHttpRequestMessage(_configuration);
     builder.Register(c => _configuration.Routes).As<HttpRouteCollection>();
     builder.RegisterType<InMemoryBookRepository>().As<IInMemoryBookRepository>().InstancePerApiRequest();
     builder.RegisterType<InMemoryFineRepository>().As<IInMemoryFineRepository>().InstancePerApiRequest();
     builder.RegisterType<GetBookQueryHandler>();
     builder.RegisterType<GetFinesQueryHandler>();
     builder.RegisterType<PayFinesCommandHandler>();
     builder.RegisterType<AllBooksQueryHandler>();
     builder.RegisterType<AddBookCommandHandler>();
     builder.RegisterType<DeleteBookCommandHandler>();
     builder.RegisterType<AllCheckedInBooksQueryHandler>();
     builder.RegisterType<CheckInCommandHandler>();
     builder.RegisterType<AllCheckedOutBooksQueryHandler>();
     builder.RegisterType<CheckOutCommandHandler>();
     builder.RegisterType<BookResourceMapper>();
     builder.RegisterType<GetLibraryRootHandler>();
     builder.RegisterType<HttpUrlProvider>().As<IHttpUrlProvider>();
     builder.RegisterType<ResourceLinker>().As<IResourceLinker>();
     builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
     var container = builder.Build();
     var resolver = new AutofacWebApiDependencyResolver(container);
     _configuration.DependencyResolver = resolver;
 }
开发者ID:robhalevt,项目名称:hyper-library,代码行数:26,代码来源:ApiServiceConfiguration.cs

示例6: RegisterDrum

        private static void RegisterDrum( HttpConfiguration config, ContainerBuilder builder )
        {
            // Web API routes
            UriMakerContext uriMakerContext = config.MapHttpAttributeRoutesAndUseUriMaker();
            builder.RegisterInstance( uriMakerContext ).ExternallyOwned();
            builder.RegisterHttpRequestMessage( config );
            builder.RegisterGeneric( typeof( UriMaker<> ) ).AsSelf().InstancePerRequest();

            builder.RegisterType<DrumUrlProvider>().As<IUrlProvider>();
        }
开发者ID:robzhu,项目名称:Library.WebApi,代码行数:10,代码来源:IoCSettings.cs

示例7: RegisterHttpConfigurationTypes

        /// <summary>
        /// Register types dependent on HTTP configuration
        /// </summary>
        /// <remarks>Utilizes extension methods of the nuget package Autofac.WebApi2</remarks>
        protected void RegisterHttpConfigurationTypes(ContainerBuilder containerBuilder)
        {
            HttpConfiguration httpConfiguration = new HttpConfiguration();

            httpConfiguration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();
            httpConfiguration.EnableCors();
            httpConfiguration.EnableSystemDiagnosticsTracing();
            httpConfiguration.MapHttpAttributeRoutes();

            containerBuilder.RegisterInstance<HttpConfiguration>(httpConfiguration);
            containerBuilder.RegisterWebApiFilterProvider(httpConfiguration); // http://goo.gl/P84rhB
            containerBuilder.RegisterHttpRequestMessage(httpConfiguration); // supports usage of IHttpRequestMessageOperator instead of alternative IQueryString
            containerBuilder.RegisterApiControllers(typeof(AddressesController).Assembly);
        }
开发者ID:TheFastCat,项目名称:XunitHangRepro,代码行数:18,代码来源:ApiAutofacModule.cs

示例8: Configure

        public static void Configure(HttpConfiguration config)
        {
            config.Routes.MapHttpRoute(
                "default", "{controller}/{id}",
                new { id = RouteParameter.Optional });

            var builder = new ContainerBuilder();
            builder.RegisterType<FakeFriendRepository>().As<IFriendRepository>();
            builder.RegisterType<FriendDocumentWriter>().As<ICollectionJsonDocumentWriter<Friend>>();
            builder.RegisterType<FriendDocumentReader>().As<ICollectionJsonDocumentReader<Friend>>();
            builder.RegisterApiControllers(typeof(ServiceConfiguration).Assembly);
            builder.RegisterHttpRequestMessage(config);

            var container = builder.Build();
            var resolver = new AutofacWebApiDependencyResolver(container);
            
            config.DependencyResolver = resolver;
        }
开发者ID:nectide,项目名称:CollectionJson.Net,代码行数:18,代码来源:ServiceConfiguration.cs

示例9: Load

 protected override void Load(ContainerBuilder builder)
 {
     builder.RegisterApiControllers(ThisAssembly);
     //builder.RegisterWebApiFilterProvider(_httpConfiguration);
     builder.RegisterHttpRequestMessage(_httpConfiguration);
 }
开发者ID:jrnail23,项目名称:ConfigCentral,代码行数:6,代码来源:WebApiModule.cs

示例10: RegisterDependencies

        public static void RegisterDependencies(Action<ContainerBuilder> beforeBuild = null)
        {
            var builder = new ContainerBuilder();

            builder.RegisterHttpRequestMessage(GlobalConfiguration.Configuration);

            builder.RegisterAssemblyTypes(
                Assembly.Load("EasyTeach.Web"),
                Assembly.Load("EasyTeach.Data"),
                Assembly.Load("EasyTeach.Core"))
                .AsImplementedInterfaces()
                .AsSelf()
                .Except<EasyTeachContext>(x => x.AsSelf()) //TODO: find a way to create EF context one per API request
                .Except<XmlDocumentationProvider>()
                .Except<LessonService>()
                .Except<GroupService>()
                .Except<VisitService>()
                .Except<ScoreService>()
                .Except<AuthLessonServiceWrapper>()
                .Except<LogLessonServiceWrapper>()
                .Except<AuthGroupServiceWrapper>()
                .Except<LogGroupServiceWrapper>()
                .Except<AuthVisitServiceWrapper>()
                .Except<AuthScoreServiceWrapper>();

            builder.Register<Func<IAuthenticationManager>>(c => () =>
            {
                HttpRequestMessage message = ResolveRequestMessage();
                return message.GetOwinContext().Authentication;
            }).InstancePerRequest();

            builder.Register(c =>
            {
                HttpRequestMessage message = ResolveRequestMessage();
                return (ClaimsPrincipal)message.GetOwinContext().Request.User;
            });
            builder.Register<Func<object, ValidationContext>>(c => o => new ValidationContext(o, new Adapter(), null));
            builder.RegisterType<UserManager<IUserDto, int>>().AsSelf().PropertiesAutowired(PropertyWiringOptions.PreserveSetValues);
            builder.RegisterHttpRequestMessage(GlobalConfiguration.Configuration);

            builder.RegisterType<LessonService>();
            builder.Register<AuthLessonServiceWrapper>(c =>
                new AuthLessonServiceWrapper(
                    c.Resolve<LessonService>(),
                        c.Resolve<ClaimsPrincipal>(),
                        c.Resolve<EntityValidator>(),
                        c.Resolve<IUserStore<IUserDto, int>>(),
                        c.Resolve<Core.Security.ClaimsAuthorizationManager>()
                    ));
            builder.Register<ILessonService>(c => new LogLessonServiceWrapper(c.Resolve<AuthLessonServiceWrapper>()));

            builder.RegisterType<GroupService>();
            builder.Register<AuthGroupServiceWrapper>(c =>
                new AuthGroupServiceWrapper(
                    c.Resolve<GroupService>(),
                        c.Resolve<ClaimsPrincipal>(),
                        c.Resolve<EntityValidator>(),
                        c.Resolve<IUserStore<IUserDto, int>>(),
                        c.Resolve<Core.Security.ClaimsAuthorizationManager>()
                    ));
            builder.Register<IGroupService>(c => new LogGroupServiceWrapper(c.Resolve<AuthGroupServiceWrapper>()));

            //builder.RegisterType<LessonService>().Named<ILessonService>("lessonService");
            //builder.RegisterDecorator<ILessonService>(
            //    (c, inner) =>
            //        new AuthLessonServiceWrapper(
            //            inner,
            //            c.Resolve<ClaimsPrincipal>(),
            //            c.Resolve<EntityValidator>(),
            //            c.Resolve<IUserStore<IUserDto, int>>(),
            //            c.Resolve<Core.Security.ClaimsAuthorizationManager>()),
            //    "lessonService");

            //builder.RegisterDecorator<IGroupService>(
            //    (c, inner) =>
            //    {
            //        return new AuthGroupServiceWrapper(
            //            inner,
            //            c.Resolve<ClaimsPrincipal>(),
            //            c.Resolve<EntityValidator>(),
            //            c.Resolve<IUserStore<IUserDto, int>>(),
            //            c.Resolve<Core.Security.ClaimsAuthorizationManager>());
            //    }, "authGroupsServiceWrapper", "groupService").Named<IGroupService>("logGroupsServiceWrapper");
            //builder.RegisterDecorator<IGroupService>(
            //    (c, inner) => {
            //                      return new LogGroupServiceWrapper(inner);
            //    }, null, "logGroupsServiceWrapper");

            //builder.RegisterType<GroupService>().Named<IGroupService>("groupService");
            //builder.RegisterDecorator<IGroupService>(
            //    (c, inner) =>
            //        new AuthGroupServiceWrapper(
            //            inner,
            //            c.Resolve<ClaimsPrincipal>(),
            //            c.Resolve<EntityValidator>(),
            //            c.Resolve<IUserStore<IUserDto, int>>(),
            //            c.Resolve<Core.Security.ClaimsAuthorizationManager>()),
            //    "groupService");

            builder.RegisterType<VisitService>().Named<IVisitService>("visitService");
//.........这里部分代码省略.........
开发者ID:WadeOne,项目名称:EasyTeach,代码行数:101,代码来源:AutofacConfig.cs

示例11: ConfigureWebApi

        public static void ConfigureWebApi(IAppBuilder app, IContainer container)
        {
            HttpConfiguration config = new HttpConfiguration();

            ContainerBuilder builder = new ContainerBuilder();
            builder.RegisterHttpRequestMessage(config);
            builder.Update(container);

            config.SuppressDefaultHostAuthentication();
            config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));

            config.Formatters.JsonFormatter.SerializerSettings = JsonSerializerSettings;
            // fix for ie9 not supporting json
            config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));

            JsonConvert.DefaultSettings = () => JsonSerializerSettings;

            config.Filters.Add(new NLogTraceFilter());
            config.Filters.Add(new NLogExceptionFilter());
            config.Filters.Add(new DomainErrorExceptionFilter());
            config.Filters.Add(new NoCacheActionFilter());

            config.MapHttpAttributeRoutes(new CustomDirectRouteProvider());

            foreach (IWebApiConfig webApiConfig in container.Resolve<IEnumerable<IWebApiConfig>>())
            {
                webApiConfig.RegisterRoutes(config);
            }

            app.UseAutofacWebApi(config);
            app.UseWebApi(config);
        }
开发者ID:MartinBG,项目名称:Gva,代码行数:32,代码来源:App.cs


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