2024-12-09 03:27:18 +04:00
|
|
|
|
using Domain.Repository;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using Persistence;
|
|
|
|
|
using Persistence.Repositories;
|
|
|
|
|
using Services;
|
|
|
|
|
using Services.Abstractions;
|
|
|
|
|
using Services.Profiles;
|
|
|
|
|
|
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
2024-12-10 19:20:51 +04:00
|
|
|
|
var configuration = builder.Configuration;
|
|
|
|
|
|
2024-12-11 01:51:02 +04:00
|
|
|
|
var connectionString = builder.Configuration.GetConnectionString("Database");
|
|
|
|
|
|
2024-12-09 03:27:18 +04:00
|
|
|
|
builder.Services.AddControllers();
|
|
|
|
|
|
|
|
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
|
|
|
builder.Services.AddSwaggerGen();
|
2024-12-10 19:20:51 +04:00
|
|
|
|
|
2024-12-18 02:14:21 +04:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> CORS
|
|
|
|
|
builder.Services.AddCors(options =>
|
|
|
|
|
{
|
|
|
|
|
options.AddPolicy("AllowFrontend",
|
|
|
|
|
policy =>
|
|
|
|
|
{
|
|
|
|
|
policy.WithOrigins("http://localhost:3000")
|
|
|
|
|
.AllowAnyHeader()
|
|
|
|
|
.AllowAnyMethod();
|
|
|
|
|
});
|
|
|
|
|
});
|
2024-12-10 19:20:51 +04:00
|
|
|
|
|
2024-12-09 03:27:18 +04:00
|
|
|
|
builder.Services.AddScoped<IRegionService, RegionService>();
|
|
|
|
|
builder.Services.AddScoped<ICityService, CityService>();
|
|
|
|
|
builder.Services.AddScoped<IStreetService, StreetService>();
|
|
|
|
|
|
|
|
|
|
builder.Services.AddScoped<IRegionRepository, RegionRepository>();
|
|
|
|
|
builder.Services.AddScoped<ICityRepository, CityRepository>();
|
|
|
|
|
builder.Services.AddScoped<IStreetRepository, StreetRepository>();
|
|
|
|
|
|
2024-12-11 01:51:02 +04:00
|
|
|
|
builder.Services.AddDbContext<RepositoryDbContext>(
|
|
|
|
|
options =>
|
|
|
|
|
{
|
|
|
|
|
options.UseNpgsql(connectionString);
|
|
|
|
|
});
|
|
|
|
|
|
2024-12-09 03:27:18 +04:00
|
|
|
|
builder.Services.AddAutoMapper(typeof(MappingProfile));
|
2024-12-18 02:14:21 +04:00
|
|
|
|
|
2024-12-09 03:27:18 +04:00
|
|
|
|
var app = builder.Build();
|
2024-12-11 01:51:02 +04:00
|
|
|
|
|
2024-12-09 03:27:18 +04:00
|
|
|
|
if (app.Environment.IsDevelopment())
|
|
|
|
|
{
|
|
|
|
|
app.UseSwagger();
|
|
|
|
|
app.UseSwaggerUI();
|
|
|
|
|
}
|
2024-12-18 02:14:21 +04:00
|
|
|
|
|
2024-12-09 03:27:18 +04:00
|
|
|
|
app.UseHttpsRedirection();
|
2024-12-18 02:14:21 +04:00
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> CORS <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
app.UseCors("AllowFrontend");
|
|
|
|
|
|
2024-12-09 03:27:18 +04:00
|
|
|
|
app.UseAuthorization();
|
|
|
|
|
app.MapControllers();
|
2024-12-18 02:14:21 +04:00
|
|
|
|
app.Run();
|