自托管.NET Core控制台应用程序中的Startup.cs

编程入门 行业动态 更新时间:2024-10-25 15:33:19
本文介绍了自托管.NET Core控制台应用程序中的Startup.cs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个自托管的 .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

本文发布于:2023-11-16 07:44:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1602339.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控制台   应用程序   Core   NET   Startup

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!