Skip to content

Instantly share code, notes, and snippets.

@fxbeckers
Created May 21, 2014 08:04
Show Gist options
  • Save fxbeckers/55cbb62d317aef80e263 to your computer and use it in GitHub Desktop.
Save fxbeckers/55cbb62d317aef80e263 to your computer and use it in GitHub Desktop.
//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