2021-05-29 17:02:16 +00:00
|
|
|
using System;
|
2021-06-05 21:07:05 +00:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2021-06-05 16:39:47 +00:00
|
|
|
using System.IO;
|
2021-05-28 20:52:56 +00:00
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
using Microsoft.Extensions.Logging;
|
2021-05-29 17:02:16 +00:00
|
|
|
using Microsoft.Extensions.Options;
|
2021-05-30 18:16:01 +00:00
|
|
|
using MongoDB.Driver;
|
2021-06-21 14:46:44 +00:00
|
|
|
using Retroactiune.Core.Interfaces;
|
|
|
|
using Retroactiune.Core.Services;
|
|
|
|
using Retroactiune.Infrastructure;
|
2021-05-28 20:52:56 +00:00
|
|
|
|
|
|
|
namespace Retroactiune
|
|
|
|
{
|
2021-06-05 21:07:05 +00:00
|
|
|
[ExcludeFromCodeCoverage]
|
2021-05-28 20:52:56 +00:00
|
|
|
public class Startup
|
|
|
|
{
|
|
|
|
public Startup(IConfiguration configuration)
|
|
|
|
{
|
|
|
|
Configuration = configuration;
|
|
|
|
}
|
|
|
|
|
|
|
|
private IConfiguration Configuration { get; }
|
|
|
|
|
|
|
|
// This method gets called by the runtime. Use this method to add services to the container.
|
|
|
|
public void ConfigureServices(IServiceCollection services)
|
|
|
|
{
|
2021-05-29 17:02:16 +00:00
|
|
|
// Database Configuration
|
2021-06-11 20:17:03 +00:00
|
|
|
services.Configure<DatabaseSettings>(Configuration.GetSection(nameof(DatabaseSettings)));
|
|
|
|
services.AddSingleton<IDatabaseSettings>(sp =>
|
|
|
|
sp.GetRequiredService<IOptions<DatabaseSettings>>().Value);
|
2021-05-29 17:02:16 +00:00
|
|
|
|
2021-05-30 18:16:01 +00:00
|
|
|
// AutoMapper
|
2021-05-29 17:02:16 +00:00
|
|
|
services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
|
|
|
|
|
2021-06-05 16:39:47 +00:00
|
|
|
|
2021-05-29 17:02:16 +00:00
|
|
|
// Services
|
2021-07-04 14:39:07 +00:00
|
|
|
services.AddSingleton<IFeedbackReceiversService, FeedbackReceiversService>();
|
2021-07-04 11:05:53 +00:00
|
|
|
services.AddSingleton<ITokensService, TokensService>();
|
2021-05-30 18:16:01 +00:00
|
|
|
services.AddSingleton<IMongoClient, MongoClient>(i =>
|
|
|
|
{
|
2021-06-11 20:17:03 +00:00
|
|
|
var settings = i.GetService<IOptions<DatabaseSettings>>();
|
2021-05-30 18:16:01 +00:00
|
|
|
return new MongoClient(settings.Value.ConnectionString);
|
|
|
|
});
|
2021-06-05 16:39:47 +00:00
|
|
|
|
2021-05-29 17:02:16 +00:00
|
|
|
// WebAPI
|
2021-05-28 20:52:56 +00:00
|
|
|
services.AddControllers();
|
2021-06-05 16:39:47 +00:00
|
|
|
services.AddSwaggerGen(c =>
|
|
|
|
{
|
|
|
|
var filePath = Path.Combine(AppContext.BaseDirectory, "Retroactiune.WebAPI.xml");
|
|
|
|
c.IncludeXmlComments(filePath);
|
|
|
|
});
|
2021-05-28 20:52:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILogger<Startup> logger)
|
|
|
|
{
|
|
|
|
if (env.IsDevelopment())
|
|
|
|
{
|
|
|
|
app.UseDeveloperExceptionPage();
|
|
|
|
}
|
2021-05-29 17:02:16 +00:00
|
|
|
|
2021-05-28 20:52:56 +00:00
|
|
|
app.UseSwagger();
|
|
|
|
app.UseSwaggerUI(c =>
|
|
|
|
{
|
|
|
|
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Retroactiune API");
|
|
|
|
c.RoutePrefix = "";
|
|
|
|
});
|
2021-05-29 17:02:16 +00:00
|
|
|
|
2021-05-28 20:52:56 +00:00
|
|
|
app.UseHttpsRedirection();
|
|
|
|
|
|
|
|
app.UseRouting();
|
|
|
|
|
|
|
|
app.UseAuthorization();
|
|
|
|
|
|
|
|
app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
|
2021-05-29 17:02:16 +00:00
|
|
|
|
2021-05-28 20:52:56 +00:00
|
|
|
logger.LogInformation("Running");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|