Skip to content

Instantly share code, notes, and snippets.

@satish860
Created September 22, 2012 15:14
Show Gist options
  • Save satish860/3766480 to your computer and use it in GitHub Desktop.
Save satish860/3766480 to your computer and use it in GitHub Desktop.
MVC 3 Dependency Resolver
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