2020-06-06 18:29:20 +03:00
|
|
|
using AutoMapper;
|
|
|
|
using Chatbot.Api.Authentication;
|
|
|
|
using Chatbot.Api.Domain.Data;
|
|
|
|
using Chatbot.Application;
|
|
|
|
using MediatR;
|
|
|
|
using MediatR.Pipeline;
|
|
|
|
using Microsoft.AspNetCore.Authentication;
|
2020-06-06 16:07:32 +03:00
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
using Microsoft.Extensions.Hosting;
|
2020-12-20 23:07:49 +02:00
|
|
|
using NDB.Extensions.Swagger;
|
2020-06-06 18:29:20 +03:00
|
|
|
using Newtonsoft.Json;
|
|
|
|
using System.Reflection;
|
2020-06-06 16:07:32 +03:00
|
|
|
|
|
|
|
namespace Chatbot.Api
|
|
|
|
{
|
|
|
|
public class Startup
|
|
|
|
{
|
|
|
|
public Startup(IConfiguration configuration)
|
|
|
|
{
|
|
|
|
Configuration = configuration;
|
|
|
|
}
|
|
|
|
|
|
|
|
public IConfiguration Configuration { get; }
|
|
|
|
|
|
|
|
// This method gets called by the runtime. Use this method to add services to the container.
|
|
|
|
public void ConfigureServices(IServiceCollection services)
|
|
|
|
{
|
2020-06-06 18:29:20 +03:00
|
|
|
services.AddControllers()
|
|
|
|
.AddNewtonsoftJson(o => o.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc);
|
|
|
|
|
|
|
|
// configure basic authentication
|
|
|
|
services.AddAuthentication("BasicAuthentication")
|
|
|
|
.AddScheme<AuthenticationSchemeOptions, BasicAuthenticationHandler>("BasicAuthentication", null);
|
|
|
|
|
|
|
|
// 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
|
2020-12-20 23:07:49 +02:00
|
|
|
services.AddSwagger("Chatbot API");
|
2020-06-06 18:29:20 +03:00
|
|
|
|
|
|
|
// Application
|
|
|
|
services.AddApplicationServices();
|
|
|
|
|
|
|
|
// DataAccess
|
|
|
|
services.AddDataAccess();
|
2020-06-06 16:07:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
|
|
|
{
|
2020-06-06 18:29:20 +03:00
|
|
|
// global cors policy
|
|
|
|
app.UseCors(x => x
|
|
|
|
.AllowAnyOrigin()
|
|
|
|
.AllowAnyMethod()
|
|
|
|
.AllowAnyHeader());
|
|
|
|
|
2020-06-06 16:07:32 +03:00
|
|
|
if (env.IsDevelopment())
|
|
|
|
{
|
|
|
|
app.UseDeveloperExceptionPage();
|
|
|
|
}
|
|
|
|
|
|
|
|
app.UseRouting();
|
2020-06-06 18:29:20 +03:00
|
|
|
app.UseAuthentication();
|
2020-06-06 16:07:32 +03:00
|
|
|
app.UseAuthorization();
|
|
|
|
app.UseEndpoints(endpoints =>
|
|
|
|
{
|
|
|
|
endpoints.MapControllers();
|
|
|
|
});
|
2020-12-20 23:07:49 +02:00
|
|
|
app.ConfigureSwagger("Chatbot API");
|
2020-06-06 18:29:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private Assembly[] GetMediatRAssemblies()
|
|
|
|
{
|
|
|
|
var assembly = typeof(Application.Queries.GetBots).Assembly;
|
|
|
|
return new Assembly[] { assembly };
|
2020-06-06 16:07:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|