How to bind an enum in GIN

342 views
Skip to first unread message

bzie...@washtec.de

unread,
Jun 19, 2013, 4:15:53 AM6/19/13
to gwt-pl...@googlegroups.com

Hello folks,

I'm trying to put a enumeration into the ginjector with these lines of code:

ClientGinjector.java

MyEnum getMyEnum();

ClientModule.java

bind(MyEnum.class).in(Singleton.class);

But when I'm trying to compile I get the following error:

[ERROR] Error injecting bla.blup.MyEnum: Unable to create or inherit binding: Binding requested for constant key 'bla.blup.MyEnum' but no explicit binding was found

Can anyone please help me?


Regards

Gerardo Cortés Oquendo

unread,
Jun 19, 2013, 11:07:28 AM6/19/13
to gwt-pl...@googlegroups.com
But an enum is a static class if you declare it you already have it.
maybe you want to do one of this two

Inject an enum option using annotations
bindConstant().annotatedWith(MyOption1.class).to(MyEnum.OP1);

@Inject
public void Clazz(final @
MyOption1 MyEnum myEnum)

or inject an enum to an interface because you have more than one enum

bind(MyInterface.class).to(MyEnum.class);

the singleton part don't have sence, an enum is singleton by definition.
if you don't need any of these options, then just use the enum, don't injected
Reply all
Reply to author
Forward
0 new messages