C
C#2y ago
Pandetthe

❔ 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
Pandetthe
PandettheOP2y ago
.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();
}
JakenVeina
JakenVeina2y ago
define "enable console input"
Pandetthe
PandettheOP2y ago
? A oh, I want to add some test commands That can be written in console
JakenVeina
JakenVeina2y ago
as in you want to be table to type commands into the console, while the application is running? assuming it launches within a console?
Accord
Accord2y ago
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.
Want results from more Discord servers?
Add your server