If the class instantiates its own dependencies then, by definition, you're not injecting those dependencies, so you're not doing dependency injection at all!
class Foo {
private nowFn: () => Date;
constructor(nowFn: () => Date) {
this.nowFn = nowFn;
}
doSomething() {
console.log(this.nowFn());
}
static create(opts: { nowFn?: () => Date } = {}) {
return new Foo(opts.nowFn ?? (() => new Date()));
}
}Dependency injection boils down the question of whether or not you can dynamically change a dependency at runtime.