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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:17:02+00:00 2026-05-15T03:17:02+00:00

Consider the following example: public interface ITask { void Execute(); } public class LoggingTaskRunner

  • 0

Consider the following example:

public interface ITask
{
    void Execute();
}

public class LoggingTaskRunner : ITask
{
    private readonly ITask _taskToDecorate;
    private readonly MessageBuffer _messageBuffer;

    public LoggingTaskRunner(ITask taskToDecorate, MessageBuffer messageBuffer)
    {
        _taskToDecorate = taskToDecorate;
        _messageBuffer = messageBuffer;
    }

    public void Execute()
    {
        _taskToDecorate.Execute();
        Log(_messageBuffer);
    }

    private void Log(MessageBuffer messageBuffer)
    {}
}

public class TaskRunner : ITask
{
    public TaskRunner(MessageBuffer messageBuffer)
    {

    }

    public void Execute()
    {
    }
}

public class MessageBuffer
{

}


public class Configuration
{
    public void Configure()
    {
        IWindsorContainer container = null;

        container.Register(
            Component.For<MessageBuffer>()
                .LifeStyle.Transient);

        container.Register(
            Component.For<ITask>()
                .ImplementedBy<LoggingTaskRunner>()
                .ServiceOverrides(ServiceOverride.ForKey("taskToDecorate").Eq("task.to.decorate")));

        container.Register(
            Component.For<ITask>()
            .ImplementedBy<TaskRunner>()
            .Named("task.to.decorate"));

    }

}

How can I make Windsor instantiate the “shared” transient component so that both “Decorator” and “Decorated” gets the same instance?

Edit: since the design is being critiqued I am posting something closer to what is being done in the app. Maybe someone can suggest a better solution (if sharing the transient resource between a logger and the true task is considered a bad design)

Edit2: Castle3 has added support for this (http://docs.castleproject.org/Windsor.Whats-New-In-Windsor-3.ashx) by introducing the “Bound” lifestyle

  • 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-15T03:17:03+00:00Added an answer on May 15, 2026 at 3:17 am

    ‘Transient’ explicitly means ‘non-shared’, so what you are asking is conceptually the wrong thing to do. The correct solution is to register Shared as a Singleton instead of Transient:

    container.Register(Component.For<Shared>());
    

    (Singleton is the default lifetime in Windsor.)

    However, I suspect that behind the stated question lies a much more complex problem. I’m guessing that you need Shared to be Transient because you need it with this lifestyle for a lot of other cases, but exactly when it comes to the relationship between Decorator and Decorated you need to share them.

    I still think this sounds like a Design Smell, but there are at least two ways you can achieve this result.

    The first option involves prematurely resolving Shared and explicitly supply the resolved instance to the configuration of the two IFoo registrations:

    container.Register(Component.For<Shared>().LifeStyle.Transient);
    
    var r = container.Resolve<Shared>();
    
    container.Register(Component
        .For<IFoo>()
        .ImplementedBy<Decorator>()
        .DependsOn(new { resource = r }));
    container.Register(Component
        .For<IFoo>()
        .ImplementedBy<Decorated>()
        .DependsOn(new { resource = r }));
    

    The second option is to make a specialized, named registration for Shared that is used only by the IFoo registrations:

    container.Register(Component.For<Shared>().LifeStyle.Transient);
    container.Register(Component.For<Shared>().Named("shared"));
    container.Register(Component
        .For<IFoo>()
        .ImplementedBy<Decorator>()
        .ServiceOverrides(new { resource = "shared" }));
    container.Register(Component
        .For<IFoo>()
        .ImplementedBy<Decorated>()
        .ServiceOverrides(new { resource = "shared" }));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following example: public class Sandbox { public interface Listener<T extends JComponent> {
Consider following example : public class SomeBusinessLayerService : DataService<MyEntityContainer> { [WebInvoke] void DoSomething(string someParam)
Consider the following example: template <typename T> class A { public: void f() {
Consider the following example class Foo{ public: Foo(int i):x(i){} int x; }; void bar(Foo
Consider the following code. public interface IFoo { } public class Bar { public
Consider the following simple RESTEasy (JAX-RS) service: @Path(/example-service) public interface ExampleService { @Path(/ping) @GET
Consider the following example: interface IPropertyCollection { public MethodWrapper GetPropertySetterByName(string name); //<<-- I want
Consider the following example code: class Foo { }; class Bar : public Foo
Consider the following example: Public Class ParentClass Public Sub GenerateReport Dim Col As Collection
To illustrate my question consider the following example: @Entity public class Box implements Serializable

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.