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

Add possibility to use a singleton Controller #350

Merged
merged 1 commit into from
Feb 13, 2017
Merged

Conversation

decebals
Copy link
Member

@decebals decebals commented Feb 7, 2017

This PR offers you the possibility to specify a Controller instance for all requests (singleton).

addControllers(ContactsController.class); // one instance for EACH request
// or
addControllers(new ContactsController()); // one instance for ALL requests

See #324 for details.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.02%) to 18.994% when pulling e9d6db0 on singleton_controller into 84ea840 on master.

@decebals decebals changed the title Add possibility to use a singleton Controller (one instance for all requests) Add possibility to use a singleton Controller Feb 8, 2017
@decebals
Copy link
Member Author

decebals commented Feb 8, 2017

The Controller class plays only a decorative role, it contains only helper methods:

public class Controller {

    public final RouteContext getRouteContext() {
        return RouteDispatcher.getRouteContext();
    }

    public final Request getRequest() {
        return getRouteContext().getRequest();
    }

    public final Response getResponse() {
        return getRouteContext().getResponse();
    }

    @SuppressWarnings("unchecked")
    public <T extends ControllerApplication> T getApplication() {
        return (T) getRouteContext().getApplication();
    }

}

In theory, in the future, we can remove the actual constrain that a controller must extends the Controller class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants