コード例 #1
0
        static void Main(string[] args)
        {
            config = new ConfigurationBuilder()

                     .AddJsonFile("appsettings.json", true, true)
                     .AddEnvironmentVariables()
                     .Build();

            var serviceCollection = new ServiceCollection();

            serviceCollection.AddSingleton <TelnetListener>();
            serviceCollection.AddSingleton <IClusterClient>((service) =>
            {
                var client = StartClientWithRetries().GetAwaiter().GetResult();

                return(client);
            });
            serviceCollection.AddLogging(config =>
            {
                config.AddFilter((level) =>
                {
                    return(true);
                });
                config.AddConsole();
            });
            var Container           = serviceCollection.BuildServiceProvider();
            var serviceScopeFactory = Container.GetRequiredService <IServiceScopeFactory>();

            using (var scope = serviceScopeFactory.CreateScope())
            {
                var telnetListener = scope.ServiceProvider.GetService <TelnetListener>();
                telnetListener.OpenAsync(new CancellationToken()).GetAwaiter();
            }

            appStopped.WaitOne();
        }