Implement instantiated services option. Resolve #119 #126
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change is a: (check at least one)
Is this a breaking change? (check one)
Is the:
What does this change address?
Resolve #119. While I think the singleton pattern should be deprecated, put under a feature flag, and discouraged, the first step is probably to give instantiated services some field experience as an optional feature.
How does this change work?
This introduces an option to enable instantiated services while maintaining backwards compatibility with the singleton pattern. See the section I added to the docs and the examples I added to https://github.com/ryneeverett/quasi-apiron starting in
apiron_instantiated_example_*.py
, which are adaptions of my previous examples which work with this branch.The implementation works in a backwards compatible way by using meta-programming to store and return a single instance of each service class when instantiated services are not enabled. This enables the rest of the code base to work with services as instantiated classes, regardless of whether this feature is enabled.
Additional context
ServiceBase.get_hosts
(and my deletion ofTestServiceBase.test_get_hosts_returns_empty_list_by_default
). I don't really understand the service discovery feature which I believe is the main point of that method so I'm liable to have broken something.