/// <summary> /// 配置应用程序 /// </summary> public void Configure(IApplicationBuilder appBuilder) { //配置WCF服务 ServiceMetadataBehavior metadataBehavior = appBuilder.ApplicationServices.GetRequiredService <ServiceMetadataBehavior>(); metadataBehavior.HttpGetEnabled = true; metadataBehavior.HttpsGetEnabled = true; UseRequestHeadersForMetadataAddressBehavior addressBehavior = new UseRequestHeadersForMetadataAddressBehavior(); DependencyInjectionBehavior dependencyInjectionBehavior = new DependencyInjectionBehavior(); InitializationBehavior initializationBehavior = new InitializationBehavior(); IList <IServiceBehavior> serviceBehaviors = new List <IServiceBehavior> { addressBehavior, dependencyInjectionBehavior, initializationBehavior }; if (AspNetSetting.Authorized) { AuthenticationBehavior authenticationBehavior = new AuthenticationBehavior(); serviceBehaviors.Add(authenticationBehavior); } appBuilder.UseServiceModel(builder => { builder.ConfigureServiceHostBase <AuthenticationContract>(host => host.Description.Behaviors.AddRange(serviceBehaviors)); builder.ConfigureServiceHostBase <AuthorizationContract>(host => host.Description.Behaviors.AddRange(serviceBehaviors)); builder.ConfigureServiceHostBase <UserContract>(host => host.Description.Behaviors.AddRange(serviceBehaviors)); }); }
public DependencyInjectionAttribute(Type objectFactory) { if (!objectFactory.CastableAs<IDependencyResolver>()) throw new Exception("objectFactory must implement IObjectFactory."); _behavior = new DependencyInjectionBehavior(objectFactory); }
/// <summary> /// 配置应用程序 /// </summary> public void Configure(IApplicationBuilder appBuilder) { //配置WCF服务 ServiceMetadataBehavior metadataBehavior = appBuilder.ApplicationServices.GetRequiredService <ServiceMetadataBehavior>(); metadataBehavior.HttpGetEnabled = true; metadataBehavior.HttpsGetEnabled = true; UseRequestHeadersForMetadataAddressBehavior addressBehavior = new UseRequestHeadersForMetadataAddressBehavior(); DependencyInjectionBehavior dependencyInjectionBehavior = new DependencyInjectionBehavior(); IList <IServiceBehavior> serviceBehaviors = new List <IServiceBehavior> { addressBehavior, dependencyInjectionBehavior }; appBuilder.UseServiceModel(builder => { builder.ConfigureServiceHostBase <ProductService>(host => host.Description.Behaviors.AddRange(serviceBehaviors)); }); }