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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:56:44+00:00 2026-06-17T17:56:44+00:00

I have a class that I would like to decorate twice. However, when I

  • 0

I have a class that I would like to decorate twice. However, when I resolve this class Windsor only decorates it once instead of using my 2 decorators. I’m not sure why this is the case because I registered both decorators before the class I’m resolving, which is how I understand decorators to work with Windsor.

Here is my code.

public interface IQueryExecuter
{
    TReturn Execute<TReturn>(IQuery<TReturn> query);
}

public class QueryLoggingDecorator : IQueryExecuter
{
    private ILogger _logger = NullLogger.Instance;

    public ILogger Logger
    {
        set { _logger = value; }
    }

    public TReturn Execute<TReturn>(IQuery<TReturn> query)
    {
        _logger.Info("Before query execute");
        var queryResults = query.Execute();
        _logger.Info("After query execute");

        return queryResults;
    }
}

public class QueryTransactionDecorator : IQueryExecuter
{
    public TReturn Execute<TReturn>(IQuery<TReturn> query)
    {
        try
        {
            Console.WriteLine("Beginning transaction");
            var queryResults = query.Execute();
            Console.WriteLine("Comitting transaction");

            return queryResults;
        }
        catch (Exception)
        {
            Console.WriteLine("Rolling back transaction");
            throw;
        }
    }
}

public interface IQuery<out TReturn>
{
    TReturn Execute();
}

public class Query : IQuery<string>
{
    public string Execute()
    {
        Console.WriteLine("Executing query");

        var queryResults = Path.GetRandomFileName();

        return queryResults;
    }
}

And here is my Windsor registration code.

public class DefaultInstaller : IWindsorInstaller
{
    public void Install(IWindsorContainer container, IConfigurationStore store)
    {
        container.Register(Component
            .For<IQueryExecuter>()
            .ImplementedBy<QueryLoggingDecorator>()
            .LifestyleTransient());
        container.Register(Component
            .For<IQueryExecuter>()
            .ImplementedBy<QueryTransactionDecorator>()
            .LifestyleTransient());
        container.Register(Component
            .For<IQueryExecuter>()
            .ImplementedBy<QueryExecuter>()
            .LifestyleTransient());
    }
}

And lastly, here is my calling code.

var container = new WindsorContainer();

container.Install(FromAssembly.This());

var queryExecuter = container.Resolve<IQueryExecuter>();
var queryResults = queryExecuter.Execute(new Query());

What am I missing?

I would expect that when I resolve IQueryExecuter that Windsor would decorate with QueryLoggingDecorator and then QueryTransactionDecorator.

  • 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-17T17:56:45+00:00Added an answer on June 17, 2026 at 5:56 pm

    The problem is these aren’t decorators; they’re just different implementations of the same interface. Decorators need something to actually decorate, which is an instance of the same interface they’re implementing, so they can call the next decorator in the chain.

    You need to set up an injectable reference to an IQueryExecuter. After that, Windsor handles the rest, injecting the decorator chain in the registered order (at least, according to the documentation).

    For example:

    public class QueryLoggingDecorator : IQueryExecuter
    {
        private ILogger _logger = NullLogger.Instance;
        private IQueryExecuter innerExecuter;
    
        public QueryLoggingDecorator(IQueryExecuter innerExecuter)
        {
            this.innerExecuter = innerExecuter;
        }
    
    
        public ILogger Logger
        {
            set { _logger = value; }
        }
    
        public TReturn Execute<TReturn>(IQuery<TReturn> query)
        {
            _logger.Info("Before query execute");
            var queryResults = innerExecuter.Execute(query);
            _logger.Info("After query execute");
    
            return queryResults;
        }
    }
    

    I will admit to not trying this out directly, but this blog indicated it would work.

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

Sidebar

Related Questions

I have a class that I would like to use in a scala.collection.mutable.PriorityQueue, but
I have a class in silverlight that I would like to store to disk.
I have a class that is marked with DataContract attributes and I would like
I have a class that is called regularly by several objects. I would like
I have a class that contains decoded video frames. I would like my decoder
I have a custom-made view that extends the View class. I would like 2
I have a class that I would like to share between a Cocoa and
If I have a class that I would like to customise by overriding one
I would like to have my abstract parent class have a method that would
I have a class that I would like to expose through a Jersey RESTful

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.