我有一个自托管的 .NET Core控制台应用程序。
网络上显示了 ASP.NET Core 的示例,但我没有Web服务器。只是一个简单的命令行应用程序。
The web shows examples for ASP.NET Core but i do not have a webserver. Just a simple command line application.
是否可以对控制台应用程序执行类似的操作?
Is it possible to do something like this for console applications?
public static void Main(string[] args) { // I don't want a WebHostBuilder. Just a command line var host = new WebHostBuilder() .UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) .UseIISIntegration() .UseStartup<Startup>() .Build(); host.Run(); }我想在ASP.NET Core中使用Startup.cs,但在控制台上。
I would like to use a Startup.cs like in ASP.NET Core but on console.
该怎么做?
推荐答案所有 .NET Core 应用程序由精心设计的独立库和程序包组成,您可以在任何类型的应用程序中自由引用和使用它们。碰巧的是,已经预先配置了 Asp核心应用程序以引用很多这些库并公开了http端点。
All .NET Core applications are composed of well-crafted independent libraries and packages which you're free to reference and use in any type of application. It just so happens that an Asp core application comes preconfigured to reference a lot of those libraries and exposes an http endpoint.
但是如果您的控制台应用需要依赖注入,则只需引用相应的库即可。这是一个指南: andrewlock/在网络核心控制台应用程序中使用依赖注入/
But if it's Dependency Injection you need for your console app, simply reference the appropriate library. Here's a guide: andrewlock/using-dependency-injection-in-a-net-core-console-application/
更多推荐
自托管.NET Core控制台应用程序中的Startup.cs
发布评论