On Thursday, 24 December 2020 at 10:33:00 UTC, Dmitriy Asondo
wrote:
The idea is to store somewhere services (classes) first and
only when the app need - instantiate services for
app/thread/http-request (as option) and provide values to
constructors via DI
There's `Object.factory`, which constructs a class instance from
a fully-qualified name:
https://dlang.org/phobos/object.html#.Object.factory
But IIRC there are issues with it in some cases and I believe
it's supposed to be deprecated at some point.
I'd just give the classes an interface and use function pointers
to construct them:
```
interface IService { ... }
alias ServiceMaker = IService function();
ServiceMaker[string] serviceRegistry;
class FooService : IService { ... }
IService makeFooService() { return new FooService(); }
void registerServices() {
serviceRegistry["FooService"] = &makeFooService;
}
```