Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable properties on MVC models to be injected during model binding #292

Closed
alexmg opened this issue Jan 22, 2014 · 4 comments
Closed

Enable properties on MVC models to be injected during model binding #292

alexmg opened this issue Jan 22, 2014 · 4 comments

Comments

@alexmg
Copy link
Member

alexmg commented Jan 22, 2014

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

@alexmg
Copy link
Member Author

alexmg commented Jan 22, 2014

From travis.illig on September 21, 2012 09:30:36

Labels: Module-Integration-Mvc

@alexmg
Copy link
Member Author

alexmg commented Jan 22, 2014

From travis.illig on December 05, 2012 10:53:22

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?

@alexmg
Copy link
Member Author

alexmg commented Jan 22, 2014

From travis.illig on January 02, 2013 12:10:13

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

@tillig
Copy link
Member

tillig commented Sep 4, 2015

This issue was moved to autofac/Autofac.Mvc#8

@tillig tillig closed this as completed Sep 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants