45 lines
1.4 KiB
C#
45 lines
1.4 KiB
C#
|
|
using Microsoft.Extensions.Configuration;
|
|||
|
|
using Microsoft.Extensions.DependencyInjection;
|
|||
|
|
using Microsoft.Extensions.Hosting;
|
|||
|
|
|
|||
|
|
namespace JiShe.CollectBus.Console
|
|||
|
|
{
|
|||
|
|
internal class Program
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
static void Main(string[] args)
|
|||
|
|
{
|
|||
|
|
CreateHostBuilder(args).Build().Run();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
|||
|
|
Host.CreateDefaultBuilder(args)
|
|||
|
|
.ConfigureAppConfiguration(ConfigureAppConfiguration)
|
|||
|
|
.ConfigureServices((hostContext, services) => { ConfigureServices(services, hostContext); });
|
|||
|
|
|
|||
|
|
|
|||
|
|
private static void ConfigureAppConfiguration(HostBuilderContext hostContext, IConfigurationBuilder config)
|
|||
|
|
{
|
|||
|
|
var env = hostContext.HostingEnvironment;
|
|||
|
|
config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
|
|||
|
|
config.AddEnvironmentVariables();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
private static void ConfigureServices(IServiceCollection services, HostBuilderContext hostContext)
|
|||
|
|
{
|
|||
|
|
var configuration = hostContext.Configuration;
|
|||
|
|
|
|||
|
|
services.AddTcp();
|
|||
|
|
services.AddUdp();
|
|||
|
|
|
|||
|
|
services.AddStackExchangeRedisCache(options =>
|
|||
|
|
{
|
|||
|
|
options.Configuration = configuration["RedisCache:ConnectionString"];
|
|||
|
|
options.InstanceName = configuration["RedisCache:InstanceName"];
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|