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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:47:02+00:00 2026-06-13T16:47:02+00:00

I read the following article .NET Junkie – Meanwhile… on the command side of

  • 0

I read the following article .NET Junkie – Meanwhile… on the command side of my architecture which was suggested by another stackoverflow user that outlines the command pattern and provides a strategy for how to use it with DI at the end of the article.

This has helped immensely but the one thing I’m missing, let’s say I create a new class called CheckoutCustomerCommandHandler.

Now, let’s say I need to inject this command and the MoveCustomerCommandHandler into a controller for whatever reason via the constructor. How does this affect the DI container setup and the constructor?

At the core, they both implement the same interface. It seems like this would result in a lookup issue for the DI container. In the article example, here is their sample injector setup:

public interface ICommandHandler<TCommand>
{
    void Handle(TCommand command);
}

// Exactly the same as before, but now with the interface.
public class MoveCustomerCommandHandler
: ICommandHandler<MoveCustomerCommand>
{
    private readonly UnitOfWork db;

    public MoveCustomerCommandHandler(UnitOfWork db,
    [Other dependencies here])
    {
        this.db = db;
    }

    public void Handle(MoveCustomerCommand command)
    {
        // TODO: Logic here
    }
}

// Again, same implementation as before, but now we depend
// upon the ICommandHandler abstraction.
public class CustomerController : Controller
{
    private ICommandHandler<MoveCustomerCommand> handler;

    public CustomerController(
    ICommandHandler<MoveCustomerCommand> handler)
    {
        this.handler = handler;
    }

    public void MoveCustomer(int customerId, 
        Address newAddress)
    {
        var command = new MoveCustomerCommand
        {
            CustomerId = customerId,
            NewAddress = newAddress
        };

        this.handler.Handle(command);
    }
}

using SimpleInjector;
using SimpleInjector.Extensions;

var container = new Container();

// Go look in all assemblies and register all implementations
// of ICommandHandler<T> by their closed interface:
container.RegisterManyForOpenGeneric(
    typeof(ICommandHandler<>),
    AppDomain.CurrentDomain.GetAssemblies());

// Decorate each returned ICommandHandler<T> object with
// a TransactionCommandHandlerDecorator<T>.
container.RegisterDecorator(typeof(ICommandHandler<>),
    typeof(TransactionCommandHandlerDecorator<>));

// Decorate each returned ICommandHandler<T> object with
// a DeadlockRetryCommandHandlerDecorator<T>.
container.RegisterDecorator(typeof(ICommandHandler<>),
    typeof(DeadlockRetryCommandHandlerDecorator<>));
  • 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-13T16:47:04+00:00Added an answer on June 13, 2026 at 4:47 pm

    Here’s what your class declarations would look like…

    public class CheckoutCustomerCommandHandler :
        ICommandHandler<CheckoutCustomerCommand> {...}
    
    public class MoveCustomerCommandHandler : 
        ICommandHandler<MoveCustomerCommand> {...}
    

    These may look like they implement the same interface, but they actually compile to two different interfaces because the generics arguments are different. Your DI framework will be able to distinguish between them.

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

Sidebar

Related Questions

I read the german article about Make on Wikipedia and found the following 2
I read the following paragraph on Wikipedia article about the CLR: Alternatively, the CIL
For a long time I had the following bookmark in Firefox: http://www.codeguru.com/csharp/.net/net_general/keyboard/article.php/c4639 I know
I have read the following article http://lifehacker.com/5919918/how-your-passwords-are-stored-on-the-internet-and-when-your-password-strength-doesnt-matter There are a number of ways a
I read the following in an article Immutable objects are particularly handy for implementing
I've read the following Mozilla Developer article that explains how to implement HTML 5
I have been following this article to read an XML file into a datagridview
I am using a command in the proc file system which is the following
I am following http://www.mikesdotnetting.com/Article/125/ASP.NET-MVC-Uploading-and-Downloading-Files . Using VS2010, ASP.NET 4.0, MVC3 in C# with ADO.NET
I've read a few articles about cryptography in .net, which leads me to the

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.