public static ServiceInstanceListener Get(WebClientFactoryOptions options) { return(new ServiceInstanceListener(x => new KestrelCommunicationListener(x, options.EndpointName, (url, listener) => { var builder = new WebHostBuilder() .UseKestrel() .ConfigureServices(services => services.AddSingleton(new HttpClient()) .AddSingleton(new FabricClient()) .AddSingleton(x)); if (options.FabricSettings.IsLocal) { builder = builder.UseContentRoot(options.ContentRoot); } builder = builder .ConfigureServices(c => ConfigureServices(c, options)) .UseStartup <Startup>() .UseApplicationInsights() .UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.None) .UseUrls(url); return builder.Build(); }))); }
private static void ConfigureServices(IServiceCollection services, WebClientFactoryOptions options) { var orleanOptions = new OrleansClientConnectionOptions { TableStorageConnectionString = options.FabricSettings.TableStorage, ClusterId = options.FabricSettings.IsLocal ? "development" : "production", FabricUrl = "fabric:/ServiceFabricSample/MyStatelessService" }; IAppContextSettings contextSettings = new AppContextSettings(options.FabricSettings.Db); services.AddScoped(provider => OrleansClientFactory.Get(orleanOptions)); services.AddSingleton(contextSettings); services.AddSingleton(options.FabricSettings); services.AddSingleton(orleanOptions); }
public static ServiceInstanceListener Get(WebClientFactoryOptions options) { return(new ServiceInstanceListener(x => new KestrelCommunicationListener(x, options.EndpointName, (url, listener) => { options.LogAction(x, $"Starting Kestrel. Earl: {url}. Content Directory: {options.ContentDirectory}"); return new WebHostBuilder() .UseKestrel() .ConfigureServices(services => services.AddSingleton(new HttpClient()) .AddSingleton(new FabricClient()) .AddSingleton(x)) .UseContentRoot(options.ContentDirectory) .UseStartup <Startup>() .UseApplicationInsights() .UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.None) .UseUrls(url) .Build(); }))); }
protected override IEnumerable <ServiceInstanceListener> CreateServiceInstanceListeners() { var myConfigPackage = Context.CodePackageActivationContext.GetConfigurationPackageObject("Config"); var fabricSettings = new FabricSettings(myConfigPackage); var webFactoryOptions = new WebClientFactoryOptions { FabricSettings = fabricSettings, EndpointName = "Web", LogAction = (ctx, log) => ServiceEventSource.Current.ServiceMessage(ctx, log), ContentRoot = (new DirectoryInfo(Directory.GetCurrentDirectory()).Parent?.FullName ?? string.Empty) + "\\Fabric.Web" }; return(new[] { OrleansServiceInstanceListenerFactory.Get(fabricSettings), WebClientFactory.Get(webFactoryOptions) }); }