可以通过ASP.NET核心中的动作方法注入哪些依赖项?
我想知道如何将表单数据从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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在启动期间调用的任何方法都可能在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.For .NET6, you can just hit a break-point in Program.cs and inspect
Builder.Services
as shown below