I'm wondering how StartableFacility in differed mode works.

I expect that Start() methods will be called after all the startable 
components have been initialized. Otherwise Start() method looks 
meaningless because all it's code might be put in constructor and there is 
no much difference whether to put code in constructor or into Start() 
method.


 In general, I expect StartableFacility initialized in differed mode allows 
me to “assemble a complex mechanism” through the constructors and then 
start it.


 But now (at least in Castle.Windsor.3.2.1) StartableFacility resolves and 
starts every component separately.


 Let me explain my case.

I have a component A that fires events and component B that subscribes on 
the events.

B subscribes on A in it's constructor.

A fires the event in it's Start() method.


    public interface IEventsSource

    {

        event Action Event;

    }


    class A : IEventsSource, IStartable

    {

        public event Action Event;


        public A()

        {

             Console.WriteLine("Constructor A");

        }


        public void Start()

        {

            Console.WriteLine("Fire event");

            

            Action handlers = Event;

            if (handlers != null)

            {

                handlers();

            }

        }


        public void Stop()

        { }

    }


    class B

    {

        public B(IEventsSource source)

        {

            source.Event += EventHandler;


            Console.WriteLine("constructor of B. Subscribed on event");

        }


        private void EventHandler()

        {

            Console.WriteLine("event is handled");

        }

    }


    class Installer : IWindsorInstaller

    {

        public void Install(IWindsorContainer container, 
IConfigurationStore store)

        {

            container.Register(Component.For<B>().Start());

            
container.Register(Component.For<IEventsSource>().ImplementedBy<A>());

        }

    }


    static class Program

    {

         static void Main()

         {

            var container = new WindsorContainer();


            container.AddFacility<StartableFacility>(f => 
f.DeferredStart());

            container.Install(new Installer());

         }

    }

I expected to get:

*Constructor A*

*constructor of B. Subscribed on event*

*Fire event*

*event is handled*


 But instead get:

*Constructor A*

*Fire event*

*constructor of B. Subscribed on event*


 Why I'm wrong?

Is there a mistake in my reasoning or is there a mistake in 
StartableFacility?

-- 
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/castle-project-users.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to