views:

81

answers:

1

Hi,
I want to assert that my registrations are valid, i.e no dependency is missing and there are no circular dependencies.
I'd like to do that in my application (and not in a unit-test) so I'd be able to fail-fast if the configuration is invalid.
I also want to accomplish that without resolving (and instantiating) all the components - only by scanning the dependency graph.
Any idea on how I can do that?

The motivation is the trial-and-error nature of configuring complex applications. I'd prefer to get a fail-fast behavior in case of a badly configured container.

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

+3  A: 

You can't be 100% sure as Windsor is a dynamic organism and not everything can be statically analyzed. All handlers may be in WaitingDependency state yet your app may be 100% working since at resolution time the dependencies will be provided by DynamicParameters, ISubDependencyResolvers or ILazyComponentLoaders.

There were plans to include this functionality you've mentioned into Windsor, but given above constraints, it would rarely provide any value.

I would suggest having good, solid verifiable conventions that decide what goes into the container and what not, and good unit tests that test the container by resolving the components.

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

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

and then iterate over them and check if they all are Valid, but I'd rather have a dedicated test for that. Take a look at this post for example.

Configuring the application does not have to be trial and error, nor should it be. It's a matter of good conventions, and sticking to them. I have two posts about it you may find useful:

Krzysztof Koźmic
The motivation of course is the trial-and-error nature of configuring complex applications. I'd prefer to get a fail-fast behavior in case of a badly configured container. Perhaps you could supply a tristate verification method that will return valid, invalid or inconclusive result? I rarely use the dynamic features of Windsor, and I believe most of the times my wrong configuration can be caught early.
Omer Mor