Registering Classes Instead of Instances

Ah thanks I see the misunderstanding now too. I don’t recommend registering class constants when they are also used to create instances, because that’s the type of inconsistency that we’re trying to avoid when using dry-system. Relying on instances exclusively works much better.

Ah gotcha, yes so to clarify - when you use Zeitwerk and refer to class constants explicitly and bypass the DI provided by dry-system then you’re going to introduce tight coupling between your code and class constants. When you use Zeitwerk setup via dry-system just to have it auto-load constants (which of course also means having it load files too) but you still use DI and don’t refer to class constants explicitly, then there’s no such coupling.

1 Like