1

I'm a little confused with IServiceLocator, IMvcServiceLocator, IDependencyResolver, etc...

What is the ASP.NET MVC 3 RTM way of locating services?

All I need is to access something like

T Resolve<T>();
T Resolve<T>(string key);

from anywhere (including another assembly).

EDIT: example

My web app has a kind of modular architecture. Themes are one aspect of modules. Each theme is an individual class library. It's not possible to know what services a theme needs. E.g. some view might display a tag cloud widget and that widget needs an instance of TagRepository.

Currently I'm using Windsor for IoC and I could expose that container for modules. But I don't really want to make every module depend on Windsor. I would like to know if there's a solution in standard Mvc library since modules need a reference to that anyway.

frennky
  • 12,581
  • 10
  • 47
  • 63
Mike Koder
  • 1,898
  • 1
  • 17
  • 27

1 Answers1

0

Asp.net Mvc doesn't have it's own DI container. You would have to implement IDependencyResolver. Take a look at this question: Castle Windsor Dependency Resolver for MVC 3

Community
  • 1
  • 1
frennky
  • 12,581
  • 10
  • 47
  • 63
  • IDependencyResolver doesn't have a method to get service by name/key. Some beta version had IMvcServiceLocator and MvcServiceLocator http://bradwilson.typepad.com/blog/2010/07/service-location-pt1-introduction.html but those don't exist in RTM. So there isn't an exact substitutions for them? – Mike Koder Jan 27 '11 at 19:50
  • I don't remember if those interfaces were the same...If you've read part 5, he stated: For developers porting code from MVC 3 Preview 1 to MVC 3 Beta, this interface replaces IMvcServiceLocator. – frennky Jan 27 '11 at 20:04