public Unity3dApiFeature( IFullNodeBuilder fullNodeBuilder, FullNode fullNode, Unity3dApiSettings apiSettings, ILoggerFactory loggerFactory, ICertificateStore certificateStore) { this.fullNodeBuilder = fullNodeBuilder; this.fullNode = fullNode; this.apiSettings = apiSettings; this.certificateStore = certificateStore; this.logger = loggerFactory.CreateLogger(this.GetType().FullName); this.InitializeBeforeBase = true; }
public static IWebHost Initialize(IEnumerable <ServiceDescriptor> services, FullNode fullNode, Unity3dApiSettings apiSettings, ICertificateStore store, IWebHostBuilder webHostBuilder) { Guard.NotNull(fullNode, nameof(fullNode)); Guard.NotNull(webHostBuilder, nameof(webHostBuilder)); Uri apiUri = apiSettings.ApiUri; X509Certificate2 certificate = apiSettings.UseHttps ? GetHttpsCertificate(apiSettings.HttpsCertificateFilePath, store) : null; webHostBuilder .UseKestrel(options => { if (!apiSettings.UseHttps) { return; } options.AllowSynchronousIO = true; Action <ListenOptions> configureListener = listenOptions => { listenOptions.UseHttps(certificate); }; var ipAddresses = Dns.GetHostAddresses(apiSettings.ApiUri.DnsSafeHost); foreach (var ipAddress in ipAddresses) { options.Listen(ipAddress, apiSettings.ApiPort, configureListener); } }) .UseContentRoot(Directory.GetCurrentDirectory()) .UseIISIntegration() .UseUrls(apiUri.ToString()) .ConfigureServices(collection => { if (services == null) { return; } // copies all the services defined for the full node to the Api. // also copies over singleton instances already defined foreach (ServiceDescriptor service in services) { // open types can't be singletons if (service.ServiceType.IsGenericType || service.Lifetime == ServiceLifetime.Scoped) { collection.Add(service); continue; } object obj = fullNode.Services.ServiceProvider.GetService(service.ServiceType); if (obj != null && service.Lifetime == ServiceLifetime.Singleton && service.ImplementationInstance == null) { collection.AddSingleton(service.ServiceType, obj); } else { collection.Add(service); } } }) .UseStartup <Startup>(); IWebHost host = webHostBuilder.Build(); host.Start(); return(host); }