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

Demonstrate guice injection into methods #1

Open
jonas-l opened this issue Sep 8, 2010 · 1 comment
Open

Demonstrate guice injection into methods #1

jonas-l opened this issue Sep 8, 2010 · 1 comment

Comments

@jonas-l
Copy link

jonas-l commented Sep 8, 2010

It would be great if this sample application could demonstrate argument injection using guice binding annotations.

I'm talking about method arguments like (where ResultsPerPage is custom binding annotation):

public List<Result> getResults(@Inject @ResultsPerPage byte resultsPerPage) {...}

With existing application configuration it's only possible to use binding annotations to inject fields. Or did I miss something?

Thanks

@christophercurrie
Copy link

Can you elaborate on the use case you're going for? From the code example, it appears that you want the resultsPerPage variable to be bound to some value that you've configured in a Guice module somewhere, as opposed to being provided by the client of a web-service. (If I have this part wrong, please clarify.)

If I'm on the right track, and you dislike field injection, the typical way Jersey does this is with constructor injection:

@Path('/results')
public class ResultsResource {
    private final byte _resultsPerPage;

    @Inject
    public ResultsResource( @ResultsPerPage byte resultsPerPage ) {
        _resultsPerPage = resultsPerPage;
    }

    // ... methods to follow ...
}

Will this meet the need, or is there a different twist you're going for?

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

No branches or pull requests

2 participants