Я новичок в F # и пытаюсь преобразовать следующий код ядра Service Fabric Asp.Net из C # в F # и терпит неудачу.Кто-нибудь может помочь?
protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
{
return new[]
{
new ServiceInstanceListener(serviceContext =>
new KestrelCommunicationListener(serviceContext, "ServiceEndpoint", (url, listener) =>
{
ServiceEventSource.Current.ServiceMessage(serviceContext, $"Starting Kestrel on {url}");
return Microsoft.AspNetCore.WebHost.CreateDefaultBuilder()
.ConfigureAppConfiguration((builderContext, config) =>
{
config.SetBasePath(builderContext.HostingEnvironment.ContentRootPath);
config.AddJsonFile("appsettings.json", false);
config.AddJsonFile($"appsettings.{builderContext.HostingEnvironment.EnvironmentName}.json", true);
config.AddJsonFile("PackageRoot/Config/eventFlowConfig.json", optional: true, reloadOnChange: true);
config.AddEnvironmentVariables();
})
.ConfigureServices(
services =>
{
services.AddSingleton<StatelessServiceContext>(serviceContext);
})
.UseStartup<Startup>()
.UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.None)
.UseUrls(url)
.Build();
}))
};
}
F #
module Service
open Microsoft.ServiceFabric.Services.Runtime
open Microsoft.ServiceFabric.Services.Communication.Runtime
open Microsoft.ServiceFabric.Services.Communication.AspNetCore
open Microsoft.AspNetCore.Hosting
type Service(context) =
inherit StatelessService(context)
let builder = (fun url listener ->
Microsoft.AspNetCore.WebHost.CreateDefaultBuilder().UseUrls(url).Build())
let kestrelCommunicationListener ctx builder = new KestrelCommunicationListener(ctx, "ServiceEndPoint", builder)
let serviceInstanceListener context () = new ServiceInstanceListener(context kestrelCommunicationListener);
override __.CreateServiceInstanceListeners() =
seq {
yield serviceInstanceListener(fun context -> kestrelCommunicationListener builder)
}