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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:57:53+00:00 2026-06-01T17:57:53+00:00

I am using StructureMap for DI and am having an issue with my MVC3

  • 0

I am using StructureMap for DI and am having an issue with my MVC3 custom base controller not being instantiated correctly. Instead of being passed an instance of IAuctionCmsServices, I am getting null.

My controllers:

public class BaseController : Controller
{
    public IAuctionCmsServices AuctionCmsServices;

    public BaseController()
        : this(null)        <--- is this the problem?
    {

    }

    public BaseController(IAuctionCmsServices auctionCmsServices)
    {
        this.AuctionCmsServices = auctionCmsServices;
    }
}

public class HomeController : BaseController
{
    public ActionResult Index()
    {
        return View);
    }
}

StructureMap code:

public class StructureMapContainer : IDependencyResolver
{
    static IContainer _container;

    public StructureMapContainer(IContainer container)
    {
        _container = container;
    }

    public object GetService(Type serviceType)
    {
        if (serviceType.IsAbstract || serviceType.IsInterface)
        {
            return _container.TryGetInstance(serviceType);
        }
        else
        {
            System.Diagnostics.Debug.WriteLine(_container.WhatDoIHave());
            return _container.GetInstance(serviceType);
        }
    }

    public IEnumerable<object> GetServices(Type serviceType)
    {
        return _container.GetAllInstances<object>().Where(s => s.GetType() == serviceType);
    }
}

public class ApplicationRegistry : Registry
{
    public ApplicationRegistry()
    {
        For<IAuctionCmsServices>().HybridHttpOrThreadLocalScoped().Use<AuctionCmsServices>();
    }
}

In global.asax.cs:

DependencyResolver.SetResolver(new StructureMapContainer(container));

When BaseController’s constructor is invoked, the IAuctionCmsServices parameter is null. If I remove the this(null) from the constructor, I still get null.

Perhaps my BaseController’s paramterless constructor is not written correctly? If I resolve for IAuctionCmsServices manually, it works. This means that IAuctionCmsServices is registered correctly but not being injected.

  • 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-01T17:57:55+00:00Added an answer on June 1, 2026 at 5:57 pm

    Did you leave out the constructor HomeController from the sample or do you not have one?

    Im not really familiar with StructureMap, so unless it does some wizardry with the IL, how is the property supposed to be injected into HomeController if it does not have a constructor that accepts it?

    IE

    public HomeController(IAuctionCmsServices auctionCmsServices)
     : base(auctionCmsServices)
    {}
    

    Apologies if Im being dense or missing something.

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

Sidebar

Related Questions

I'm on an MVC3 project and I am using snap structuremap for my dependecy
I am using SignalR in my MVC3 application, and since I have implemented StructureMap
I'm using Structure map and want to inject instance (constructed by container) into controller's
I'm using StructureMap, v. 2.5.3 and am having trouble with chaining together implementations on
I have an ASP.NET MVC 2 application with a custom StructureMap controller factory to
I'm using StructureMap to Enrich some of my objects with an instance call to
I have just started using StructureMap, having previously worked with Spring.Net. I love the
In Using StructureMap 2.5 to scan all assemblies in a folder , we can
I'm currently using StructureMap to inject instances of NHibernate ISessions using the following code:
I have an asp.net mvc2 application that is using StructureMap 2.6 and NHibernate 3.x.

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.