IoC、AOP 等
什么是 IoC 容器?
什么是 IoC/DI 框架?
为什么我们需要 IoC/DI 框架?
IoC/DI和AOP有什么关系吗?
关于 IoC 和 AOP,Spring.net/ninject 是什么?
What is an IoC container?
What is an IoC/DI framework?
Why do we need a framework for IoC/DI?
Is there any relationship between IoC/DI and AOP?
What is Spring.net/ninject with respect to IoC and AOP?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
JMSA,
James Kovacs 写了一篇精彩的文章,涵盖了您的许多问题,我建议您阅读它 这里
Spring.Net、Ninject、Unity、Castle Windsor、Autofac 都是可以以不同方式配置的 IOC 容器,其中许多也支持 AOP。
IOC/DI 框架很有用,因为它们提供了标准机制,例如,如果您正在雇用新开发人员,则更容易说,我们使用此框架并向他们传递教程/帮助指南的链接。 同时这些框架经过大型社区/公司的尝试和测试。
如果在阅读本文和上述答案后您的任何问题仍未得到解答,请告诉我,我将尽力提供进一步的帮助。
JMSA,
James Kovacs wrote a fantastic article which covers many of your questions I would recommend reading it Here
Spring.Net, Ninject, Unity, Castle Windsor, Autofac are all IOC containers which are configurable in different ways, many of them do also support AOP.
Frameworks for IOC/DI are useful because they provide standard mechanisms, for example if you are hiring a new developer it is much easier to say, we use this framework and pass them the links to the tutorials / help guide. At the same time these frameworks are tried and tested by a large community / companies.
Let me know if any of your questions remain unanswered after reading the article and the above answes and I'll do my best to provide further assistance.
从语义的角度来看......
依赖注入本身意味着一个依赖,即构建/使用所需的东西(应用程序的“核心关注点”)。 例如,没有发动机的汽车就不是汽车。
各个方面被描述为与应用程序的核心关注点交叉。 这意味着既与核心问题分离又不重要(您可以将它们视为“有就更好”)。 既然应用程序可以在没有方面的情况下运行,那么它们真的是依赖项吗? 例如,即使没有防盗装置,汽车仍然是汽车。
(当然,这是从理论角度来看的。在现实世界中,诸如安全之类的问题对于可销售产品的存在通常与核心关注点本身一样至关重要。)
因此,虽然在实践中 DI 可以用于实现方面,但我不会将该过程称为真正的 DI。 这是来自专门使用构造函数注入的人。
From a semantics point of view...
Dependency Injection itself implies a dependency, i.e. something that is required for construction/use (the application's "core concerns"). For example, a car is not a car without an engine.
Aspects are described as being cross-cutting to the application's core concerns. That means both separate from and non-crucial to the core concerns (you could think of them as "nice-to-haves"). Since the application can run without aspects, are they really dependencies? For example, a car is still a car even without an immobiliser.
(Of course, this is from a theoretical standpoint. In the real world matters like security are often as crucial to the existence of a marketable product as the core concerns themselves.)
So in while in practice DI can be used to implement aspects, I would not call that process true DI. This is coming from someone who uses constructor injection exclusively.
Martin Fowler 在这里写了一篇关于控制反转和依赖注入的含义的好文章。
此处详细介绍了 Spring.NET 使用 AOP。 我更熟悉基于Java的Spring版本,所以我不能绝对肯定地说Spring.NET目前只支持基于代理的AOP。
也就是说,要通知的类必须实现接口。 Spring将创建一个动态代理来实现该接口并委托给原始目标实例。
虽然它确实指出:
Martin Fowler has a good article here on the meaning of Inversion of Control and Dependency Injection.
Spring.NET usage AOP is described in detail here. I'm more familiar with the Java-based version of Spring, so I cannot say with absolutely certainty that Spring.NET currently only supports proxy-based AOP.
That is, a class to be advised must implement an interface. Spring will create a dynamic proxy that implements this interface and delegates to the original target instance.
Although it does state: