Closed teunmooij closed 2 years ago
Hi @teunmooij,
Thanks for the issue and PR. I'd like to make sure I understand the goal of this feature before accepting. It seems like the idea is provide generic system patterns, or strategies. For example you could have a generic "web-application" system, which expected a configuration, a web server, and database components. However, to support web applications that do not require a database because all data is managed by a RESTful service, you would like the ability to make the database component optional.
Is this the sort of think you are trying to solve?
Hi @cressie176,
Yes, that's the basic idea. Actually the example I gave in the issue description is not just a random example. That's my actual usecase. I'd like to create an express sub-system with some default configuration, middleware and admin-routes. Some of my services in which I'd like to use this subsystem have additional routes, but some other don't. In the ones that do, i want to register some middleware AFTER my routes get registered.
Hi @teunmooij,
That makes sense. Thank you for your PR.
Thanks for reviewing
Published as systemic@v4.1.0
I'd like to be able to set an optional dependency on a component.
Use case: A library defining a subsystem that can be included in multiple services that might or might not have a certain component. The susbsytem in the library can contain a componentan that has optional dependency on a component in the service. If it exists it will be injected.
Example
In this exmplate the
routes
will be added before themiddleware
, but if the system doesn't containroutes
, an error is thrown when starting the system because of the missing dependency. This could be solved by making theroutes
dependency optional.I'll include a PR with an implementation of this proposed change.