65 lines
2.2 KiB
C#
65 lines
2.2 KiB
C#
// Copyright (c) 2020 Tudor Stanciu
|
|
|
|
using MediatR;
|
|
using MediatR.Pipeline;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Netmash.Extensions.Swagger;
|
|
using Netmash.Extensions.Swagger.Constants;
|
|
using Netmash.Infrastructure.DatabaseMigration;
|
|
using Netmash.Infrastructure.DatabaseMigration.Constants;
|
|
using Tuitio.Application;
|
|
using Tuitio.Application.Services.Abstractions;
|
|
using Tuitio.Domain.Data;
|
|
|
|
namespace Tuitio.Extensions
|
|
{
|
|
public static class StartupExtensions
|
|
{
|
|
public static void ConfigureServices(this IServiceCollection services, IConfiguration configuration)
|
|
{
|
|
services.AddControllers();
|
|
|
|
// MediatR
|
|
services.AddMediatR(typeof(Application.Commands.AuthenticateUser).Assembly);
|
|
services.AddScoped(typeof(IPipelineBehavior<,>), typeof(RequestPreProcessorBehavior<,>));
|
|
services.AddScoped(typeof(IPipelineBehavior<,>), typeof(RequestPostProcessorBehavior<,>));
|
|
|
|
// AutoMapper
|
|
services.AddAutoMapper(
|
|
typeof(Application.Mappings.MappingProfile).Assembly);
|
|
|
|
// Swagger
|
|
services.AddSwagger("Tuitio API", AuthorizationType.None);
|
|
|
|
// Data access
|
|
services.AddMigration(DatabaseType.SQLServer, MetadataLocation.Database);
|
|
services.AddDataAccess();
|
|
|
|
// Application
|
|
services.AddApplicationServices();
|
|
}
|
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
public static void Configure(this WebApplication app)
|
|
{
|
|
// global cors policy
|
|
app.UseCors(z => z.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
|
|
|
|
app.UseRouting();
|
|
app.UseAuthorization();
|
|
app.UseEndpoints(endpoints =>
|
|
{
|
|
endpoints.MapControllers();
|
|
});
|
|
app.ConfigureSwagger("Tuitio API");
|
|
|
|
app.UseMigration();
|
|
|
|
var behaviorService = app.Services.GetService<IBehaviorService>();
|
|
behaviorService.FillTokenStore();
|
|
}
|
|
}
|
|
}
|