mvc web api , . mvc/web api - , , , ( ..). ActualResponse, ? , . , . Application_Start, .
:
public static class ActionMethodsRegistrator
{
private static readonly Type ApiControllerType = typeof(IHttpController);
public static void RegisterActionMethods(YourCustomConfig config)
{
var contollersTypes = Assembly.GetExecutingAssembly().GetTypes()
.Where(foundType => ApiControllerType.IsAssignableFrom(foundType));
foreach (var contollerType in contollersTypes)
{
var allMethods = contollerType.GetMethods(BindingFlags.Instance | BindingFlags.Public);
foreach (var methodInfo in allMethods)
{
var actualResponseAttrubute = methodInfo.GetCustomAttribute<ActualResponseAttribute>();
if (actualResponseAttrubute != null)
{
config.SetActualResponseType(actualResponseAttrubute.Type, contollerType.Name, methodInfo.Name);
}
}
}
}
}
Global.asax:
protected void Application_Start()
{
YourCustomConfig config = InitializeConfig();
ActionMethodsRegistrator.RegisterActionMethods(config);
}