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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:24:54+00:00 2026-05-26T00:24:54+00:00

very new to Structure-Map. trying to figure it out how it works and how

  • 0

very new to Structure-Map. trying to figure it out how it works and how can i benefit from it.

i have got this so far..

Global.asax.cs:

IContainer container = new Container(x =>
    {
         x.For<IControllerActivator>().Use
              <StructureMapControllerActivator>();
         x.For<IUserRepo>().Use<UserRepo>();
    }); 

DependencyResolver.SetResolver(new StructureMapDependencyResolver(container));

StructureMapControllerActivator:

public class StructureMapControllerActivator : IControllerActivator
{
    private readonly IContainer _container;

    public StructureMapControllerActivator(IContainer container )
    {
        this._container = container;
    }

    public IController Create(RequestContext requestContext, Type controllerType)
    {
        return _container.GetInstance(controllerType) as IController;
    }
}

StructreMapDependencyResolver:

private readonly IContainer _container;

    public StructureMapDependencyResolver(IContainer container )
    {
        this._container = container;
    }

    public object GetService(Type serviceType)
    {
        object instance = _container.TryGetInstance(serviceType);
        if(instance == null && !serviceType.IsAbstract)
        {
            _container.Configure(c => c.AddType(serviceType,serviceType));
            instance = _container.TryGetInstance(serviceType);
        }
        return instance;
    }

    public IEnumerable<object> GetServices(Type serviceType)
    {
        return _container.GetAllInstances(serviceType).Cast<object>();
    }
}

My AccountController:

public class AccountController : Controller
{
    private readonly IUserRepo _userRepo;

    private AccountController()
    {
        _userRepo = ObjectFactory.GetInstance<IUserRepo>();
    }

    public ActionResult Login()
    {
        return View();
    }
}

Error Code & Description:

StructureMap Exception Code: 202
No Default Instance defined for PluginFamily MBP_Blog.Controllers.AccountController
MBP-Blog, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

I have a Interface Name : IUserRepo and a repository Name: UserRepo

please help as I try to google but dint find any solution within first 3 pages.

New error after using @Martin’s code:

StructureMap Exception Code: 180
StructureMap cannot construct objects of Class MBP_Blog.Controllers.AccountController, MBP-Blog, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null because there is no public constructor found.

  • 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-26T00:24:55+00:00Added an answer on May 26, 2026 at 12:24 am

    Take out the StructureMapControllerActivator, I don’t think you need it. If you keep it, you need to add a mapping for your AccountController.

    Also, use Controller Injection instead, it will make unit testing easier:

    public class AccountController : Controller
    {
        private readonly IUserRepo _userRepo;
    
        public AccountController(IUserRepo userRepo)
        {
            _userRepo = userRepo;
        }
    
        public ActionResult Login()
        {
            return View();
        }
    }
    

    Also again, for your Container, you can default the mappings. This will automatically map IService to Service :

    IContainer container = new Container(
                x =>
                    {
                        x.Scan(scan =>
                                   {
                                       scan.Assembly("MBP_Blog");
                                       scan.Assembly("MBP_Blog.Data");
                                       scan.WithDefaultConventions();
                                   });
                    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to figure out how to structure this database. I have used
Very new to python and can't understand why this isn't working. I have a
Im very new in C++ I have found this post http://msdn.microsoft.com/en-us/magazine/cc163486.aspx and trying to
I'm very new to this, so go easy on me. From my understanding, JAXB
I am very new to rails, and from what i have been reading and
I am very new to RoR so this may be very fundamental. My structure
Very new to JQuery and MVC and webdevelopment over all. I'm now trying to
Very new mobile developer here... I am trying to retrieve a list of tweets
I very new to Python, and fairly new to regex. (I have no Perl
I am trying to get the best from the excellent open source Mind Map

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.