❔ Console input
Hi, is it possible to enable console input in web sdk using Host?
public static async Task Main(string[] args)
{
using IHost host = Host.CreateDefaultBuilder(args)
.ConfigureHostConfiguration(configHost =>
{
configHost.SetBasePath(Directory.GetCurrentDirectory());
configHost.AddJsonFile("Config/hostsettings.json", optional: true);
configHost.AddCommandLine(args);
})
.ConfigureAppConfiguration((hostContext, configApp) =>
{
configApp.AddJsonFile("Config/appsettings.json", optional: true);
configApp.AddJsonFile(
$"Config/appsettings.{hostContext.HostingEnvironment.EnvironmentName}.json",
optional: true);
configApp.AddCommandLine(args);
})
.ConfigureLogging((hostContext, configLogging) =>
{
configLogging.AddConfiguration(hostContext.Configuration.GetSection("Logging"));
configLogging.AddConsole();
configLogging.AddDebug();
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>().ConfigureLogging(logging =>
{
logging.AddConsole();
logging.AddDebug();
}).UseKestrel();
})
public static async Task Main(string[] args)
{
using IHost host = Host.CreateDefaultBuilder(args)
.ConfigureHostConfiguration(configHost =>
{
configHost.SetBasePath(Directory.GetCurrentDirectory());
configHost.AddJsonFile("Config/hostsettings.json", optional: true);
configHost.AddCommandLine(args);
})
.ConfigureAppConfiguration((hostContext, configApp) =>
{
configApp.AddJsonFile("Config/appsettings.json", optional: true);
configApp.AddJsonFile(
$"Config/appsettings.{hostContext.HostingEnvironment.EnvironmentName}.json",
optional: true);
configApp.AddCommandLine(args);
})
.ConfigureLogging((hostContext, configLogging) =>
{
configLogging.AddConfiguration(hostContext.Configuration.GetSection("Logging"));
configLogging.AddConsole();
configLogging.AddDebug();
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>().ConfigureLogging(logging =>
{
logging.AddConsole();
logging.AddDebug();
}).UseKestrel();
})
5 Replies
.ConfigureServices((hostBuilder, services) =>
{
services.AddDbContext<MainDbContext>(options =>
options.UseSqlServer(hostBuilder.Configuration.GetConnectionString("DefaultConnection")));
services.AddTransient<IStartupFilter, DataContextAutomaticMigrationStartupFilter<MainDbContext>>();
services.AddSingleton<IAuthService, AuthService>();
services.AddHostedService<StartupService>();
services.AddHostedService<MailSenderService>();
services.AddHostedService<SalesSweepService>();
})
.UseConsoleLifetime()
.Build();
await host.RunAsync();
}
.ConfigureServices((hostBuilder, services) =>
{
services.AddDbContext<MainDbContext>(options =>
options.UseSqlServer(hostBuilder.Configuration.GetConnectionString("DefaultConnection")));
services.AddTransient<IStartupFilter, DataContextAutomaticMigrationStartupFilter<MainDbContext>>();
services.AddSingleton<IAuthService, AuthService>();
services.AddHostedService<StartupService>();
services.AddHostedService<MailSenderService>();
services.AddHostedService<SalesSweepService>();
})
.UseConsoleLifetime()
.Build();
await host.RunAsync();
}
define "enable console input"
?
A oh, I want to add some test commands
That can be written in console
as in
you want to be table to type commands into the console, while the application is running?
assuming it launches within a console?
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.