Created
November 19, 2015 14:17
-
-
Save donaldgray/18e6ccd29c78f17a7dd8 to your computer and use it in GitHub Desktop.
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
/// <summary> | |
/// This is just a helper class to make resolving dependencies manually a bit tidier | |
/// </summary> | |
public static class WebApiDependencyResolver | |
{ | |
/// <summary> | |
/// Use configured WebApi DependencyResolver to resolve dependency of type T. | |
/// </summary> | |
/// <typeparam name="T"></typeparam> | |
/// <returns></returns> | |
public static T ResolveDependency<T>() | |
{ | |
var resolver = GlobalConfiguration.Configuration.DependencyResolver; | |
var type = typeof(T); | |
return (T)resolver.GetService(type); | |
} | |
/// <summary> | |
/// Resolve dependency of type T using IDependencyScope. | |
/// </summary> | |
/// <typeparam name="T"></typeparam> | |
/// <param name="scope">The scope.</param> | |
/// <returns></returns> | |
public static T ResolveDependency<T>(this IDependencyScope scope) | |
{ | |
var type = typeof(T); | |
return (T)scope.GetService(type); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment