예제 #1
0
        private RaftHttpCluster(IOptionsMonitor <RaftClusterMemberConfiguration> config, IServiceProvider dependencies, out MutableMemberCollection members)
            : this(config.CurrentValue, out members)
        {
            configurator       = dependencies.GetService <IRaftClusterConfigurator>();
            messageHandler     = dependencies.GetService <IMessageHandler>();
            AuditTrail         = dependencies.GetService <IPersistentState>();
            hostingAddresses   = dependencies.GetRequiredService <IServer>().GetHostingAddresses;
            httpHandlerFactory = dependencies.GetService <IHttpMessageHandlerFactory>();
            var loggerFactory = dependencies.GetRequiredService <ILoggerFactory>();

            Logger = loggerFactory.CreateLogger(GetType());
            //track changes in configuration
            configurationTracker = config.OnChange(ConfigurationChanged);
        }
예제 #2
0
 private protected static IWebHost CreateHost <TStartup>(int port, bool localhost, IDictionary <string, string> configuration, IRaftClusterConfigurator configurator = null)
     where TStartup : class
 {
     return(new WebHostBuilder()
            .UseKestrel(options =>
     {
         if (localhost)
         {
             options.ListenLocalhost(port);
         }
         else
         {
             options.ListenAnyIP(port);
         }
     })
            .UseShutdownTimeout(TimeSpan.FromMinutes(2))
            .ConfigureLogging(builder => builder.AddDebug().SetMinimumLevel(LogLevel.Debug))
            .ConfigureAppConfiguration(builder => builder.AddInMemoryCollection(configuration))
            .ConfigureServices(services =>
     {
         if (configurator != null)
         {
             services.AddSingleton(configurator);
         }
     })
            .UseStartup <TStartup>()
            .Build());
 }