Neoteroi / BlackSheep

Fast ASGI web framework for Python
https://www.neoteroi.dev/blacksheep/
MIT License
1.86k stars 78 forks source link

Take action when the default router is populated and orphan #470

Closed RobertoPrevato closed 8 months ago

RobertoPrevato commented 8 months ago

🚀 Feature Request Version 2 exposes a default singleton router to support defining routes with methods imported from BlackSheep. This can be a footgun for users who configure a custom router but still use the methods imported from BlackSheep to register routes. Take action when the default router is populated and orphan,

Example:

from blacksheep import Application, Router, get

router = Router()

app = Application(router=router)

@get("/")  # ERROR!!!
def home():
    return "Hello, World!"

The error above consists in using the routing methods belonging to the default singleton router when it is not associated to the application object.