本文整理汇总了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));
}
示例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;
}
示例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;
}
示例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());
}
示例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;
}
示例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>();
}
示例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);
}
示例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;
}
示例9: Load
protected override void Load(ContainerBuilder builder)
{
builder.RegisterApiControllers(ThisAssembly);
//builder.RegisterWebApiFilterProvider(_httpConfiguration);
builder.RegisterHttpRequestMessage(_httpConfiguration);
}
示例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");
//.........这里部分代码省略.........
示例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);
}