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

Allow ModelBinding resolution to work with subclasses #603

Closed
mmiller678 opened this issue Dec 3, 2014 · 2 comments
Closed

Allow ModelBinding resolution to work with subclasses #603

mmiller678 opened this issue Dec 3, 2014 · 2 comments

Comments

@mmiller678
Copy link

I can't get the Autofac model binding for MVC to work with subclasses - which I think is the intended behavior. The current Autofac model bind provider matches on exact type like the built in MVC one does.

Ideally it would be nice if the model binder could be registered to say I want to be used with the any subclasses that implement the specified type - i.e.

Ideally I would like to do something like this:

builder.RegisterType()
.AsModelBinderForTypesAndSubclasses(typeof(IEntity))
.PropertiesAutowired();
builder.RegisterModelBinderProvider();

autofacModelBinderProvider.GetBinder(typeof(EntityImplementation)) would return EntityModelBinder

Is there a way to do this in the current implementation? My current solution is to create my own provider and resolve the binders thru the dependency resolver, but I would prefer to use a purely Autofac solution if possible.

@tillig
Copy link
Member

tillig commented Dec 4, 2014

This is not currently supported. Most likely we won't enhance the behavior for the current integration just because it could pretty easily break (or change behavior in) apps that aren't expecting it. We also try to be consistent with the way things work in standard MVC so it's easy to figure out what to expect. However, the integration points for ASP.NET vNext are being worked on and that may be a good time to look at this.

In the meantime... your solution of a custom provider is probably the best way to go.

@tillig
Copy link
Member

tillig commented Sep 4, 2015

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

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