-
Notifications
You must be signed in to change notification settings - Fork 42
Closed
Description
Currently the hosting syntax looks similar to the following:
await AppHost.RunAsync<App>(null, builder =>
{
builder.ConfigureServices(services =>
{
services.AddSingleton<ILoggerManager, LoggerManager>();
});
});This has the following issues:
- The order of operations is out of order which is slightly confusing, such that RunAsync comes first but runs last, with the builder inside doing the most heavy lifting.
- Syntax is not like modern builders, and is more similar to the obsolete IHostBuilder generic host with actions, rather than the fluent application builder style that superceded that syntax.
- Heavy nesting makes it harder to read and reduces flexibility in cross-collection configuration, such as if you want to get a service from service collection and use that elsewhere, such as IConfiguration.
I propose we switch to the following syntax more inline with modern application builders:
// Creates a builder with arguments already supplied, adding them to IConfiguration through builder.Configuration.AddCommandLine(args) or some IOptions alternative.
ConsoleAppBuilder builder = RazorConsole.CreateBuilder(args);
// Add services to the container.
builder.Services.AddSingleton<ILoggerManager, LoggerManager>();
builder.Services.AddSingleton<WeatherForecastService>();
// Resolves dependencies, configuration and creates the console app.
ConsoleApp<App> app = builder.Build<App>();
// Other app configuration now that services are instantiated for app.Services.GetService().
// App is now running and rendering.
await app.RunAsync(token: default);Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels