Cocona
Cocona copied to clipboard
Integrate with ASP.NET Core
Is there anyway to not use the ASP.NET Core CLI parser but Cocona instead, as it would greatly help to integrate https://github.com/buehler/dotnet-operator-sdk to use just one hosted app instead of making two.
This example works:
Program.cs:
var builder = CoconaApp.CreateBuilder(args);
builder.Services.AddSingleton<EmailService>();
var app = builder.Build();
app.AddCommands<EmailCommand>();
app.AddCommand(ExecuteAspNetCore);
app.Run();
void ExecuteAspNetCore()
{
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddControllers();
builder.Services.AddSqlServer<MyDbContext>(
builder.Configuration.GetConnectionString(MyDbContext.ConnectionStringName));
var app = builder.Build();
app.MapControllers();
app.UseSwagger();
app.UseSwaggerUI(options => options.EnableTryItOutByDefault());
app.Run();
}
This example works:
Program.cs:
var builder = CoconaApp.CreateBuilder(args); builder.Services.AddSingleton<EmailService>(); var app = builder.Build(); app.AddCommands<EmailCommand>(); app.AddCommand(ExecuteAspNetCore); app.Run(); void ExecuteAspNetCore() { var builder = WebApplication.CreateBuilder(args); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); builder.Services.AddControllers(); builder.Services.AddSqlServer<MyDbContext>( builder.Configuration.GetConnectionString(MyDbContext.ConnectionStringName)); var app = builder.Build(); app.MapControllers(); app.UseSwagger(); app.UseSwaggerUI(options => options.EnableTryItOutByDefault()); app.Run(); }
That's exactly the problem. First you have two sets of hosted builders and doesn't share with each other, and so some services are often duplicated, and that also means I possibly have to manage two builders like config hot reload and stuff...
Also, its not compatible with WebApplicationFactory