开发者

How can I override a component registered in Castle Windsor?

I'm just starting with Windsor, so please be gentle :) I have a scenario where I want to be able to override/replace components placed inside a windsor container. Read on ...

In my prod code, I want to be able to register a component which implements a base class, and use a container to resolve the implementer. So far, using

container.Register(Component.For<LoggerBase>().ImplementedBy<DebugLogger>());

and

container.Resolve<LoggerBase>();

In my tests, I'd like to add a stub/mock implementation to override the "DebugLogger" implementation so开发者_开发百科 that when my prod code calls container.Resolve<LoggerBase>(); it gets the overridden implementation.

Any pointers would be welcome!


Instead of chasing down that path, you should rather use different container instances for different scenarios. Each instance could be configured differently. That's the whole point of a DI Container.

However, in general DI Containers should not be used for unit testing.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜