可以通过ASP.NET核心中的动作方法注入哪些依赖项?

发布于 2025-02-07 13:42:04 字数 252 浏览 0 评论 0原文

我想知道如何将表单数据从CSHTML获取到控制器。 我尝试了httpcontext.request.form.data,但这无效。 我偶然发现了一个问题,所以有人在哪里使用:

public IActionResult Validate(IFormCollection form)

这起作用了。 现在,我想知道如何以这种方式注入其他依赖性。通过查找调试器,文档或源代码。因此,将来我知道在哪里搜索。

I wondered how I could get the form data from a cshtml to the controller.
I tried HttpContext.Request.Form.Data and this didn't work.
By accident I found a question on SO where someone used:

public IActionResult Validate(IFormCollection form)

This worked.
Now I wonder how I can look up what other dependencies can be injected this way. Either by looking up the debugger, documentation or the source code. So in the future I know where to search.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

枫林﹌晚霞¤ 2025-02-14 13:42:05

在启动期间调用的任何方法都可能在DI容器中添加许多服务,因此很难记录此类功能。

就像您说的那样,最简单的方法是使用调试器。

在.NET 5中,您可以在Configureservices方法(在startup.cs中)中达到一个突破点,并检查以下“服务”参数。扩展的结果视图将显示许多(如您现在看到的274,但是在调用addrazorPages之前,

此处可以在program.cs中点击点并检查builder.services如下所示

”在此处输入图像说明”

Any method which is called during startup may be adding many services to the DI container so it would be hard to document such a thing.

The easiest way, like you said is to use the debugger.

In .NET 5, you could hit a break-point in the ConfigureServices Method (in Startup.cs) and inspect the "services" argument as below. Expanding Results View will show many, (as you can see there are now 274, but before the call to AddRazorPages, there was less than 100.

enter image description here

For .NET6, you can just hit a break-point in Program.cs and inspect Builder.Services as shown below

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文