64 lines
2.1 KiB
C#
64 lines
2.1 KiB
C#
|
|
using Silk_Road_Api.Repositories;
|
|
using Silk_Road_Api.Services;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Silk_Road_Api.DatabaseContext;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Silk_Road_Api;
|
|
|
|
public class Program
|
|
{
|
|
public static void Main(string[] args)
|
|
{
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
// Add services to the container.
|
|
|
|
builder.Services.AddControllers();
|
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
builder.Services.AddSwaggerGen();
|
|
builder.Services.AddDbContext<SilkRoadApiContext>(
|
|
options => options.UseSqlServer(builder.Configuration.GetConnectionString("SilkRoadApiContext"))
|
|
);
|
|
builder.Services.AddScoped<IUserRepository, UserRepository>();
|
|
builder.Services.AddScoped<IUserService, UserService>();
|
|
builder.Services.AddScoped<IDrugRepository, DrugRepository>();
|
|
builder.Services.AddScoped<IManufacturerRepository, ManufacturerRepository>();
|
|
builder.Services.AddScoped<IDrugService, DrugService>();
|
|
builder.Services.AddScoped<IManufacturerService, ManufacturerService>();
|
|
builder.Services.AddAutoMapper(typeof(Program));
|
|
|
|
builder.Services.AddDistributedMemoryCache();
|
|
|
|
builder.Services.AddSession(options =>
|
|
{
|
|
options.Cookie.Name = "SessionId";
|
|
options.Cookie.HttpOnly = true;
|
|
options.Cookie.IsEssential = true;
|
|
});
|
|
|
|
var app = builder.Build();
|
|
|
|
// Configure the HTTP request pipeline.
|
|
//if (app.Environment.IsDevelopment())
|
|
//{
|
|
app.UseSwagger();
|
|
app.UseSwaggerUI();
|
|
//}
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
app.UseAuthorization();
|
|
app.UseCors(builder => builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
|
|
app.UseWebSockets(new WebSocketOptions
|
|
{
|
|
KeepAliveInterval = TimeSpan.FromSeconds(1),
|
|
});
|
|
app.MapControllers();
|
|
app.UseSession();
|
|
app.Run();
|
|
}
|
|
}
|