102 lines
4.2 KiB
C#
102 lines
4.2 KiB
C#
using Hangfire;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.ApiExplorer;
|
|
using Microsoft.AspNetCore.Mvc.ApplicationModels;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Strata.ApiLib.Core;
|
|
using Strata.ApiLib.Core.Cors.Extensions;
|
|
using Strata.ApiLib.Core.Transformers;
|
|
using Strata.CoreLib.Claims.Extensions;
|
|
using Strata.Hangfire.AspNetCore.Filters.Dashboard;
|
|
using Strata.RxNorm.Api.Generics;
|
|
using Strata.RxNorm.Biz.Configurations;
|
|
using Strata.SignalR.Configuration;
|
|
using Strata.SwaggerExtensions;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using System.Net.Mime;
|
|
using System.Text.Json;
|
|
|
|
namespace Strata.RxNorm.Api
|
|
{
|
|
[ExcludeFromCodeCoverage]
|
|
public class Startup
|
|
{
|
|
private readonly IConfiguration _configuration;
|
|
|
|
public Startup(IConfiguration configuration)
|
|
{
|
|
_configuration = configuration;
|
|
}
|
|
|
|
// This method gets called by the runtime. Use this method to add services to the container.
|
|
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
|
|
public void ConfigureServices(IServiceCollection services)
|
|
{
|
|
services.AddStrataPlatformServices(_configuration);
|
|
services.AddControllers(options =>
|
|
{
|
|
//Prevent browsers from caching API responses (this addresses an IE11 issue):
|
|
options.Filters.Add(
|
|
new ResponseCacheAttribute()
|
|
{
|
|
Location = ResponseCacheLocation.None,
|
|
NoStore = false,
|
|
Duration = -1
|
|
});
|
|
options.ReturnHttpNotAcceptable = true;
|
|
options.Filters.Add(new ProducesAttribute(MediaTypeNames.Application.Json));
|
|
options.Filters.Add(new ConsumesAttribute(MediaTypeNames.Application.Json));
|
|
options.Conventions.Add(new RouteTokenTransformerConvention(new SlugifyParameterTransformer()));
|
|
})
|
|
.AddJsonOptions(options =>
|
|
{
|
|
options.JsonSerializerOptions.PropertyNameCaseInsensitive = true;
|
|
options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
|
|
|
|
// Uncomment this line if you want enum to be serialized / deserialized as string value instead of int value
|
|
//options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
|
|
});
|
|
|
|
services.AddAuthorizationBuilder()
|
|
.AddPolicy(Policies.IsAdmin, policy => policy.RequireAssertion(context => context.User.IsInRole("CI - System Administrator") || context.User.IsSdtEmployee()))
|
|
.AddPolicy(Policies.StrataOnly, policy => policy.RequireAssertion(context => context.User.IsSdtEmployee()));
|
|
|
|
// configure hangfire
|
|
services.AddStrataHangfire();
|
|
services.AddRxNormServices(_configuration);
|
|
|
|
services.AddRouting();
|
|
services.AddSwagger(_configuration);
|
|
services.AddStrataSignalR();
|
|
services.AddStrataHealthChecks(_configuration);
|
|
|
|
services.AddStrataCors(_configuration);
|
|
services.AddHealthChecks();
|
|
}
|
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IApiVersionDescriptionProvider provider)
|
|
{
|
|
app.UseRouting();
|
|
app.UseStrataCorsPolicy(env);
|
|
|
|
#if DEBUG
|
|
app.UseHangfireDashboard("/hangfire", new DashboardOptions
|
|
{
|
|
Authorization = [new AllowAnyoneDashboardAuthorizationFilter()]
|
|
});
|
|
#endif
|
|
app.UseAccessTokenQueryStringMiddleware();
|
|
app.UseStrataPlatformMiddleware();
|
|
app.ConfigureSwagger(env, provider);
|
|
|
|
app.UseEndpoints(endpoints => endpoints.MapControllers().RequireAuthorization());
|
|
app.UseEndpoints(endpoints => endpoints.MapNotificationHub());
|
|
app.UseStrataHealthChecks(env);
|
|
}
|
|
}
|
|
}
|