You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
OptifitWebService/Server/Program.cs

75 lines
2.5 KiB

using Infrastructure;
using Microsoft.EntityFrameworkCore;
using Server.IServices;
using Asp.Versioning;
using Server.Services;
using Microsoft.OpenApi.Models;
using Infrastructure.Repositories;
using AutoMapper;
using Server.Mappers;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddScoped<IUsersService, UsersService>();
builder.Services.AddScoped<IExerciceService, ExerciceService>();
builder.Services.AddScoped<ISessionService, SessionService>();
builder.Services.AddScoped<ITrainingProgramService, TrainingProgramService>();
builder.Services.AddScoped<IUserRepository, UserRepository>();
builder.Services.AddScoped<IExerciceRepository, ExerciceRepository>();
builder.Services.AddScoped<ISessionRepository, SessionRepository>();
builder.Services.AddScoped<ITrainingProgramRepository, TrainingProgramRepository>();
builder.Services.AddControllers();
builder.Services.AddDbContext<OptifitDbContext>(options =>
options.UseSqlite("Data Source=../Server/FirstTest.db", b => b.MigrationsAssembly("Infrastructure")));
// Register AutoMapper
builder.Services.AddAutoMapper(typeof(UserProfile));
builder.Services.AddAutoMapper(typeof(ExerciceProfile));
builder.Services.AddAutoMapper(typeof(SessionProfile));
builder.Services.AddAutoMapper(typeof(PaginatedResultProfile));
builder.Services.AddAutoMapper(typeof(TrainingProgramProfile));
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
// Add API's versioning
builder.Services.AddApiVersioning(options =>
{
options.DefaultApiVersion = new ApiVersion(1, 0);
options.AssumeDefaultVersionWhenUnspecified = true;
options.ReportApiVersions = true;
})
.AddApiExplorer(options =>
{
options.GroupNameFormat = "'v'VVV";
options.SubstituteApiVersionInUrl = true;
});
builder.Services.AddSwaggerGen(c =>
c.SwaggerDoc("v1", new OpenApiInfo { Title = "Optifit API", Version = "v1" })
);
builder.Services.AddRouting(options => options.LowercaseUrls = true);
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Optifit API v1");
c.RoutePrefix = string.Empty; // Serve Swagger UI at the app's root
});
app.UseHttpsRedirection();
}
app.UseAuthorization();
app.MapControllers();
app.Run();