Files
CartriX/CartriX.Api/Program.cs
T

89 lines
2.2 KiB
C#

//using CartriX.Api.Interfaces;
//using CartriX.Api.Services;
using CartriX.Api.Classes;
using Microsoft.EntityFrameworkCore;
using Scalar.AspNetCore;
using Microsoft.EntityFrameworkCore.Internal;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
//builder.Services.AddScoped<IPrinterService, PrinterService>();
//builder.Services.AddScoped<ICartridgeService, CartridgeService>();
//builder.Services.AddScoped<ILocationService, LocationService>();
//builder.Services.AddScoped<IReportService, ReportService>();
//builder.Services.AddScoped<INetworkService, NetworkService>();
//builder.Services.AddScoped<IManufacturerService, ManufacturerService>();
//builder.Services.AddScoped<IArticleService, ArticleService>();
//builder.Services.AddSingleton<ISnmpService, SnmpService>();
//builder.Services.AddHostedService<BackgroundApiService>();
builder.Services.AddCors(options =>
{
options.AddPolicy("AllowAll", policy =>
{
policy
.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod();
});
});
builder.WebHost.UseUrls(
"http://0.0.0.0:5000"
);
builder.Services.AddOpenApi(options =>
{
options.AddDocumentTransformer((document, context, cancelationToken) =>
{
document.Info = new()
{
Title = "CartriX API"
};
return Task.CompletedTask;
});
});
builder.Services.AddDbContext<AppDbContext>(options =>
{
options.UseSqlite(
builder.Configuration.GetConnectionString("DevSQL"));
});
var app = builder.Build();
app.UseBlazorFrameworkFiles();
app.UseStaticFiles();
app.UseRouting();
app.UseCors("AllowAll");
app.MapControllers();
app.MapFallbackToFile("index.html");
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
app.MapScalarApiReference(options =>
{
options.HideSearch = true;
options.HideModels = true;
options.Layout = ScalarLayout.Modern;
options.DefaultOpenAllTags = false;
options.Agent = new ScalarAgentOptions
{
Disabled = true
};
options.Title = "CartriX API Documentation";
options.Theme = ScalarTheme.DeepSpace;
});
}
app.Run();