You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: as added to make linters happy and remove unused imports lints.
from . importcontrollers# NoQA
...
This has downsides:
it makes for a poor development experience
imports look unused even if they are used, making linters unhappy
increases code verbosity adding little value
In this case, adopting convention over configuration can help improving the situation:
all modules inside a controllers package under the same namespace where the Application class is instantiated might be automatically imported
It would be nice to support the same for regular routes defined using request handlers. But to achieve this, it is also necessary to support importing get, post, put, etc. methods to register request handlers in a similar fashion as already supported for controllers.
Therefore the blacksheep.server.routing module should export a default router that is used by default, when no router is explicitly configured for the application.
In the final form, routes would also be automatically imported:
* Apply minor corrections to GzipMiddleware
* Fix ensure_response type annotation
* Add features to describe app environment
* Rename gzip.py to compression.py
* Add auto-import of controllers and routes #334
* Update CHANGELOG.md
* Adopt pyproject.toml
Explicit is better than implicit. However, having to import controllers and routes explicitly is boring and annoying!
Consider the following example:
The user currently needs to import
Controller
types defined in each module inside thecontrollers
package explicitly.Example:
Note:
as
added to make linters happy and remove unused imports lints.This has downsides:
In this case, adopting convention over configuration can help improving the situation:
controllers
package under the same namespace where theApplication
class is instantiated might be automatically importedIt would be nice to support the same for regular routes defined using request handlers. But to achieve this, it is also necessary to support importing
get
,post
,put
, etc. methods to register request handlers in a similar fashion as already supported for controllers.Therefore the
blacksheep.server.routing
module should export a default router that is used by default, when no router is explicitly configured for the application.In the final form, routes would also be automatically imported:
In such scenario, routes would be automatically imported when instantiating an
Application
class that uses the default router.Users who want to maintain things explicit has still the option of doing so:
Application
instance to use a specificRouter
The text was updated successfully, but these errors were encountered: