Skip to content

Dependency injection for lifespan - #37

Merged
ManiMozaffar merged 3 commits into
ManiMozaffar:mainfrom
amirsoroush:dependency_injection_for_lifespan
Sep 13, 2026
Merged

ManiMozaffar merged 3 commits into
ManiMozaffar:mainfrom
amirsoroush:dependency_injection_for_lifespan

Conversation

@amirsoroush

Copy link
Copy Markdown
Contributor

As the docs currently suggests that the users should use lifespan instead of OnStartUp and OnShutDown events, we should also let them define their dependencies through the lifespan.

The OnStartUp and OnShutDown events are triggers, so the @app.task() would do the injection correctly:

func=inject(wrapped_function, dependency_overrides_provider=get_provider()),

But, lifespan doesn't:

ctx = self.lifespan(self)

While fixing the issue, I noticed that there is another issue regarding different versions of FastDepends. In v2, the parameter name was "dependeny_overrides_provider" and in v3 it changes to "dependeny_provider": Lancetnik/FastDepends@4beac5f

we have defined "fast-depends>=2.4.0" in the pyproject.toml so we should also consider this. I wrote a helper function for that which inspects the inject() functions parameter.

@ManiMozaffar
ManiMozaffar merged commit a4abbc8 into ManiMozaffar:main Sep 13, 2026
3 checks passed
@amirsoroush
amirsoroush deleted the dependency_injection_for_lifespan branch September 13, 2026 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants