-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
feat/refactor!: router-level middleware, support for lifespans on mounted apps #35
Conversation
Codecov Report
@@ Coverage Diff @@
## main #35 +/- ##
==========================================
+ Coverage 98.11% 98.18% +0.07%
==========================================
Files 172 175 +3
Lines 5412 5513 +101
Branches 624 636 +12
==========================================
+ Hits 5310 5413 +103
+ Misses 56 55 -1
+ Partials 46 45 -1
|
@sm-Fifteen I think you may be interested in this based on your comments in encode/starlette#649(comment) and tiangolo/fastapi#617 I'm not really advertising it / putting it in the docs just yet, but this change does enable lifespans for submounted apps: xpresso/tests/test_lifespans.py Lines 11 to 30 in 3b8a438
(incidentally, that example also uses dependency injection in the lifespan event, which I know is also something you were pushing for in the FastAPI issue) |
@adriangb: Ah, that's very interesting! I recall you mentionning moving your efforts of improving the FastAPI DI system to your own Now that I can see the vision realized as a competitor to FastAPI, and all the various improvements you made on it, namely:
...I can really say that such big changes would have been hard to pull off well on top of the existing FastAPI codebase. I'm definitely going to be following this closely! Also, looks like you forgot to update this part: xpresso/docs/tutorial/lifespan.md Line 4 in b2b3ac7
|
Great, thanks for the kind words! I do hope that some of this eventually makes it back to FastAPI, but like you say a lot of it would be hard / impossible to re-integrate.
Do you mean that we should call out support for lifespans on mounted apps? To be clear, we do not support ASGI lifespans on arbitrary mounted apps. We only support context manager lifespans on Xpresso apps. So you can't mount a Blacksheep (or other ASGI framework) app and have it run it's lifespans. |
Ah, right, my bad, I was skimming through the documentation and didn't realize the distinction you were trying to make. That should probably be pointed out somewhere in the "Dependency scopes" or "Lifespan" parts of the tutorial, then, since it seems like an important point to raise. |
Yup I just added that feature (in this PR) though, so I was thinking of letting it marinate a bit to see if I find any flaws in the design before really advertising it |
Closes #32
This is a middle road of where we are now and #32:
App
is not longer based onStarlette
, butRouter
still inherits from Starlette'sRouter
and adds middleware on top of it