Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inline lifespan chooser #55

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions microbootstrap/bootstrappers/fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,10 @@ async def _wrapped_lifespan_manager(self, app: fastapi.FastAPI) -> typing.AsyncI
async with self._lifespan_manager(app), self.application_config.lifespan(app):
yield {}

def _choose_lifespan_manager(
self,
) -> typing.Callable[[fastapi.FastAPI], typing.AsyncContextManager[dict[str, typing.Any]]]:
if self.application_config.lifespan:
return self._wrapped_lifespan_manager

return self._lifespan_manager

def bootstrap_before(self) -> dict[str, typing.Any]:
return {
"debug": self.settings.service_debug,
"lifespan": self._choose_lifespan_manager(),
"lifespan": self._wrapped_lifespan_manager if self.application_config.lifespan else self._lifespan_manager,
}


Expand Down
Loading