How to use dependency injection with ASP.NET MVC model?
I ended up creating a service locator: http://martinfowler.com/articles/injection.html#UsingAServiceLocator
It's getting easier for me than dealing with an IoC container and trying to inject my DI code throughout the MVC pipeline.
source to share
You can find a sane How-To on Shiju Vargheses Blog: ASP.NET MVC Tip: Dependency Injection with Unity App Block
source to share
I usually install dependencies in the controller, for example
PersonController(IPersonRepository r)
{
\\ constrtuctor code
}
in models, maybe when you need some instance of something that inherits an interface, you do something like this:
var r = container.Resolve<IPersonRepository>();
source to share
I would recommend considering the S # arp architecture http://www.sharparchitecture.net/
An open source environment for asp.net mvc.
source to share
Are you completely sure that you need to inject a dependency into your domain model? An object or business object usually encapsulates state and exposes methods to change that state according to business rules. Code that doesn't fall into this category is usually found in a service. Have you read the concept of a domain service at all ? Perhaps using one will better suit your needs and you won't need to inject any dependencies into your domain.
source to share
Checkout this sample that I created based on Ayende's explanations on his blog. Basically, I'm using Castle as my IoC container, and I'm using Mvc Contrib to add all the controllers to the container and make Mvc get them from it. Then I can inject anything into containers like ISIBernate ISession.
If you want to inject stuff inside your model classes (objects), NH now supports Including Hibernate Managed Object Dependencies . See this , this and this for specific examples for Spring and Windsor.
source to share