You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For the past year and half, I've been using an extension method and a generic model binder combination that allow me to inject view models on am Mvc ActionResult.
For example - say I have a view model called "SimpleOrderModel" that injects a repository (imho a controller shouldn't understand how to load and save a model - it's the model's job).
Therefore, I should be able to create an action result that looks like this:
[HttpPost]
public ActionResult Configure(SimpleOrderModel simpleOrderModel)
{
if(ModelState.IsValid)
{
To go along with this code, I have a registration extension where the call looks like this:
I have this in my local repo and I've included a patch file of the implementation. I could also move this to a named branch or check it my fork depending on the process of including it.
This appears to overlap the ExtensibleActionInvoker, which can also do some model injection. Have you tried that? Is there something missing from ExtensibleActionInvoker that we could enable to solve this?
This looks like it is somewhat related to the Autofac.Integration.Mvc.ExtensibleActionInvoker, which injects parameters into an action. I'm not sure if the two functions could (or should) be tied together, but if/when this gets implemented it's something to think about. It would mean you don't have to register specific models for injection - it'd "just work."
Summary: Enable properties on MVC models to be injected during model binding (was: An Mvc ModelBinder extension) Owner: --- Labels: -Type-Defect Type-Enhancement
From steve.he...@gmail.com on February 08, 2011 14:41:08
For the past year and half, I've been using an extension method and a generic model binder combination that allow me to inject view models on am Mvc ActionResult.
For example - say I have a view model called "SimpleOrderModel" that injects a repository (imho a controller shouldn't understand how to load and save a model - it's the model's job).
Therefore, I should be able to create an action result that looks like this:
[HttpPost]
public ActionResult Configure(SimpleOrderModel simpleOrderModel)
{
if(ModelState.IsValid)
{
To go along with this code, I have a registration extension where the call looks like this:
builder.RegisterInjectedModel().InstancePerDependency();
I find this incredibly useful.
I have this in my local repo and I've included a patch file of the implementation. I could also move this to a named branch or check it my fork depending on the process of including it.
Attachment: autofacmvc_iocmodelbinder.patch
Original issue: http://code.google.com/p/autofac/issues/detail?id=292
The text was updated successfully, but these errors were encountered: