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 4617278
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:06:07+00:00 2026-05-22T02:06:07+00:00

What Autofac version should I use for ASP.NET MVC 1.0. Also, What examples are

  • 0

What Autofac version should I use for ASP.NET MVC 1.0. Also, What examples are available for using it with ASP.NET MVC using the repository pattern?

public class MyController : BaseController
{
    private readonly IUser _user;
    private readonly ICompany _company;

    public MyController(IUser user, ICompany company)
    {
        _user = user;
        _company = company;
    }

    public ActionResult Index()
    {
        // Actions
    }
}
  • 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-05-22T02:06:07+00:00Added an answer on May 22, 2026 at 2:06 am

    I’ve decided to use StructureMap for my application. Here’s what I’ve did to make it work:

    Create my own CustomFactory class:

    public class StructureMapControllerFactory : DefaultControllerFactory
    {
        protected override IController GetControllerInstance(Type controllerType)
        {
            if (controllerType == null)
            {
                return base.GetControllerInstance(controllerType);
            }
    
            try
            {
                return ObjectFactory.GetInstance(controllerType) as Controller;
            }
            catch (StructureMapException ex)
            {
                throw;
            }
        }
    }
    

    Create a Bootstrapper, using the StructureMap convention to register all the interfaces and its implementation for my assembly. (I’ve posted a blog post on this):

    public class StructureMapBootstrapper : IBootstrapper
    {
        private static bool hasStarted;
    
        public void BootstrapStructureMap()
        {
            ObjectFactory.Initialize(x =>
            {
                x.AddRegistry<FactoryRegistry>();
            });
        }
    
        public static void Restart()
        {
            if (hasStarted)
            {
                ObjectFactory.ResetDefaults();
            }
            else
            {
                Bootstrap();
                hasStarted = true;
            }
        }
    
        public static void Bootstrap()
        {
            new StructureMapBootstrapper().BootstrapStructureMap();
        }
    }
    
    public class FactoryRegistry : Registry
    {
        public FactoryRegistry()
        {
            Scan(s =>
            {
                s.Assembly("Calendar.Library");
                s.TheCallingAssembly();
                s.AddAllTypesOf<IController>().NameBy(type => type.Name.Replace("Controller", "").ToLower());
                s.WithDefaultConventions();
            });
        }
    }
    

    Register StructureMap in Global.asax.cs:

    protected void Application_Start()
    {
        StructureMapBootstrapper.Bootstrap();
        ControllerBuilder.Current.SetControllerFactory(new StructureMapControllerFactory());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use Autofac and Autofac.Integrations.Web to register ASP.NET MVC controllers. I
I'm using Autofac with ASP.NET MVC so all my controllers have their dependencies resolved
I am using Autofac with ASP.NET MVC integration, all my controllers receive dependencies and
Hi I want to use Autofac in my asp.net mvc appliation and here is
Using Autofac, I have the following scenario: public class MainClass { public delegate MainClass
I working on asp.net mvc3 project. I am using autofac for DI. I have
I have autofac set up to do dependency injection of my asp.net MVC controllers,
On ASP.NET MVC 2 I have an ActionFilterAttribute called [Transaction] that starts an NHibernate
Autofac automatically generates factories for Func<T> ; I can even pass parameters. public class
I am using Autofac 2.4.5.724 under vb.net 2010. I have several classes without default

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.