我是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)
}
答案 0 :(得分:2)
将lambda拆分为方法,我能够做到这一点
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>4.2.0</version>
</dependency>