lmorchard / pebbling-club

🐧🪨
3 stars 0 forks source link

Let App auto-discover its AppModules for init / deinit #113

Open lmorchard opened 1 month ago

lmorchard commented 1 month ago

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.

lmorchard commented 1 month ago

Topological sorting? https://en.wikipedia.org/wiki/Topological_sorting

lmorchard commented 1 month ago

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? 🤔