The user currently needs to import Controller types defined in each module inside the controllers package explicitly.
Example:
# app/controllers/__init__.py
from .home import HomeController as HomeController
from .comments import CommentsController as CommentsController
from .favorites import FavoritesController as FavoritesController
from .reactions import ReactionsController as ReactionsController
from .reviews import ReviewsController as ReviewsController
from .topics import TopicsController as TopicsController
from .users import UsersController as UsersController
Note: as added to make linters happy and remove unused imports lints.
from . import controllers # 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:
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