Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8505391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:18:16+00:00 2026-06-11T02:18:16+00:00

I have a problem with the Autofac ExtensibleActionInvoker interacting with the MVC ModelBinder when

  • 0

I have a problem with the Autofac ExtensibleActionInvoker interacting with the MVC ModelBinder when using interfaces for parameters. The background is as follows:

I am building a MVC application and I am using Autofac MVC3’s ExtensibleActionInvoker to inject my services as parameters to my actions, e.g.

    public ActionResult Test( IMyService service)
    {
        //A new instance of service is created by Autofac ExtensibleActionInvoker 
        return View();
    }

This works really well and makes for a really clean design (see Alex Meyer-Gleaves post for more information on this approach). I want to use this method as I am producing a code generator to create actions, views, services and DTOs and a per-action service approach makes this easier.

However I also want to use interfaces for the parameters in action classed which receive input from an HttpPost action. This is because I use DI to create classes outside each layer. If I change the DefaultModelBinder to use DI to create the class (see page 595 of Steve Sanderson’s book on MVC3 on how to do this) this this works fine, e.g.

    [HttpPost]
    public ActionResult Test(ITestClass dataComingFromView)
    {
        //model binder creates the class via DI and then binds it to the data from the post
        return View();
    }

However in the above simple example above I get a conflict with the ExtensibleActionInvoker enabled, i.e.

  1. Without ExtensibleActionInvoker enabled the method above works fine, i.e. the extended
    DefaultModelBinder uses DI to create the TestClass class and modelbinder binds
    input from the view to the fields in the class.
  2. With ExtensibleActionInvoker enabled it does not work, i.e. I get an empty TestClass class with no binding. I assume the ExtensibleActionInvoker takes precedence over the model binder and just creates an empty TestClass class.
  3. (Just for completeness I should say that if I just use MVC “out of the box”, i.e. no new DefaultModelBinder and no ExtensibleActionInvoker enabled, then it says you cannot use an interface as an Action method parameter.)

My question for anyone with better Autofac knowledge than me is: can I change the Autofac ExtensibleActionInvoker to select what it binds to? All my injected service classed start with IService so I could filter on that. I know you can do that in Autofac elsewhere but couldn’t see anything to do that with ExtensibleActionInvoker, but maybe I missed it.

Any help would be appreciated.

Jon Smith – Selective Analytics

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T02:18:18+00:00Added an answer on June 11, 2026 at 2:18 am

    Having now worked on this problem I found a simple answer. My problem was due to me not really understanding how the MVC Model Binding worked.

    If you look at my orginal problem I had created a DefaultModelBinder to allow me to use interfaces as my model parameters (see original question at the top). This was added after me including the Autofac’s ExtensibleActionInvoker to bind my IService types. The problem was that the two DI approaches clashed.

    The answer was that the DefaultModelBinder was sufficient to bind both my data classes and the Service definitions, so I do not need Autofac’s ExtensibleActionInvoker. For completeness I have included the DefaultModelBinder code in case it is useful to anyone else.

    public class DiModelBinder : DefaultModelBinder
    {
        protected override object CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType)
        {
            return modelType.IsInterface
                       ? DependencyResolver.Current.GetService(modelType)
                       : base.CreateModel(controllerContext, bindingContext, modelType);
        }
    }
    

    Note that I only call the DependencyResolver if the modeltype is an interface as I don’t pass abstract classes between layers. Any alternative is to always call the DependencyResolver and then call the base.CreateModel if the DI does not resolve the type. I didn’t do this because calling the DependencyResolver is slightly expensive so I only call it when I know I need it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET MVC application which sets up an Autofac IOCContainer within the
I have problem with my query on C, I’m using the oci8 driver. This
I have problem with show or hide form in Window Form Application. I start
I have run into an issue while creating a data service and using Autofac
I have problem with Uploadify: I log in the project using: FormsAuthentication.SetAuthCookie(myName, false); Then,
I have problem when I try to set a background to .header - nothing
I have problem in creating modular analysis architecture for C# application. Aim: It is
Have problem while getting data from Memcached on .NET MVC solution. I have this
Here's my problem: I have a container where I register concrete types as interfaces.
I have problem with building in Qt4 creator. I have some created projects and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.