| | | 1 | | /* |
| | | 2 | | * Program.cs |
| | | 3 | | * event-list |
| | | 4 | | * |
| | | 5 | | * Created by Tiago Amaral on 05/09/2025. |
| | | 6 | | * Copyright ©2024 Tiago Amaral. All rights reserved. |
| | | 7 | | */ |
| | | 8 | | |
| | | 9 | | using System.Reflection; |
| | | 10 | | using Microsoft.EntityFrameworkCore; |
| | | 11 | | |
| | | 12 | | using event_list.modules.eventlist.infra; |
| | | 13 | | using event_list.modules.eventlist.storage; |
| | | 14 | | using event_list.modules.eventlist.services; |
| | | 15 | | using event_list.shared.Middlewares; |
| | | 16 | | |
| | 0 | 17 | | var builder = WebApplication.CreateBuilder(args); |
| | | 18 | | |
| | | 19 | | // Add services to the container. |
| | | 20 | | // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle |
| | 0 | 21 | | builder.Services.AddControllers(); |
| | 0 | 22 | | builder.Services.AddEndpointsApiExplorer(); |
| | 0 | 23 | | builder.Services.AddSwaggerGen( c => { |
| | 0 | 24 | | var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; |
| | 0 | 25 | | var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); |
| | 0 | 26 | | c.IncludeXmlComments(xmlPath); |
| | 0 | 27 | | }); |
| | | 28 | | |
| | | 29 | | // Removendo CORS |
| | 0 | 30 | | builder.Services.AddCors(options => |
| | 0 | 31 | | { |
| | 0 | 32 | | options.AddPolicy("AllowAll", |
| | 0 | 33 | | policy => |
| | 0 | 34 | | { |
| | 0 | 35 | | policy.AllowAnyOrigin() |
| | 0 | 36 | | .AllowAnyMethod() |
| | 0 | 37 | | .AllowAnyHeader(); |
| | 0 | 38 | | }); |
| | 0 | 39 | | }); |
| | | 40 | | |
| | | 41 | | // Custom Module |
| | 0 | 42 | | builder.Services.AddDbContext<EventListDbContext>(options => |
| | 0 | 43 | | options.UseInMemoryDatabase("EventListDb")); |
| | | 44 | | |
| | 0 | 45 | | builder.Services.AddScoped<EventListDbContext>(); |
| | 0 | 46 | | builder.Services.AddScoped<IEventListStorage, EventListStorage>(); |
| | 0 | 47 | | builder.Services.AddScoped<IEventListDeleteByIdentifierService, EventListDeleteByIdentifierService>(); |
| | 0 | 48 | | builder.Services.AddScoped<IEventListFetchByIdentifierService, EventListFetchByIdentifierService>(); |
| | 0 | 49 | | builder.Services.AddScoped<IEventListFetchService, EventListFetchService>(); |
| | 0 | 50 | | builder.Services.AddScoped<IEventListSaveService, EventListSaveService>(); |
| | | 51 | | |
| | 0 | 52 | | builder.Services.AddScoped<IEventListServices, EventListServices>(); |
| | 0 | 53 | | builder.Services.AddScoped<EventListController>(); |
| | | 54 | | |
| | 0 | 55 | | var app = builder.Build(); |
| | | 56 | | |
| | | 57 | | // Configure the HTTP request pipeline. |
| | 0 | 58 | | if (app.Environment.IsDevelopment()) { |
| | 0 | 59 | | app.UseCors("AllowAll"); |
| | 0 | 60 | | app.UseSwagger(); |
| | 0 | 61 | | app.UseSwaggerUI(); |
| | 0 | 62 | | } |
| | 0 | 63 | | app.UseMiddleware<CustomHeaderResponse>(); |
| | 0 | 64 | | app.UseMiddleware<ExceptionMiddleware>(); |
| | 0 | 65 | | app.MapControllers(); |
| | 0 | 66 | | app.UseHttpsRedirection(); |
| | 0 | 67 | | app.Run(); |