Allow dependency injection on the PackageManager
We want to allow one to provide their own PackageManager instance. There are 3 standard ways of doing this: 1) Provide an instance in the constructor; 2) Provide a template parameter; 3) Use a hook that is called by the constructor; We are going with option 3 as the other two methods have clear downsides: Option 1 exposes too much of the implementation detail (even if it can be wrapped by another constructor) and makes the dependency to internal state hard / impossible (we need to instantiate SpecialDirs then load the config that may modify SpecialDirs). Option 2 is even worse as it exposes implementation details to the type and makes OOP impossible (e.g. method accepting a `PackageManager` need to be changed). Option 3 is the best compromise, as its main downside is that it requires to create a new `Dub` type, however that is already required due to the amount of configuration points that do IO (loadConfig, determineDefaultCompiler, computePkgSuppliers). |
---|
|
source/dub/dub.d |
---|