Canon/Canon.Server/Program.cs
Ichirinko dbbab1c761 feat-visualization (#33)
尽管里面有点粪,但还是生成了漂亮的树,就当给树施肥了
剩下一个小问题:未考虑节点的宽度(因为名称不一样长),但目前未发现对图生成的明显影响

Co-authored-by: jackfiled <xcrenchangjun@outlook.com>
Reviewed-on: PostGuard/Canon#33
Co-authored-by: Ichirinko <1621543655@qq.com>
Co-committed-by: Ichirinko <1621543655@qq.com>
2024-04-19 14:59:45 +08:00

43 lines
1.3 KiB
C#

using Canon.Core.Abstractions;
using Canon.Core.LexicalParser;
using Canon.Server.Extensions;
using Canon.Server.Services;
using Canon.Visualization.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");
builder.Services.AddTransient<ILexer, Lexer>();
builder.Services.AddSingleton<IGrammarParser, GeneratedGrammarParser>(
_ => GeneratedGrammarParser.Instance);
builder.Services.AddSingleton<SyntaxTreePresentationService>();
builder.Services.AddTransient<CompilerService>();
WebApplication application = builder.Build();
if (application.Environment.IsDevelopment())
{
application.UseSwagger();
application.UseSwaggerUI();
}
application.UseStaticFiles();
application.MapControllers();
application.MapFallbackToFile("/index.html");
await application.RunAsync();