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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:53:50+00:00 2026-05-24T10:53:50+00:00

I have a command class that needs to have 2 constructors. However, using structuremap

  • 0

I have a command class that needs to have 2 constructors. However,
using structuremap it seems that I can only specify one constructor to
be used. I have solved the problem for now by subtyping the specific
command class, which each implementation implementing it’s own
interface and constructor. Like the code below shows. The
ISelectCommand implements two separate interfaces for the
string constructor and the int constructor, just for the sake of
registering the two subtypes using structuremap.

However, I consider this a hack and I just wonder why is it not
possible for structuremap to resolve the constructor signature by the
type passed in as parameter for the constructor? Then I could register
the SelectProductCommand as an ISelectCommand and
instantiate it like:
ObjectFactury.With(10).Use>();
orObjectFactury.With(“testproduct”).Use>();

public class SelectProductCommand : ISelectCommand<IProduct>,
ICommand, IExecutable
{
   private readonly Func<Product, Boolean> _selector;
   private IEnumerable<IProduct> _resultList;

   public SelectProductCommand(Func<Product, Boolean> selector)
   {
       _selector = selector;
   }

   public IEnumerable<IProduct> Result
   {
       get { return _resultList; }
   }

   public void Execute(GenFormDataContext context)
   {
       _resultList = GetProductRepository().Fetch(context,
_selector);
   }

   private Repository<IProduct, Product> GetProductRepository()
   {
       return ObjectFactory.GetInstance<Repository<IProduct,
Product>>();
   }
}

public class SelectProductIntCommand: SelectProductCommand
{
    public SelectProductIntCommand(Int32 id): base(x =>
 x.ProductId == id) {}
}

public class SelectProductStringCommand: SelectProductCommand
{
    public SelectProductStringCommand(String name): base(x =>
x.ProductName.Contains(name)) {}
}

P.s. I know how to tell structuremap what constructor map to use, but my again my question is if there is a way to have structuremap select the right constructor based on the parameter passed to the constructor (i.e. using regular method overloading).

  • 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-24T10:53:51+00:00Added an answer on May 24, 2026 at 10:53 am

    I think I solved the problem using a small utility class. This class gets the concrete type from ObjectFactory and uses this type to construct the instance according to the parameters past into the factory method. Now on the ‘client’ side I use ObjectFactory to create an instance of CommandFactory. The implementation of CommandFactory is in another solution and thus the ‘client solution’ remains independent of the ‘server’ solution.

    public class CommandFactory
    {
    
        public ICommand Create<T>()
        {
            return Create<T>(new object[] {});
        }
    
        public ICommand Create<T>(object arg1)
        {
            return Create<T>(new[] {arg1});
        }
    
        public ICommand Create<T>(object arg1, object arg2)
        {
            return Create<T>(new[] {arg1, arg2});
        }
    
        public ICommand Create<T>(object arg1, object arg2, object arg3)
        {
            return Create<T>(new[] {arg1, arg2, arg3});
        }
    
        public ICommand Create<T>(object[] arguments)
        {
            return (ICommand)Activator.CreateInstance(GetRegisteredType<T>(), arguments);
        }
    
        public static Type GetRegisteredType<T>()
        {
            return ObjectFactory.Model.DefaultTypeFor(typeof (T));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I have a Command that can be called from both a Window
I'm dealing with a hardware resource that can only handle 1 command at a
I have a command line executable that alters some bits in a file that
I have a command that runs fine if I ssh to a machine and
I have this command that I run everyday via cron: find /home/get/public_html/videos -daystart -maxdepth
I have a command-line utility that gets quite a bit of downloads from my
I have this command that I run every 24 hours currently. find /var/www/html/audio -daystart
I'm writing an Excel Addin using COM Interop from .net. I have a command
Summary I have written a process monitor command-line application that takes as parameters: The
I have a class which has the following constructor public DelayCompositeDesigner(DelayComposite CompositeObject) { InitializeComponent();

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.