Bring back simple POCO controller

+ HttpContext temporary injection through property
+ 404 when action is not found
This commit is contained in:
Yishai Galatzer 2014-02-11 17:25:30 -08:00
parent 87379400cf
commit cc3fec2f76
3 changed files with 31 additions and 5 deletions

View File

@ -0,0 +1,10 @@
namespace MvcSample
{
public class SimplePocoController
{
public string Index()
{
return "Hello world";
}
}
}

View File

@ -45,12 +45,14 @@ namespace Microsoft.AspNet.Mvc
if (method == null)
{
throw new InvalidOperationException(String.Format("Could not find action method '{0}'", _descriptor.ActionName));
actionResult = new HttpStatusCodeResult(404);
}
else
{
object actionReturnValue = method.Invoke(controller, null);
object actionReturnValue = method.Invoke(controller, null);
actionResult = _actionResultFactory.CreateActionResult(method.ReturnType, actionReturnValue, _requestContext);
actionResult = _actionResultFactory.CreateActionResult(method.ReturnType, actionReturnValue, _requestContext);
}
}
// TODO: This will probably move out once we got filters

View File

@ -31,7 +31,21 @@ namespace Microsoft.AspNet.Mvc
{
try
{
return ActivatorUtilities.CreateInstance(_serviceProvider, descriptor.ControllerType);
var controller = ActivatorUtilities.CreateInstance(_serviceProvider, descriptor.ControllerType);
// TODO: How do we feed the controller with context (need DI improvements)
var contextProperty =
#if NET45
descriptor.ControllerType.GetProperty("Context");
#else
descriptor.ControllerType.GetRuntimeProperty("Context");
#endif
if (contextProperty != null)
{
contextProperty.SetMethod.Invoke(controller, new [] { context });
}
return controller;
}
catch (ReflectionTypeLoadException)
{