This repository was archived by the owner on Oct 1, 2022. It is now read-only.
Description Story
As a ServiceX developer I want to use dependency injection in API endpoints so I can avoid brittle code
Dependencies such as the TransformerManager, RabbitAdaptor, etc. are currently stored as class attributes on API resource classes. For example:
class SubmitTransformationRequest (ServiceXResource ):
@classmethod
def make_api (cls , rabbitmq_adaptor , object_store ,
code_gen_service , lookup_result_processor , docker_repo_adapter ):
cls .rabbitmq_adaptor = rabbitmq_adaptor
cls .object_store = object_store
cls .code_gen_service = code_gen_service
cls .lookup_result_processor = lookup_result_processor
cls .docker_repo_adapter = docker_repo_adapter
return cls
There are a few issues with this implementation:
Lots of boilerplate make_api class methods.
Web routes, which are simply functions (not classes) cannot store attributes.
Incentivizes workarounds, such as borrowing dependencies from other resource classes (as in Add transformer deployment status endpoint #90 ):
class DeploymentStatus (ServiceXResource ):
@auth_required
def get (self , request_id ):
# todo - improve dependency injection
manager : TransformerManager = TransformStart .transformer_manager
This is a good use case for the dependency injection pattern.
Acceptance Criteria
A new route / API resource can simply declare which dependencies it requires and have them provided automatically:
class SomeResource (ServiceXResource ):
def get (self , rabbitmq_adaptor ):
...
Dependencies can be swapped out or mocked in a modular fashion.
Assumptions
We can find a reliable, well-tested implementation or package for dependency injection in Flask. Candidates: Flask-Injector .
Reactions are currently unavailable
Story
As a ServiceX developer I want to use dependency injection in API endpoints so I can avoid brittle code
Dependencies such as the TransformerManager, RabbitAdaptor, etc. are currently stored as class attributes on API resource classes. For example:
There are a few issues with this implementation:
make_apiclass methods.This is a good use case for the dependency injection pattern.
Acceptance Criteria
Assumptions