调试依赖注入.net(Debugging dependency injection in .NET)

编程入门 行业动态 更新时间:2024-10-26 06:39:33
调试依赖注入.net(Debugging dependency injection in .NET)

使用DI时,由于各处都有很多接口,因此难以阅读代码。 也就是说,你不能只在Visual Studio中点击F12(转到定义),因为它只会带你到界面。 您需要知道配置使用哪个类。

是否有插件或类似的东西使这更容易? 你是怎么解决这个问题的?

When using DI it's harder to read the code since you have alot of interfaces everywhere. i.e., you can't just hit F12 (go to definition) in Visual Studio since that only takes you to the interface. You need to know which class is configured to be used.

Is there a plugin or something like that which makes this easier? How are you people tackling this?

最满意答案

在Visual Studio 2015中,您可以按CTRL + F12,如果只有一个,它将直接跳转到实现,否则将提示可供选择的实现列表。

ReSharper有一个名为Agent Mulder的插件,它将ReSharper与依赖注入库集成在一起。 它允许您查看正在使用的类,并允许您直接跳转到接口的配置或其实现。 你一定要看一下。

但说实话,用DI调试代码并没有改变,因为你仍然可以在调试时进入方法调用,就像你习惯的那样。

如果您的应用程序设计得很好,那么在处理代码时您不太可能需要从一个类跳到另一个类,因为类对其依赖项的细节不感兴趣。 因此,依赖注入实际上应该使这更容易。

但即使浏览代码和调试(有点)更难,能够插入新功能,添加coss切割问题并能够测试应用程序将对应用程序的整体质量和可维护性产生巨大的可能影响。

In Visual Studio 2015 and up, you can hit CTRL + F12 and that will jump directly to the implementation if there is only one, and otherwise will prompt a list of implementations to choose from. This makes it easy to navigate your code from inside your IDE.

There's a plugin for ReSharper called Agent Mulder that integrates ReSharper with Dependency Injection libraries. It allows you to see which classes are in use and allows you to jump directly to the interface's configuration or its implementation.

But to be honest, debugging the code with DI doesn't change, since you can still step into methods calls while debugging, as you're used to.

If your application is designed well, it will be less likely that you need to jump from class to class while working with the code, since a class is not interested in the details of its dependencies. So Dependency Injection should in fact make this easier.

But even if browsing code and debugging would become (a bit) harder, being able to plug in new features, add coss-cutting concerns, and being able to test an application will have a enormous possitive impact on the overal quality and maintainability of an application.

更多推荐

本文发布于:2023-07-27 15:32:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1292428.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Debugging   net   dependency   NET   injection

发布评论

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

>www.elefans.com

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