Open lmorchard opened 1 month ago
Topological sorting? https://en.wikipedia.org/wiki/Topological_sorting
Another wrinkle: I've been specifying dependencies in app modules with Typescript interfaces. To discover dependencies at runtime would probably require explicit base class inheritance so that instanceof
would work? 🤔
Maybe a dumb idea, as I keep code golfing and fussing with the general app architecture:
Currently I instantiate AppModules as properties of an App. In the constructor, I explicitly push them into a list of modules. However, this list of modules could be auto-discovered thusly:
Object.values(app).filter(v => v instanceof AppModule);
So, the App could discover all its own modules, thereby further simplifying the declaration of an app assembly.
What's missing from this notion, though, is an order of initialization. AppModules have dependencies - e.g. most things need config & logging, some things need a repository, some things need other sibling modules.
So, I think the second part of this would be to allow AppModules to specify their dependencies and sort the list of discovered modules in order of dependency needs.