How can I override a component registered in Castle Windsor?

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

In my prod code, I want to be able to register a component that implements the base class, and use the container to resolve the implementation. Still use

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

and

container.Resolve<LoggerBase>();

In my tests, I would like to add a stub / mock implementation to override the "DebugLogger" implementation, so that when my prod code calls container.Resolve<LoggerBase>();, it gets an overridden implementation.

Any pointers are welcome!

+3
1

, , . -. DI.

DI .

+3

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


All Articles