Hello everyone.

I'm trying to create a Singleton to be used by Guice, and still remain to 
be used as classical Singleton (it's a new jar for a bigger project, and we 
currently don't support DI, but we will in the future).
So i have a Interface like
@ImplementedBy(MyClassImpl.class)
public interface IMyClass {
    boolean returnTrue();
}
I now have the implementation with a private constructor:
@Singleton
public class MyClassImpl implements IMyClass {
    private MyClassImpl() {}
    @Provides
    @Singleton
    public static MyClassImpl getInstance() {
        if (instance == null) {
            instance = new PermissionDecisionMakerImpl();
        }
        return instance;
    }
    @Override
    boolean returnTrue() {
        return true;
    }
}
As you see, i already tried with the Annotations to have the Singleton to 
be automaticly found by the Injector.
When i do:
(Guice.createInjector().getInstance(IMyClass.class)
i get the Exception:
Could not find a suitable constructor in MyClassImpl. Classes must have 
either one (and only one) constructor annotated with @Inject or a 
zero-argument constructor that is not private.
  at MyClassImpl.class(MyClassImpl.java:??)
  while locating IMyClass

What do i do wrong?
I know, i can use toInstance within the Module, but i wanted just to use 
Annotations. Is there a way to get this running?

Regards,
-Rainer

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-guice/-/HUZLwjwMyLAJ.
To post to this group, send email to google-guice@googlegroups.com.
To unsubscribe from this group, send email to 
google-guice+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en.

Reply via email to