Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Windsor verify configuration: how to resolve dependency? #1229


User avatar
0
tonid created

Hi,

I have this unit test:

public class WindsorRegistration_Tests : AppTestBase
    {
        private readonly ITestOutputHelper output;

        public WindsorRegistration_Tests(ITestOutputHelper output)
        {
            this.output = output;
        }

        [Fact]
        public void Should_Not_Have_Any_Misconfigured_Components()
        {
            // From http://blog.usermaatre.co.uk/programming/2014/11/27/testing-dependency-registrations-with-castle-windsor/
            var container = LocalIocManager.IocContainer;
            var key = SubSystemConstants.DiagnosticsKey;
            var host = (IDiagnosticsHost)container.Kernel.GetSubSystem(key);
            var diagnostic = host.GetDiagnostic<IPotentiallyMisconfiguredComponentsDiagnostic>();
            var problems = diagnostic.Inspect();

            if (problems != null && problems.Any())
            {
                var message = new StringBuilder();
                message.AppendFormat("Misconfigured components ({0})\r\n", problems.Count());

                //Iterate over the problems, writing messages to the console
                foreach (IExposeDependencyInfo problem in problems)
                {
                    var inspector = new DependencyInspector(message);
                    problem.ObtainDependencyDetails(inspector);
                }

                output.WriteLine(message.ToString());
            }

            // No misconfigured components
            problems.Count().ShouldBe(0);
        }

    }

Then I get the following output message:

'Abp.Events.Bus.Handlers.Internals.ActionEventHandler`1' is waiting for the following dependencies:
- Service 'Action`1' which was not registered.

'Abp.Localization.Sources.Resource.ResourceFileLocalizationSource' is waiting for the following dependencies:
- Parameter 'name' which was not provided. Did you forget to set the dependency?
- Service 'System.Resources.ResourceManager' which was not registered.

'Abp.Localization.Sources.Xml.XmlLocalizationSource' is waiting for the following dependencies:
- Parameter 'name' which was not provided. Did you forget to set the dependency?
- Parameter 'directoryPath' which was not provided. Did you forget to set the dependency?

'Abp.Localization.MultiTenantLocalizationDictionary' is waiting for the following dependencies:
- Parameter 'sourceName' which was not provided. Did you forget to set the dependency?
- Service 'Abp.Localization.Dictionaries.ILocalizationDictionary' which was not registered.

'Abp.Runtime.Caching.Memory.AbpMemoryCache' is waiting for the following dependencies:
- Parameter 'name' which was not provided. Did you forget to set the dependency?

So, how to resolve these dependencies? I think this test should be included in aspnetzero.


1 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Thank you for sharing this code. I even did not know Castle Windsor has such a feature.

    But, as the interface you used (IPotentiallyMisconfiguredComponentsDiagnostic) says it, that is 'potential'. But these are not problems. Because, these classes are not injected, but actually directly resolved from container (like service locator pattern). And the resolving code provides missing dependencies (like 'name') in the resolve request. Since all these are internals of the framework, you don't have to worry about it.

    Thanks, Have a nice day.