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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:58:01+00:00 2026-06-15T19:58:01+00:00

how do i use structuremap to give me the same concrete type configured one

  • 0

how do i use structuremap to give me the same concrete type configured one of 2 different possible ways? For example, i have a class configured to listen to a user queue in one instance, but configured for a facility queue in another instance. Everything else about the object is the same.

I created the object to accept an enum in the constructor, and based on the enum value, the object will listen to either the facility queue or the user queue. So how do I configure structuremap to pass me the two differently configured objects of the same type? The class implements my interface, so it looks like this:

public class Configuration : IConfiguration {
    public Configuration(enum configType) {
        if (configType == enum.users) {
            /* code */
        } else if(configType == enum.facilities) {
            /* code */
        }
    }
}

and then, i’m trying to setup the parent class to accept the configuration object twice, once configured for facilities, and once configured for users. How would I do this? I thought maybe I could do it based on when instance name of the two classes, but I can’t find anything in the documentation or elsewhere that might explain how to do this. Here’s what the parent class looks like:

public class Parent : IParent {
    public Parent(IConfiguration facilityConfig, IConfiguration userConfig) {
    }
}

So, in the parent class, I would want “facilityConfig” to be an instance of Configuration with enum.facilities passed in, while the “userConfig” object would be an instance of the same Configuration class, but with enum.users passed in. Let me know if what I’m asking doesn’t make sense.

  • 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-15T19:58:02+00:00Added an answer on June 15, 2026 at 7:58 pm

    One solution for this problem could be to have two separate configuration classes, instead of one that does the switch based on the enum value.

    You could define the IConfiguration implementations like this:

    public class UsersConfiguration : IConfiguration
    {
        /* code for user */
    }
    
    public class FacilitiesConfiguration : IConfiguration
    {
        /* code for facilities */
    }
    

    and then, in your container configuration you could use Ctor to specify which types to resolve your constructor arguments to:

    var c = new StructureMap.Container();
    
    c.Configure(x =>
        {
            x.For<IParent>().Use<Parent>()
                .Ctor<IConfiguration>("facilityConfig").Is<FacilitiesConfiguration>()
                .Ctor<IConfiguration>("userConfig").Is<UsersConfiguration>();
        });
    

    After this registration, you can create an IParent instance:

    var p = c.GetInstance<IParent>();
    

    and notice that the two dependencies were correctly set by the container.


    Update:

    If having different implementations for IConfiguration is problematic, then you can tell StructureMap exactly how to instantiate a Parent:

    var c = new Container(x =>
    {
        x.For<IParent>().UseSpecial(i => i.ConstructedBy(ConstructParent));
    });
    

    The ConstructParent() method can be defined like this:

    private static IParent ConstructParent()
    {
        return new Parent(
                    new Configuration(ConfigType.facilities),
                    new Configuration(ConfigType.users));
    }
    

    If you prefer, you can do this all in one shot:

    var c = new Container(x =>
    {
        x.For<IParent>().UseSpecial(i => i.ConstructedBy(
            _ => new Parent(
                new Configuration(ConfigType.facilities),
                new Configuration(ConfigType.users))));
    });
    

    However, in a case like this (“exactly the same apart from this one config value”) I would prefer to extract the common definitions in a base (perhaps abstract) class and have two derivatives that only define the config value that differs.

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

Sidebar

Related Questions

How can I figure StructureMap to use more than one concrete Class per Interface.
Firstly, I'm starting to use StructureMap, but an example in any DI framework will
With StructureMap one can do a resolution and force the container to use specific
I'm trying to use the MoqAutoMocker class that comes with StructureMap and I can't
I have a generic interface, IValidator. I want to be able to use StructureMap
Assuming that I have a complex type, for example: interface IFoo { IBar {get;set;}
I configured an ASP.NET MVC 4 Web API project to use StructureMap 2.6.2.0 as
I have an interface IRepository and an implementation EFRepository. I use structuremap injection in
I have a simple MVC3 Web application. I use structureMap as a dependency Injection.
All our apps have been converted to use StructureMap, and our libraries were converted

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.