Skip to content

Instantly share code, notes, and snippets.

@weslley39
Created February 19, 2014 16:53
Show Gist options
  • Save weslley39/9096210 to your computer and use it in GitHub Desktop.
Save weslley39/9096210 to your computer and use it in GitHub Desktop.
UnityDependencyResolver
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