Skip to content

Commit c588127

Browse files
committed
easier middleware installation
1 parent 3f26f58 commit c588127

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,18 @@ async def lifespan(app: FastAPI) -> AsyncGenerator[None, Any]:
126126
For a contextual session to work, a context needs to be set. This assumes some
127127
kind of middleware.
128128

129+
130+
You can use ready-made FastAPI middleware:
131+
```python
132+
from fastapi import FastAPI
133+
from context_async_sqlalchemy import add_fastapi_db_session_middleware
134+
135+
app = FastAPI()
136+
137+
add_fastapi_db_session_middleware(app)
138+
```
139+
140+
129141
I'll use FastAPI middleware as an example:
130142
```python
131143
from fastapi import Request
@@ -177,17 +189,6 @@ async def fastapi_db_session_middleware(
177189
```
178190

179191

180-
You can use ready-made FastAPI middleware:
181-
```python
182-
from fastapi import FastAPI
183-
from context_async_sqlalchemy import add_fastapi_db_session_middleware
184-
185-
app = FastAPI()
186-
187-
add_fastapi_db_session_middleware(app)
188-
```
189-
190-
191192
#### 4. Write a function that will work with the session
192193

193194
```python

0 commit comments

Comments
 (0)