Created
September 22, 2012 15:14
-
-
Save satish860/3766480 to your computer and use it in GitHub Desktop.
MVC 3 Dependency Resolver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DependencyResolver : IDependencyResolver | |
{ | |
private readonly IContainer container; | |
public DependencyResolver(IContainer container) | |
{ | |
this.container = container; | |
} | |
public object GetService(Type serviceType) | |
{ | |
return serviceType.IsAbstract || serviceType.IsInterface ? container.TryGetInstance(serviceType) | |
: container.GetInstance(serviceType); | |
} | |
public IEnumerable<object> GetServices(Type serviceType) | |
{ | |
return container.GetAllInstances(serviceType).Cast<object>(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment