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

Binding Providers of parameterised types #60

Open
gravelld opened this issue Jan 11, 2017 · 2 comments
Open

Binding Providers of parameterised types #60

gravelld opened this issue Jan 11, 2017 · 2 comments
Assignees

Comments

@gravelld
Copy link

Consider:

private class AnOptionProvider @Inject()(s:String) extends Provider[Option[String]] {
  def get = Option(s)
}

I can do:

bind(new TypeLiteral[Option[String]]() {}).toProvider(classOf[AnOptionProvider])

But I can't do:

bind(new TypeLiteral[Option[String]]() {}).toProvider[AnOptionProvider]

Which is slightly more elegant.

I get the feeling I'm missing something from the README when it says:

bind[A].toProvider[BProvider]
bind[A].toProvider[TypeProvider[B]]

Assuming this solved it, could that example be fleshed out?

@tsuckow tsuckow self-assigned this Jan 13, 2017
@tsuckow
Copy link
Member

tsuckow commented Jan 13, 2017

The issue is that bind(new TypeLiteral[Option[String]]() {}) is invoking the guice native method and thus not returning the scala wrapped builders that support the .toProvider[AnOptionProvider] syntax.

This does work:

 bind[Option[String]].toProvider[AnOptionProvider]

I'm looking into what it would take to override the methods and return the Scala versions.

@tsuckow
Copy link
Member

tsuckow commented Jan 13, 2017

This is an issue I have tried to resolve before, unfortunately at every turn I end up with an ambiguous method error.

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