void IHostStartup.Init(IHostBuilderInternal builder) { builder.ConfigureServices(services => { var serviceProvider = services.AddHttpClient().BuildServiceProvider(); this.httpFactory = serviceProvider.GetRequiredService <IHttpClientFactory>(); }); }
public void Init(IHostBuilderInternal builder) { if (!(builder.GetBuilderWrapper() is IWebHostBuilder hostBuilder)) { return; } var serverUrls = hostBuilder.GetSetting(WebHostDefaults.ServerUrlsKey); if (!string.IsNullOrEmpty(serverUrls)) { var urls = serverUrls.Split(';'); Uri uri = null; foreach (var url in urls) { if (url.Contains("*")) // http://*:5000 { var fakeurl = url.Replace('*', '_'); if (Uri.TryCreate(fakeurl, UriKind.Absolute, out var uri1)) { uri = uri1; break; } } else { if (Uri.TryCreate(url, UriKind.Absolute, out var uri1)) { if (!uri1.IsLoopback) { uri = uri1; } } } } if (uri != null) { this.Port = uri.Port; if (uri.Host != "_") { this.Host = uri.Host; } } } var coreAttributes = this.ObjectService.AsObjectServiceInternal().CoreAttributes; if (coreAttributes.TryGetValue(typeof(MiddlewareAttribute), out var list)) { this.MiddlewareTypes = list.OrderByDescending(x => x.Priority).Select(x => x.OwnerType).ToArray(); } builder.ConfigureServices(services => { //把自己加进去 services.AddSingleton <IStartupFilter>(this); var middlewares = this.MiddlewareTypes; if (middlewares != null && middlewares.Length > 0) { foreach (var middleware in middlewares) { services.AddSingleton(middleware); } } }); }
public void Init(IHostBuilderInternal builder) { builder.ConfigureServices(services => { services.AddHostedService <ServiceRunning>(); }); }