On 11.12.2013. 10:53, QAston wrote: > > This issue is probably nearly as old as programming itself. > There are several sollutions already developed: dependency injection > (requires complex configuration rules), manually passing deps as args > (cumbersome), service locator or global variables.
Yeah, and it always keeps pooping right up! > > Your sollution as far as I understand it relies on swapping a global > variable when inside a context and restoring it afterwards. While this > would be perfectly fine in environment where code is executed in OS > threads, there will be a problem in the case of Vibe.d which uses > fibers. But I guess the problem is solvable there aswell. I was thinking about such issues and think they are all solvable. I concluded that I should present this issues as simple and possible to check out the general interest first. > > Just to note - you have to bind to globals at some point - what if > someone wants to swap writeln function whith his own (for example to > call logger, or for whatever reason)? Or he may want to swap dbContext > :).In my practice I make swappable only things I think I'll need to swap > in future. Yes. Not only that swapping would need to permitted but also only same type values could be swapped. D makes sure of that.
