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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:48:55+00:00 2026-05-28T20:48:55+00:00

I’m implementing a finite-state machine, with each class representing a state. Each state knows

  • 0

I’m implementing a finite-state machine, with each class representing a state. Each state knows which other states it can transition to, and this naturally leads to circular relationships. (See the State Design Pattern).

For this simplified example I’m creating two components, where the first component has a reference to the second component, and the second component has a reference to the first.

The problem is that the Windsor framework is correctly setting the references for the first created component, but not setting the references for the second:

Here are the two components:

// DefaultMouseHandler knows about NewLineMouseHandler
public class DefaultMouseHandler : MouseHandler
{
    public DefaultMouseHandler()
    {
    }

    public NewLineMouseHandler NewLineMouseHandler
    {
        get;
        set;
    }

    internal override MouseHandler LeftButtonDown(System.Windows.Input.MouseButtonEventArgs e)
    {
        return this.NewLineMouseHandler;
    }
}


// NewLineMouseHandler knows about DefaultMouseHandler
public class NewLineMouseHandler : MouseHandler
{
    public NewLineMouseHandler()
    {
    }

    public DefaultMouseHandler DefaultMouseHandler
    {
        get;
        set;
    }

    internal override MouseHandler LeftButtonUp(System.Windows.Input.MouseButtonEventArgs e)
    {
        return this.DefaultMouseHandler;
    }
}

I then register the components as so:

_windsorContainer.Register(Classes.FromThisAssembly()
                                 .BasedOn<MouseHandler>()
                         );

But when I first attempt to create the DefaultMouseHandler:

  • The DefaultMouseHandler is constructed
  • The NewLineMouseHandler is constructed
  • The NewLineMouseHandler is set on the DefaultMouseHandler

But the DefaultMouseHandler is NOT set on the NewLineMouseHandler.

Can this be considered a defect in Castle Windsor?

What’s the best way to have the two components referencing each other, without either component being aware of the Windsor container?

  • 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-28T20:48:57+00:00Added an answer on May 28, 2026 at 8:48 pm

    The solution I’ve come up with is to use the TypedFactoryFacility.

    This allows objects to be created as they are needed, so we don’t have the complications of them all being dependent upon one another at initialization time.

    public interface IMouseHandlerFactory
    {
        T CreateHandler<T>() where T : MouseHandler;
    }
    
    // In the registration code
    _windsorContainer.AddFacility<TypedFactoryFacility>();
    _windsorContainer.Register(Classes.FromThisAssembly()
                                   .BasedOn<MouseHandler>(),
                               Component.For<IMouseHandlerFactory>()
                                        .AsFactory()
                              );
    
    // The base class
    public abstract class MouseHandler
    {
        // Every mousehandler will create at least one other mouse handler
        // This is the factory that they will use for mouse handling creation
        // The property will be automatically set by the DI container
        public IMouseHandlerFactory MouseHandlerFactory { get; set; }
    
        // Methods the concrete implementations will override
        internal virtual MouseHandler LeftButtonDown(MouseButtonEventArgs e) { return this; }
        internal virtual MouseHandler LeftButtonUp(MouseButtonEventArgs e) { return this; }
    }   
    
    // The implementations
    public class DefaultMouseHandler : MouseHandler
    {
        internal override MouseHandler LeftButtonDown(MouseButtonEventArgs e)
        {
            return this.MouseHandlerFactory.CreateHandler<NewLineMouseHandler>();
        }
    }
    
    public class NewLineMouseHandler : MouseHandler
    {
        internal override MouseHandler LeftButtonUp(MouseButtonEventArgs e)
        {
            return this.MouseHandlerFactory.CreateHandler<DefaultMouseHandler>();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,

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.