Learning Inversion of Control through Dependency Injection in MVC 3

一笑奈何 提交于 2020-01-13 06:34:10

问题


Can someone please provide me a simple example of DI and IoC?
I understand the first one but was unable to get an implementation of the second one.

I'm working with MVC 3 and I really want to use the IDependencyResolver, but I can't understand how.

Is ninject an option or is it required?

Is there a tutorial like nerdDinner and I wasn't able to find it?

Can somebody give me a link to study it?


回答1:


In order to grok real world DI and its patterns and anti-patterns quickly, I recommend getting DI in .NET. (I've ordered it already EDIT: And it was a page turner that taught me a lot and should teach people of all experience levels well)

Failing that, read all Mark Seemann's high-rated posts here.

I personally learned from the ninject wiki, but that, while excellent, is Ninject 1.0 specific.




回答2:


don't use IDependencyResolver. It has nothing to do with Inversion of Control, and it's fundamentally broken. If you want to learn how to use IoC Container properly with MVC 3 see this tutorial (uses Windsor).




回答3:


This isn't my example, but is one I just ran across while looking for a simple, functional example. It uses NInject and the final IoC functionality of .Net MVC 3.

http://www.shahnawazk.com/2010/12/dependency-injection-in-aspnet-mvc-3.html

Simple downloadable example project at the bottom of the article.




回答4:


I cant answer for asp related techs, but on the academic side, the fact that you are using DI implies that you have inverted control.

Ill make it explicit -- when you do not invert control, you basically make the various components of an application resolve their own dependencies. When you invert control, you allow the resolving of the dependencies happen at some other layer. That is the 'inversion' of the control.



来源:https://stackoverflow.com/questions/4900398/learning-inversion-of-control-through-dependency-injection-in-mvc-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!