开发者

How can I validate the configuration of windsor castle

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 scanni开发者_如何学Gong 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.


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:

  • Build your conventions
  • Validate your conventions
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜