Created
May 21, 2014 08:04
-
-
Save fxbeckers/55cbb62d317aef80e263 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
//Example usage | |
// | |
//var customControllerActivator = new CustomControllerActivator(); | |
//customControllerActivator.AddType(() => new MyApiController()); | |
//httpConfiguration.Services.Replace(typeof(IHttpControllerActivator),customControllerActivator); | |
class CustomControllerActivator : IHttpControllerActivator | |
{ | |
readonly Dictionary<Type, Func<IHttpController>> _dictionary = new Dictionary<Type, Func<IHttpController>>(); | |
public IHttpController Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType) | |
{ | |
return _dictionary[controllerType](); | |
} | |
public void AddType<T>(Func<T> creator) where T : class, IHttpController | |
{ | |
_dictionary.Add(typeof(T), creator); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment