Exemple #1
0
        public void Init(
            Action <IServiceCollection> configureServices,
            Action <ILoggingBuilder> configureLogging,
            HostType hostType)
        {
            if (configureServices == null)
            {
                throw new ArgumentNullException(nameof(configureServices));
            }
            if (configureLogging == null)
            {
                throw new ArgumentNullException(nameof(configureLogging));
            }

            IHostBuilder builder;

            switch (hostType)
            {
            case HostType.Default:
                builder = Host.CreateDefaultBuilder();
                break;

            case HostType.WindowsLimited:
                builder = WindowsHost.CreateWindowsBuilder();
                break;

            default:
                throw new InvalidOperationException("invalid host type");
            }

            s_host = builder.ConfigureServices((context, services) =>
            {
                configureServices(services);
            })
                     .ConfigureLogging(logging =>
            {
                configureLogging(logging);
            }).Build();
        }