Suppose I've two settings (for sake of simplicity) that alters behaviour of my types in a reusable library.
I can define a configuration class:
class Config {
public bool Behaviour1 { get; set; }
public bool Behaviour2 { get; set; }
}
Than if I do such thing I must propagate the instance from the composition root (no matter if handled with IoC) to the whole hierarchy.
The code will be invaded by an horde of conditional statements, reducing readability, maintainability and extensibility.
Would not be better to define two behavioural types?
public class Behaviour1 : IBehaviour1 {}
public class Behaviour2 : IBehaviour2 {}
Remove global dependency the other types have from Config
. Than each class that need a behaviour will depends on IBehaviourX
and its factory will inject a proper concrete on the basis of Config
type.
In this way only few top level types will depends on Config and behaviour of assigning behaviour (pardon the pun) will not propagate to the whole hierarchy.
I'm interested on your solutions in such case.