From 0f3e788fedf2ac1b972cca6fd7d2c3042b400c41 Mon Sep 17 00:00:00 2001 From: Decebal Suiu Date: Wed, 1 Dec 2021 18:58:15 +0200 Subject: [PATCH] Add protected constructor in Route that facilitates the injection of dependencies --- .../main/java/ro/pippo/core/route/Route.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/pippo-core/src/main/java/ro/pippo/core/route/Route.java b/pippo-core/src/main/java/ro/pippo/core/route/Route.java index 089cfdac..ecc1318a 100644 --- a/pippo-core/src/main/java/ro/pippo/core/route/Route.java +++ b/pippo-core/src/main/java/ro/pippo/core/route/Route.java @@ -37,6 +37,30 @@ public class Route { private Map attributes; + /** + * Used in subclasses (facilitates the injection of dependencies). + *
{@code
+     * @Component
+     * public class LogRoute extends Route implements RouteHandler {
+     *
+     *     public LogRoute() {
+     *         super(HttpConstants.Method.GET, "/log");
+     *
+     *         setRouteHandler(this);
+     *     }
+     *
+     *     @Override
+     *     public void handle(RouteContext routeContext) {
+     *         // do something
+     *     }
+     *
+     * }
+     * }
+ */ + protected Route(String requestMethod, String uriPattern) { + this(requestMethod, uriPattern, routeContext -> {}); + } + public Route(String requestMethod, String uriPattern, RouteHandler routeHandler) { this.requestMethod = requestMethod; this.uriPattern = uriPattern;