Description
Hi 👋 ,
We are using this awesome tool with many Azure services. One that does not cooperate nicely with DI is Azure Functions.
I'm hoping I'll get some light shed on why they don't cooperate.
Azure Functions is a docker container with a bunch of modules, those modules are instances of Azure Functions, as AWS Lambdas. The code is placed usually in __init__.py
Below is a simple example of how this may look like.
.
├── Dockerfile
├── dependencies.py
├── maintenance_break_cron
│ ├── __init__.py
│ └── function.json
├── promotions_consumer
│ ├── __init__.py
│ ├── function.json
│ └── utils.py
In the dependencies.py
is our container
class Container(containers.DeclarativeContainer):
wiring_config = containers.WiringConfiguration(
modules=[
"promotions_consumer"
]
feature_flag_service = providers.Factory(
FeatureFlagService, provider=feature_flag_provider
)
metrics = providers.Singleton(Metrics)
The wiring does not work if the @inject/Provide
pair is placed in __init__.py
but it does work in utils.py
. Our workaround at this point is move the code with DI into submodule (like utils.py
). Another one is to access dependencies in this way
container = Container()
metrics = container.metrics()
I'm wondering what is the issue in our case? Is our wiring not right?
Any help would be greatly appreciated.