Add automatic imports of controllers and routes #334
Labels
enhancement
New feature or request
fixed in branch
Already fixed in a branch, waiting to be merged
needs docs
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: