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

  • Home
  • SEARCH
  • 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 3283206
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:00:51+00:00 2026-05-17T20:00:51+00:00

When attempting to register a startable component that depends on a service whose implementation

  • 0

When attempting to register a startable component that depends on a service whose implementation “decorates” the same service interface, Castle fails to resolve the startable component, claiming that the dependency cannot be resolved. Curiously enough, explicitly resolving the startable component works as expected. I have seen this behavior in both Castle Windsor 2.5 and 2.5.1. Please see the below NUnit test case:

UPDATE

I’ve discovered that I can get the startable mechanism to work, but I need to separate the registrations of the IFoo implementers into a separate container.Register() call from the registration of the startable component. The IFoo registrations must happen first. Even more interestingly, this does not work if I use an IWindsorInstaller to install the components. Please see additional test cases below:

UPDATE

Installing the IFoo implementers in a separate installer, in a separate call to container.Install() works. Installing the startable component by including its IWindsorInstaller in the params[] list to a single call to container.Install() does not work, but installing it in a separate call to container.Install() does work. I have consolidated all test cases into the below code snippet:

using System;
using Castle.Facilities.Startable;
using Castle.MicroKernel.Registration;
using Castle.MicroKernel.SubSystems.Configuration;
using Castle.Windsor;
using NUnit.Framework;

namespace Tests
{
    [TestFixture]
    public class TestProblemsWithStartableAndDecorators
    {
        /// <summary>
        /// This test passes with the following output to the console:
        /// 
        /// foo decorator
        ///     typeof decorated : Foo
        /// startable constructor
        ///     typeof foo : FooDecorator
        /// 
        /// </summary>
        [Test]
        public void TestUsingResolve()
        {
            using (var container = new WindsorContainer())
            {
                container.AddFacility<StartableFacility>(f => f.DeferredStart());
                container.Register(
                    Component.For<IFoo>().ImplementedBy<FooDecorator>(),
                    Component.For<IFoo>().ImplementedBy<Foo>(),
                    Component.For<IGetStarted>().ImplementedBy<GetStarted>()
                    );
                container.Resolve<IGetStarted>();
            }
        }

        /// <summary>
        /// This test should pass with the same output as the above test.
        /// However, it fails with the following exeption:
        /// 
        /// Castle.MicroKernel.Handlers.HandlerException : Can't create component 'Tests.TestProblemsWithStartableAndDecorators+FooDecorator' as it has dependencies to be satisfied. 
        /// Tests.TestProblemsWithStartableAndDecorators+FooDecorator is waiting for the following dependencies: 
        /// 
        /// Services: 
        /// - Tests.TestProblemsWithStartableAndDecorators+IFoo. 
        /// A dependency cannot be satisfied by itself, did you forget to add a parameter name to differentiate between the two dependencies? 
        /// 
        /// Tests.TestProblemsWithStartableAndDecorators+foo is registered and is matching the required service, but cannot be resolved.
        /// </summary>
        [Test]
        public void TestUsingStartable()
        {
            using (var container = new WindsorContainer())
            {
                container.AddFacility<StartableFacility>(f => f.DeferredStart());
                container.Register(
                    Component.For<IFoo>().ImplementedBy<FooDecorator>(),
                    Component.For<IFoo>().ImplementedBy<Foo>(),
                    Component.For<IGetStarted>().ImplementedBy<GetStarted>().Start()
                    );
            }
        }

        public interface IFoo
        {
        }

        public class Foo : IFoo
        {
        }

        public class FooDecorator : IFoo
        {
            public FooDecorator(IFoo decorated)
            {
                Console.WriteLine("foo decorator");
                Console.WriteLine("    typeof decorated : " + decorated.GetType().Name);
            }
        }

        public interface IGetStarted
        {
        }

        public class GetStarted : IGetStarted
        {
            public GetStarted(IFoo foo)
            {
                Console.WriteLine("startable constructor");
                Console.WriteLine("    typeof foo : " + foo.GetType().Name);
            }
        }

        // works
        [Test]
        public void TestUsingStartableWithSeparateRegistrations()
        {
            using (var container = new WindsorContainer())
            {
                container.AddFacility<StartableFacility>(f => f.DeferredStart());
                container.Register(Component.For<IFoo>().ImplementedBy<FooDecorator>(),
                                   Component.For<IFoo>().ImplementedBy<Foo>());
                container.Register(Component.For<IGetStarted>().ImplementedBy<GetStarted>().Start());
            }
        }

        // fails
        [Test]
        public void TestUsingStartableWithSeparateRegistrationsRegisteringStartableFirst()
        {
            using (var container = new WindsorContainer())
            {
                container.AddFacility<StartableFacility>(f => f.DeferredStart());
                container.Register(Component.For<IGetStarted>().ImplementedBy<GetStarted>().Start());
                container.Register(Component.For<IFoo>().ImplementedBy<FooDecorator>(),
                                   Component.For<IFoo>().ImplementedBy<Foo>());
            }
        }

        // fails
        [Test]
        public void TestUsingStartableWithInstaller()
        {
            using (var container = new WindsorContainer())
            {
                container.AddFacility<StartableFacility>(f => f.DeferredStart());
                container.Install(new TestInstaller());
            }
        }

        public class TestInstaller : IWindsorInstaller
        {
            public void Install(IWindsorContainer container,
                                IConfigurationStore store)
            {
                container.Register(Component.For<IFoo>().ImplementedBy<FooDecorator>(),
                                   Component.For<IFoo>().ImplementedBy<Foo>());
                container.Register(Component.For<IGetStarted>().ImplementedBy<GetStarted>().Start());
            }
        }

        // works
        [Test]
        public void TestUsingStartableWithSeparateFooInstaller()
        {
            using (var container = new WindsorContainer())
            {
                container.AddFacility<StartableFacility>(f => f.DeferredStart());
                container.Install(new FooInstaller());
                container.Register(Component.For<IGetStarted>().ImplementedBy<GetStarted>().Start());
            }
        }

        // fails
        [Test]
        public void TestUsingStartableWithSeparateInstallers()
        {
            using (var container = new WindsorContainer())
            {
                container.AddFacility<StartableFacility>(f => f.DeferredStart());
                container.Install(new FooInstaller(), new StartableInstaller());
            }
        }

        // works
        [Test]
        public void TestUsingStartableWithSeparateCallsToInstall()
        {
            using (var container = new WindsorContainer())
            {
                container.AddFacility<StartableFacility>(f => f.DeferredStart());
                container.Install(new FooInstaller());
                container.Install(new StartableInstaller());
            }
        }

        public class FooInstaller : IWindsorInstaller
        {
            public void Install(IWindsorContainer container,
                                IConfigurationStore store)
            {
                container.Register(Component.For<IFoo>().ImplementedBy<FooDecorator>(),
                                   Component.For<IFoo>().ImplementedBy<Foo>());
            }
        }

        public class StartableInstaller : IWindsorInstaller
        {
            public void Install(IWindsorContainer container,
                                IConfigurationStore store)
            {
                container.Register(Component.For<IGetStarted>().ImplementedBy<GetStarted>().Start());
            }
        }
    }
}
  • 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-17T20:00:52+00:00Added an answer on May 17, 2026 at 8:00 pm

    Fixed in HEAD. Will be part of 2.5.2 release. For future reference, here’s the bug report.

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

Sidebar

Related Questions

I am attempting to write a service, that will every X minutes attempt to
I'm attempting to create a CodeActivity object that will register a DLL on a
I am attempting to use a custom implementation of the SharedPreferences interface to persist
I am attempting to host a service that serves up basic web content (HTML,
I am attempting to register a .dll using RegAsm. It is a .NET 2.0
Simple Inject is throwing the following exception when attempting to register my DbContext. The
Attempting to set up an automated texting service for customers, where people can text
Attempting to make a NSObject called 'Person' that will hold the login details for
I've got a Windows Forms control that I'm attempting to wrap as a WPF
I'm attempting to dynamically register entities and configurations with a context (ef4 code-only) I

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.