Is there TryResolve in Unity?

Vadim picture Vadim · May 18, 2009 · Viewed 8.4k times · Source

How can I make Unity not to throw ResolutionFailedException if Resolve fails?

Is there something like TryResolve<IMyInterface>?

var container = new UnityContainer();
var foo = container.TryResolve<IFoo>();
Assert.IsNull(foo);

Answer

Bryan Ray picture Bryan Ray · Aug 25, 2010

Also note that, if you're using Unity 2.0 you can use the new IsRegistered() method and it's generic version as well.