Created
February 19, 2014 16:53
-
-
Save weslley39/9096210 to your computer and use it in GitHub Desktop.
UnityDependencyResolver
This file contains hidden or 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
using System; | |
using System.Collections.Generic; | |
using System.Web.Mvc; | |
using Microsoft.Practices.Unity; | |
namespace Ukutool | |
{ | |
public class UnityDependencyResolver : IDependencyResolver | |
{ | |
private readonly IUnityContainer _container; | |
public UnityDependencyResolver(IUnityContainer container) | |
{ | |
_container = container; | |
} | |
public object GetService(Type serviceType) | |
{ | |
try | |
{ | |
return _container.Resolve(serviceType); | |
} | |
catch | |
{ | |
return null; | |
} | |
} | |
public IEnumerable<object> GetServices(Type serviceType) | |
{ | |
try | |
{ | |
return _container.ResolveAll(serviceType); | |
} | |
catch | |
{ | |
return new List<object>(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment