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

61 lines
1.7 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<UserRepository>(); // Register UserRepository
builder.Services.AddControllers();
builder.Services.AddDbContext<OptifitDbContext>(options =>
options.UseSqlite("Data Source=FirstTest.db"));
// Register AutoMapper
builder.Services.AddAutoMapper(typeof(UsersMappers));
// 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();