86 lines
2.8 KiB
C#
86 lines
2.8 KiB
C#
using AutoMapper;
|
|
using IdentityServer.Application;
|
|
using IdentityServer.Application.Services.Abstractions;
|
|
using IdentityServer.Domain.Data;
|
|
using MediatR;
|
|
using MediatR.Pipeline;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using NDB.Extensions.Swagger;
|
|
using NDB.Extensions.Swagger.Constants;
|
|
using Newtonsoft.Json;
|
|
using System.Reflection;
|
|
|
|
namespace IdentityServer.Api
|
|
{
|
|
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.
|
|
public void ConfigureServices(IServiceCollection services)
|
|
{
|
|
services.AddControllers()
|
|
.AddNewtonsoftJson(o => o.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc);
|
|
|
|
// MediatR
|
|
services.AddMediatR(GetMediatRAssemblies());
|
|
services.AddScoped(typeof(IPipelineBehavior<,>), typeof(RequestPreProcessorBehavior<,>));
|
|
services.AddScoped(typeof(IPipelineBehavior<,>), typeof(RequestPostProcessorBehavior<,>));
|
|
|
|
// AutoMapper
|
|
services.AddAutoMapper(
|
|
typeof(Application.Mappings.MappingProfile).Assembly);
|
|
|
|
// Swagger
|
|
services.AddSwagger("Identity Server API", AuthorizationType.None);
|
|
|
|
// Data access
|
|
services.AddDataAccess();
|
|
|
|
// Application
|
|
services.AddApplicationServices();
|
|
}
|
|
|
|
private Assembly[] GetMediatRAssemblies()
|
|
{
|
|
var assembly = typeof(Application.Commands.AuthenticateUser).Assembly;
|
|
return new Assembly[] { assembly };
|
|
}
|
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
|
{
|
|
// global cors policy
|
|
app.UseCors(x => x
|
|
.AllowAnyOrigin()
|
|
.AllowAnyMethod()
|
|
.AllowAnyHeader());
|
|
|
|
if (env.IsDevelopment())
|
|
{
|
|
app.UseDeveloperExceptionPage();
|
|
}
|
|
|
|
app.UseRouting();
|
|
app.UseAuthorization();
|
|
app.UseEndpoints(endpoints =>
|
|
{
|
|
endpoints.MapControllers();
|
|
});
|
|
app.ConfigureSwagger("IdentityServer API");
|
|
|
|
var behaviorService = app.ApplicationServices.GetService<IBehaviorService>();
|
|
behaviorService.FillTokenStore();
|
|
}
|
|
}
|
|
}
|