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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:11:11+00:00 2026-05-23T06:11:11+00:00

I have following interface public interface IBuilder<T> { T Create(string param); } with many

  • 0

I have following interface

 public interface IBuilder<T>
 {
    T Create(string param);
 }

with many classes that implement the interface above. One of them is:

 public class ConcreteABuilder : IBuilder<ConcreteA>
 {
        public ConcreteA Create(string param)
        {
            return new ConcreteA();
        }
 }

I’m using StructureMap to register all classes that implement IBuilder<>

Scan(x =>
{
      x.TheCallingAssembly();
      x.AddAllTypesOf(typeof(IBuilder<>));
});    

Now, I have 2 cases

EDITED

I get the types(in both cases) in the form of System.Type

Case 1

At runtime I get any T type(System.Type) (e.g. typeof(ConcreteA)) and I need to get the matched builder instance. In this case it must return ConcreteABuilder instance.

Case 2

At runtime I get the type(System.Type) of some implemented IBuilder(e.g. typeof(ConcreteABuilder)) and I need to get the matched builder instance. In this case it must return ConcreteABuilder instance.

How using StructureMap’s ObjectFactory to solve Case1 & Case2?

Thank you

  • 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-23T06:11:12+00:00Added an answer on May 23, 2026 at 6:11 am

    I think what you’re looking for is registering your types with:

    x.ConnectImplementationsToTypesClosing(typeof(IBuilder<>))
    

    Then asking the container for an IBuilder<ConcreteA> or a ConcreteABuilder will return a ConcreteABuilder… now the problem is that since you don’t know the type until runtime (selected by the user or something?), you can only use the non-generic version:

    object someBuilder = ObjectFactory.GetInstance(thePassedInTypeAtRuntime);
    ... then use reflection to invoke the createMethod
    

    or

    dynamic someBuilder = (dynamic)ObjectFactory.GetInstance(thePassedInTypeAtRuntime);
    ....
    

    and somewhere where you actually know that you’re asking for a an IBuilder that can return ConcreteA

    ConcreteA myA = someBuilder.Create(someParams);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following classes public interface InterfaceBase { } public class ImplementA:InterfaceBase {
Say I have the following: namespace SomeProject { public interface ISomething { string SomeMethod();
Let's say that I have the following interface: public interface IMyService { void SimpleMethod(int
Example, I have the following interface and classes: public interface IRole { DateTime Since
I have the following: public interface ICartItem { string Name { get; set; }
Let's say I have the following Java interface that I may not modify: public
I have the following interface: public interface ILogger { void Debug(string message, params object[]
I have the following interface public interface DeviceKey { String getKey(); } I also
I have defined the following interface: public interface IHaveAProblem { string Issue { get;
Imagine we have following classes: public interface MyInterface<T> { List<T> getList(T t); } abstract

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.