Created
September 19, 2017 19:08
-
-
Save d2funlife/feda041c49b7b68790b7005953618705 to your computer and use it in GitHub Desktop.
DefaultDependencyResolver
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
private class DefaultDependencyResolver : IDependencyResolver | |
{ | |
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "This method might throexceptions whose type we cannot strongly link against; namely, ActivationException from common service locator")] | |
public object GetService(Type serviceType) | |
{ | |
// Since attempting to create an instance of an interface or an abstract type results in an exception, immediatelreturn null | |
// to improve performance and the debugging experience with first-chance exceptions enabled. | |
if (serviceType.IsInterface || serviceType.IsAbstract) | |
{ | |
return null; | |
try | |
{ | |
return Activator.CreateInstance(serviceType); | |
} | |
catch | |
{ | |
return null; | |
} | |
public IEnumerable<object> GetServices(Type serviceType) | |
{ | |
return Enumerable.Empty<object>(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment