How can I check the configuration of Windsor Castle

I want to claim that my registrations are valid, i.e. there is no dependency, and no circular dependencies.
I would like to do this in my application (and not in the unit test) so that I can work quickly if the configuration is invalid.
I also want to achieve this by not allowing (and not instantiating) all components - only by scanning the dependency graph.
Any idea on how I can do this?

Motivation is the trial and error nature of customizing complex applications. I would rather get fault tolerance in the case of a poorly configured container.

BTW - my inspiration came from the AutoMapper AssertConfigurationIsValid () method.

+4
source share
1 answer

You cannot be 100% sure that Windsor is a dynamic organism, and not everything can be subjected to static analysis. All handlers can be in the WaitingDependency state, but your application can work 100%, because during resolving the dependencies DynamicParameters , ISubDependencyResolver or ILazyComponentLoader s will be provided.

There were plans to include this functionality, which you mentioned in Windsor, but with the above limitations, it rarely provided any value.

I suggest having good, reliable, verifiable conventions that decide what goes into the container and what doesn't, and good unit tests that verify the container by resolving the components.

If you don't mind false negatives, you can do the following:

 var allHandlers = container.Kernel.GetAssignableHandlers(typeof(object)); 

and then iterate over them and check if they are all Valid , but I would prefer to conduct a special test. Look at this post, for example .

Application configuration should not be trial and error, and should not be. This is a matter of good conventions and their affection. I have two posts about this that may come in handy:

+5
source

Source: https://habr.com/ru/post/1308277/


All Articles