Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide Mixins #38

Open
aesteve opened this issue Jun 30, 2015 · 0 comments
Open

Provide Mixins #38

aesteve opened this issue Jun 30, 2015 · 0 comments
Assignees
Milestone

Comments

@aesteve
Copy link
Owner

aesteve commented Jun 30, 2015

Allow users to compose their controllers with mixins so that they can reuse logic.

For example, they could declare a LoggingMixin this way :

@Mixin("log")
public class LogMixin {
    @Before
    public void timeBefore(RoutingContext context) {
        context.put("timeBefore", System.currentTimeMillis());
        context.next();
    }

    @After
    public void logAfter(RoutingContext context) {
        long timeAfter = System.currentTimeMillis();
        long timeBefore = Long.valueOf(context.get("timeBefore"));
        logger.info("time for request #0", timeAfter - timeBefore);
        context.next();
    }
}

Then in MyApiController :

@Controller("my/api")
@Includes("log")
public class MyApiController {
    @GET
    public void myApi(RoutingContext context, Payload<String> payload) {
         payload.set("Hello");
         context.next();
    }
}
@aesteve aesteve self-assigned this Jun 30, 2015
@aesteve aesteve added this to the 0.2 milestone Jun 30, 2015
@aesteve aesteve modified the milestones: 0.2, 2.0 Dec 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant