Bring back simple POCO controller
+ HttpContext temporary injection through property + 404 when action is not found
This commit is contained in:
parent
87379400cf
commit
cc3fec2f76
|
|
@ -0,0 +1,10 @@
|
|||
namespace MvcSample
|
||||
{
|
||||
public class SimplePocoController
|
||||
{
|
||||
public string Index()
|
||||
{
|
||||
return "Hello world";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue