简体   繁体   English

如何从f#访问.net asp.core库中的静态类

[英]How to access static classes in a .net asp.core library from f#

I'm trying to translate the following: 我正在尝试翻译以下内容:

using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;

namespace AspNetCoreDotNetCore2App
{
    public class Program
    {
        public static void Main(string[] args)
        {
            BuildWebHost(args).Run();
        }

        public static IWebHost BuildWebHost(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>()
                .Build();
    }
}

to f# 到F#

I've come up with this: 我想出了这个:

open Microsoft.AspNetCore
open Microsoft.AspNetCore.Hosting

type Program =     
    static member BuildWebHost =
        fun (args : string []) ->
            WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>()
                .Build()

    static member Main(args : string []) =    
        BuildWebHost(args).Run() 

but get an error when building: 但是在构建时出现错误:

D:\documents\code\rhea\Program.fs(318,13): error FS0039: The value, namespace, type or module 'WebHost' is not defined.
 Maybe you want one of the following:   IWebHost   WebHostBuilder   WebHostDefaults   WebHostExtensions   Web
D:\documents\code\rhea\Program.fs(323,9): error FS0039: The value or constructor 'BuildWebHost' is not defined. Maybe y
ou want one of the following:   Builder   IWebHost

Here's the documentation of WebHost: https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.webhost?view=aspnetcore-2.1 这是WebHost的文档: https ://docs.microsoft.com/zh-cn/dotnet/api/microsoft.aspnetcore.webhost ? view = aspnetcore-2.1

open Microsoft.AspNetCore
open Microsoft.AspNetCore.Hosting

let createWebHostBuilder args =
   WebHost
       .CreateDefaultBuilder(args)
       .UseStartup<Startup>();

[<EntryPoint>]
let main args =
    CreateWebHostBuilder(args).Build().Run()
    0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASP.Core 中的 .NET 版本 - .NET versions in ASP.Core ASP.Core 3 中基于角色的授权:如何授予某个角色无处不在的访问权限? - Role based authorization in ASP.Core 3: how to grant access everywhere to certain role? 如何避免返回任务 <Microsoft.FSharp.Core.Unit> 来自F#库 - How can I avoid returning a Task<Microsoft.FSharp.Core.Unit> from an F# library 如何在 Asp.Core 应用程序中实现 AlwaysEncrypted AzureKeyVaultProvider 3.0.0 - How to implement AlwaysEncrypted AzureKeyVaultProvider 3.0.0 in Asp.Core application 如何在asp.core中使用Fluent API创建关系或主键? - How to create a relationship or primary key with Fluent API in asp.core? 为什么要在F#核心库中重写.NET LINQ方法? - Why are the .NET LINQ methods re-written in the F# core library? ASP.NET Core Web API - Static class 'UserUniqueEmailValidator' cannot derive from type 'ValidationAttribute'. Static 类必须派生自 object - ASP.NET Core Web API - Static class 'UserUniqueEmailValidator' cannot derive from type 'ValidationAttribute'. Static classes must derive from object 如何处理在ASP.Net Core中在相同上下文范围内运行的静态类? - How to handle static classes running in the same context scope in ASP.Net Core? 使用DistributedSqlServerCache的ASP.CORE会话 - ASP.CORE Session using a DistributedSqlServerCache asp.core页面razor枚举下拉列表 - asp.core page razor enum dropdownlist
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM