2024-04-19 14:59:45 +08:00
|
|
|
using Canon.Core.Abstractions;
|
2024-04-22 21:26:34 +08:00
|
|
|
using Canon.Core.GrammarParser;
|
2024-04-19 14:59:45 +08:00
|
|
|
using Canon.Core.LexicalParser;
|
2024-04-26 10:18:49 +08:00
|
|
|
using Canon.Core.SemanticParser;
|
2024-04-19 14:59:45 +08:00
|
|
|
using Canon.Server.Extensions;
|
2024-04-29 23:55:36 +08:00
|
|
|
using Canon.Server.Models;
|
2024-04-19 14:59:45 +08:00
|
|
|
using Canon.Server.Services;
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
|
|
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
|
|
|
|
|
|
|
|
string? connectionString = builder.Configuration.GetConnectionString("MongoDB");
|
|
|
|
if (connectionString is null)
|
|
|
|
{
|
|
|
|
throw new InvalidOperationException("Failed to get MongoDB connection string.");
|
|
|
|
}
|
|
|
|
|
|
|
|
builder.Services.AddControllers();
|
|
|
|
builder.Services.AddSwaggerGen();
|
|
|
|
builder.Services.AddDbContext<CompileDbContext>(options =>
|
|
|
|
{
|
|
|
|
options.UseMongoDB(connectionString, "Canon");
|
|
|
|
});
|
|
|
|
builder.Services.AddGridFs(connectionString, "Canon");
|
2024-04-29 23:55:36 +08:00
|
|
|
builder.Services.AddSingleton<ICompilerLogger, CompilerLogger>();
|
2024-04-19 14:59:45 +08:00
|
|
|
builder.Services.AddTransient<ILexer, Lexer>();
|
2024-04-22 21:26:34 +08:00
|
|
|
builder.Services.AddSingleton<IGrammarParser>(
|
2024-04-19 14:59:45 +08:00
|
|
|
_ => GeneratedGrammarParser.Instance);
|
|
|
|
builder.Services.AddSingleton<SyntaxTreePresentationService>();
|
2024-04-26 10:18:49 +08:00
|
|
|
builder.Services.AddSingleton<SyntaxTreeTraveller>();
|
2024-04-19 14:59:45 +08:00
|
|
|
builder.Services.AddTransient<CompilerService>();
|
2024-04-22 21:26:34 +08:00
|
|
|
builder.Services.AddHostedService<DatabaseSetupService>();
|
2024-04-19 14:59:45 +08:00
|
|
|
|
|
|
|
WebApplication application = builder.Build();
|
|
|
|
|
|
|
|
if (application.Environment.IsDevelopment())
|
|
|
|
{
|
|
|
|
application.UseSwagger();
|
|
|
|
application.UseSwaggerUI();
|
|
|
|
}
|
|
|
|
|
|
|
|
application.UseStaticFiles();
|
|
|
|
|
|
|
|
application.MapControllers();
|
|
|
|
application.MapFallbackToFile("/index.html");
|
|
|
|
|
|
|
|
await application.RunAsync();
|