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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:21:31+00:00 2026-06-15T21:21:31+00:00

If I have the following code [Serializable] public abstract class ValidatedCommandArgs { } public

  • 0

If I have the following code

[Serializable]
public abstract class ValidatedCommandArgs
{
}

public interface IValidatedCommand<T>
    where T : ValidatedCommandArgs
{
    IEnumerable<ValidationError> Execute(T args);
}

Now a simple implementation

public class CreateClientArgs : ValidatedCommandArgs
{
    public string Code { get; set; }
    public string Name { get; set; }
}

public class CreateClientCommand : IValidatedCommand<CreateClientArgs>
{
    public IEnumerable<ValidationError> Execute(CreateClientArgs args)
    {
        throw new NotImplementedException();
    }
}

Then register the command handler

container.RegisterType<IValidatedCommand<CreateClientArgs>>, CreateClientCommand>();

Now what I want to be able to do is to wrap every resolution of IValidatedCommand so that I can essentially do this

public class LoggedCommandHandler<T> : IValidatedCommand<T>
    where T : ValidatedCommandArgs
{
    readonly IValidatedCommand<T> Inner;

    public LoggedCommandHandler(IValidatedCommand<T> inner)
    {
        this.Inner = inner;
    }

    IEnumerable<ValidationError> IValidatedCommand<T>.Execute(T args)
    {
        //Serialize ARGS
        //Save Inner.GetType().ClassName + the serialized args to the DB
        return Inner.Execute(args);
    }
}

Then whenever I resolve (for example) IValidatedCommand<CreateClientArgs> I would actually get an instance of LoggedCommandHandler<CreateClientArgs> which is resolved with inner = CreateClientCommand

Sorry for being so verbose, but I don’t recall what the technique is called.

  • 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-15T21:21:33+00:00Added an answer on June 15, 2026 at 9:21 pm

    What you are looking for is called the Decorator Pattern.

    There is an extension for Unity that helps you in using it.


    Update

    This solution is more explicit than the one by Jim Christopher.

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

Sidebar

Related Questions

Ok, I have the following code. public class MyProgressBar extends JPanel implements MyData, Serializable
I have an Abstract class: [Serializable] public abstract class BaseModel { public virtual int
Consider the following code: [Serializable] public class Human { public string Name { get;
I have this code @Entity @Table(name = picture) public class Picture implements Serializable {
We have the followig code: [Serializable] public class Class1 { [XmlElement(description)] public string Description
Let's say I have the following code: public class Foo { private int x;
I have the following Java class: public class GetCardInfoRequest implements RequestBase, java.io.Serializable{ public String
Have the following structure [Serializable] public class Parent { public int x = 5;
I have the following class signature and ClientEventSourc implements Serializable : public class Grid
I have the following class: @MappedSuperclass public abstract class MappedModel { @Id @GeneratedValue(strategy =

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.