public ReportingServicesHealthCheck(ReportingServicesConfiguration reportingServicesConfiguration) { _reportingServicesConfiguration = reportingServicesConfiguration ?? throw new ArgumentNullException(nameof(reportingServicesConfiguration)); // Setting for ASP.NET Core on Linux: https://github.com/dotnet/corefx/issues/28961#issuecomment-400803703 AppContext.SetSwitch("System.Net.Http.UseSocketsHttpHandler", false); }
/// <summary> /// Creates a new <see cref="AzureServiceBusReportingServices"/> /// instance with the specified configuration. /// </summary> /// <param name="configuration"> /// The configuration for the client, specifying how to communicate /// with RSMassTransit. /// </param> public AzureServiceBusReportingServices(ReportingServicesConfiguration configuration) : base(configuration) { }
// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { var reportingServicesConfiguration = new ReportingServicesConfiguration(); Configuration.GetSection("ReportingServices").Bind(reportingServicesConfiguration); services.AddHealthChecks() .AddCheck("self", () => HealthCheckResult.Healthy()) .AddSqlServer(Configuration["Database:ConnectionString"], tags: new[] { "services" }) .AddReportingServicesHealthCheck(reportingServicesConfiguration); services.AddCors(options => { options.AddPolicy( "CorsPolicy", builder => builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials()); }); services.AddMvc(options => { options.CacheProfiles.Add( "Never", new CacheProfile { Location = ResponseCacheLocation.None, NoStore = true }); options.Filters.Add(new AuthorizeFilter(new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build())); options.Filters.Add <AtlasLogEnrichmentFilter>(); options.Filters.Add <ContextInformationFilter>(); }) .SetCompatibilityVersion(CompatibilityVersion.Version_2_2) .AddJsonOptions(opt => { opt.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc; opt.SerializerSettings.DateFormatHandling = DateFormatHandling.IsoDateFormat; opt.SerializerSettings.DateParseHandling = DateParseHandling.DateTime; opt.SerializerSettings.Converters.Add(new TrimmingConverter()); }); // This code is added AFTER app.UseMvc(); otherwise it will not work. services.ConfigureInvalidModelStateResponseFactory(); // ApplicationInsights services.AddSingleton <ITelemetryInitializer, ServiceContextTelemetryIntitializer>(); services.AddSingleton <ITelemetryInitializer, UserTelemetryInitializer>(); services.AddApplicationInsightsTelemetry(Configuration); // Register Configuration objects services.Configure <DatabaseConfiguration>(Configuration.GetSection("Database")); services.Configure <ApplicationInsightsConfiguration>(Configuration.GetSection("ApplicationInsights")); services.AddApplicationInsightsKubernetesEnricher(); JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear(); var tokenValidationParameters = new TokenValidationParameters { NameClaimType = AtlasClaimTypes.UniqueName }; // Add Authentication services. services.AddAuthentication(sharedOptions => { sharedOptions.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(cfg => { cfg.Audience = Configuration["OAuth2:ClientId"]; cfg.Authority = Configuration["OAuth2:Authority"]; cfg.RequireHttpsMetadata = false; cfg.SaveToken = true; cfg.TokenValidationParameters = tokenValidationParameters; }); // Adds a default implementation for IHttpContextAccessor services.AddHttpContextAccessor(); services.AddAtlasIdentityService(); // Add custom authorization services and the authorization handlers to the services services.AddAtlasAuthorizationServices(Configuration) .AddAtlasPrivilegeAuthorizationHandlers(); services.AddExecutionAuthorizationPolicies(); // Register Hosted Services services.AddTransient <Atlas.Infrastructure.Services.Logging.ILogger, ApplicationInsightsLogger>(); services.AddScoped <IDapperContext, DapperContext>(); services.AddScoped <IUnitOfWork, DapperUnitOfWork>(); services.AddScoped <IContextInformation, ContextInformation>(); services.Configure <ReportingServicesConfiguration>(Configuration.GetSection("ReportingServices")); // Add custom authorization handlers services.AddScoped <IAuthorizationHandler, CreateCashHandler>(); // Register all Handlers and Pre/PostProcessors in a given assembly. services.AddMediatR(typeof(Startup).Assembly); Mapper.Initialize(cfg => cfg.AddProfile <MappingProfile>()); services.AddAutoMapper(); if (Configuration["SwaggerGen"].Equals(bool.TrueString, StringComparison.InvariantCultureIgnoreCase)) { services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "Execution API", Version = "v1" }); c.AddSecurityDefinition("Bearer", new ApiKeyScheme { Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"", Name = "Authorization", In = "header", Type = "apiKey" }); c.DescribeAllParametersInCamelCase(); c.OperationFilter <AddResponseHeadersFilter>(); // To use the [SwaggerResponseHeader] attribute c.DocumentFilter <LowercaseDocumentFilter>(); // To lowercase the URIs // Set the comments path for the Swagger JSON and UI. var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); c.IncludeXmlComments(xmlPath); var security = new System.Collections.Generic.Dictionary <string, System.Collections.Generic.IEnumerable <string> > { { "Bearer", Array.Empty <string>() }, }; c.AddSecurityRequirement(security); }); } var containerBuilder = new ContainerBuilder(); containerBuilder.Populate(services); containerBuilder.RegisterModule(new MediatorModule()); // Register types from LDC.Atlas.Application.Common containerBuilder.RegisterModule(new Atlas.Application.Common.MediatorModule()); // Register types from LDC.Atlas.MasterData.Common containerBuilder.RegisterModule(new MasterData.Common.MediatorModule()); // Register types from LDC.Atlas.Document.Common containerBuilder.RegisterModule(new Document.Common.MediatorModule()); // Create the IServiceProvider based on the container. return(new AutofacServiceProvider(containerBuilder.Build())); }
/// <summary> /// Creates a new <see cref="RabbitMqReportingServices"/> /// instance with the specified configuration. /// </summary> /// <param name="configuration"> /// The configuration for the client, specifying how to communicate /// with RSMassTransit. /// </param> public RabbitMqReportingServices(ReportingServicesConfiguration configuration) : base(configuration) { }
/// <summary> /// Add a health check for SqlServer services. /// </summary> /// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param> /// <param name="reportingServicesConfiguration">The SSRS configuration to be used.</param> /// <param name="name">The health check name. Optional. If <c>null</c> the type name 'reportingservices' will be used for the name.</param> /// <param name="failureStatus"> /// The <see cref="HealthStatus"/> that should be reported when the health check fails. Optional. If <c>null</c> then /// the default status of <see cref="HealthStatus.Unhealthy"/> will be reported. /// </param> /// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param> /// <returns>The <see cref="IHealthChecksBuilder"/>.</returns> public static IHealthChecksBuilder AddReportingServicesHealthCheck(this IHealthChecksBuilder builder, ReportingServicesConfiguration reportingServicesConfiguration, string name = null, HealthStatus?failureStatus = HealthStatus.Unhealthy, IEnumerable <string> tags = null) { return(builder.Add(new HealthCheckRegistration( name ?? ReportingServicesName, sp => new ReportingServicesHealthCheck(reportingServicesConfiguration), failureStatus, tags))); }