Search code examples
castle-windsorioc-container

Check If Castle.Windsor.IWindsorContainer can Resolve


Is there a way in Castle Windsor to see if the IContainer can resolve All Instances.

I have a class in my Nunit Test DLL. What I would like to do is test to see if the IWindsorContainer can resolve all Registered Installers.

if not then the Test case for the resolver should fail.

the class I have at the moment is

    using Castle.MicroKernel.Registration;
    using Castle.Windsor;
    using NUnit.Framework;
    using System;

    namespace UnitTest
    {
        public class IOCBaseTest<T> : IDisposable
        {
            protected IWindsorContainer _container;

            public IOCBaseTest()
            {
                _container = new WindsorContainer();

                _container.Register(Classes.FromAssemblyNamed("IOC").InNamespace("IOC.Installers.Business", false));
                _container.Register(Classes.FromAssemblyNamed("UnitTest.Moq"));
            }

            [TestCase]
            public void TestWetherIOCContainerIsCorrectlySetup()
            {
var _handler = _container.Kernel.GetHandler(typeof(T)).CurrentState;

            Assert.AreEqual(_handler, Castle.MicroKernel.HandlerState.Valid);
            }
            [TestFixtureSetUp()]
            public abstract void SetupTests();

            public void Dispose()
            {
                _container.Dispose();
            }
        }
    }

I know that when I debug the IWindsorContainer I can see if there is potentially misconfigured resolvers. But how do I access this? or is there a way to test if the _container has any issues.

Edit: I Think I may have found the Issue, but need to test more... Thanks


Solution

  • Yup. Windsor has diagnostics subsystem for this very purpose. The documentation has all the details.

    Also, I'd recommend encapsulating your registration code in installers.