akhundMurad / diator

Diator is a Python library for implementing CQRS pattern in your Python applications.
https://akhundmurad.github.io/diator/
MIT License
61 stars 6 forks source link

Make handler call nested in middlewares stack #6

Closed SamWarden closed 1 year ago

SamWarden commented 1 year ago

Current process_request and process_response methods don't allow to wrap a handler call using with or try-except blocks. It would be more convenient to have a middlewares as in popular frameworks which calls each other and the handler at the end

References

Aiohttp

Docs

@middleware
async def middleware(request, handler):

Aiogram 3.x

Docs Source code

class Middleware(BaseMiddleware):
    async def __call__(
        self,
        handler: Callable[[Message, Dict[str, Any]], Awaitable[Any]],
        event: Message,
        data: Dict[str, Any]
    ) -> Any:

FastAPI

Docs

@app.middleware("http")
async def middleware(request: Request, call_next):

Blacksheep

Docs

class Middleware:
    async def __call__(self, request, handler):
akhundMurad commented 1 year ago

Hello @SamWarden, thank you for your contribution. Today I created a pull request related to this issue. What do you think about implementation?