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

  • SEARCH
  • Home
  • 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 8250067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:46:00+00:00 2026-06-07T23:46:00+00:00

Is it possible to configure Autofac to work with ASP .NET MVC and ASP

  • 0

Is it possible to configure Autofac to work with ASP .NET MVC and ASP .NET Web Api. I’m aware that the dependency resolvers are different. But when using the documented approaches I can only set one global resolver.

// Set the dependency resolver implementation.
GlobalConfiguration.Configuration.DependencyResolver = resolver;

Is this approach bad idea? Should I separate my solution into two projects and handle the dependency injection for each individually?

  • 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-07T23:46:02+00:00Added an answer on June 7, 2026 at 11:46 pm

    It is certainly possible to configure Autofac to work with both MVC and Web API. This is expected to be a very common scenario. There are two separate dependency resolver implementations because MVC and Web API can be used independently of one another. The same applies for the Autofac integrations.

    When using both MVC and Web API in the same application each will require its own dependency resolver, though they can be provided with the same instance of the container.

    var builder = new ContainerBuilder();
    
    // Add your registrations
    
    var container = builder.Build();
    
    // Set the dependency resolver for Web API.
    var webApiResolver = new AutofacWebApiDependencyResolver(container);
    GlobalConfiguration.Configuration.DependencyResolver = webApiResolver;
    
    // Set the dependency resolver for MVC.
    var mvcResolver = new AutofacDependencyResolver(container);
    DependencyResolver.SetResolver(mvcResolver);
    

    It is also possible to share registrations between the two because the InstancePerApiRequest and InstancePerHttpRequest lifetime scopes now share the same tag.

    Note that the mechanism for setting the dependency resolver for Web API and MVC is different. Web API uses GlobalConfiguration.Configuration.DependencyResolver and MVC uses DependencyResolver.SetResolver.

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

Sidebar

Related Questions

Is it possible to configure MAF in an ASP.NET such a way that it
Is it possible to configure asp.net development server to be web server at 80
I am aware that it is possible to configure vim to highlight all matches
Is it possible to configure an IIS site to read ASP.Net settings from a
Is it possible to configure the ClickOnce installation so that it requires .Net Framework
Is it possible to configure Apache Tomcat to simulate network latency that a client
Is is possible ot configure Chainsaw to read log files that have been customized
Is it possible to configure svn such that it automatically sets the svn:keywords property
In views, is it possible to configure a cck taxonomy field so that a
In Windows Forms, is it possible to configure a drop-down combobox control so that

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.