什么是.NET中的IoC? [英] What is IoC in .NET
问题描述
可能重复:
什么是控制的反转?
我不熟悉具有反转控制(IoC)。什么是IoC,应用程序如何从使用IOC中获益。如何在.NET中实现C#?
I am not familiar with Inversion of Control (IoC). What is IoC and how can applications benefit from using IOC. How is it implemented in .NET with C#?
推荐答案
如果您有一组依赖于彼此的课程,那么很难将某个类替换为另一类(更好/更便宜/更快)类做同样的工作。为了使您的代码更加灵活,您可以使用依赖注入。
If you have a set of classes that depend on eachother, it's difficult to replace some class for another (better/cheaper/faster) class that does the same job. In order to make your code more flexible, you can use dependency injection.
C#的易于使用的DI框架是Ninject。他们有一个非常理解的关于这个问题的教程。
An easy to use DI framework for C# is Ninject. They have a very understandable tutorial about this subject.
链接:
http://blog.andresays.org/2010/10/dependency-injection-with-ninject-and-asp-net-mvc/
祝你好运!
这篇关于什么是.NET中的IoC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!