コード例 #1
0
        public Task StartAsync()
        {
            var builder = new WebHostBuilder();

            // Workaround for https://github.com/WireMock-Net/WireMock.Net/issues/292
            // On some platforms, AppContext.BaseDirectory is null, which causes WebHostBuilder to fail if ContentRoot is not
            // specified (even though we don't actually use that base path mechanism, since we have our own way of configuring
            // a filesystem handler).
            if (string.IsNullOrEmpty(AppContext.BaseDirectory))
            {
                builder.UseContentRoot(System.IO.Directory.GetCurrentDirectory());
            }

            _host = builder
                    .ConfigureAppConfigurationUsingEnvironmentVariables()
                    .ConfigureServices(services =>
            {
                services.AddSingleton(_options);
                services.AddSingleton <IMappingMatcher, MappingMatcher>();
                services.AddSingleton <IOwinRequestMapper, OwinRequestMapper>();
                services.AddSingleton <IOwinResponseMapper, OwinResponseMapper>();
            })
                    .Configure(appBuilder =>
            {
                appBuilder.UseMiddleware <GlobalExceptionMiddleware>();

                _options.PreWireMockMiddlewareInit?.Invoke(appBuilder);

                appBuilder.UseMiddleware <WireMockMiddleware>();

                _options.PostWireMockMiddlewareInit?.Invoke(appBuilder);
            })
                    .UseKestrel(options =>
            {
                SetKestrelOptionsLimits(options);

                SetHttpsAndUrls(options, _urlOptions.GetDetails());
            })
                    .ConfigureKestrelServerOptions()

#if NETSTANDARD1_3
                    .UseUrls(_urlOptions.GetDetails().Select(u => u.Url).ToArray())
#endif
                    .Build();

            return(RunHost(_cts.Token));
        }