Hi,

one of my modules contains the following code: The Provuder works by 
calling Class.newInstance(), which is generallly fine. Except that it 
ignores @Inject constructors.

Are there any possibilities to change that?

Thanks,

Jochen

P.S: And, btw: Is the "synchronized" on get really needed?



    private void bind(Binder pBinder, Class<?> pInterface, final 
Class<?>pImplementation, String pName) {
        final Class<Object> type;
        if (pInterface == null) {
            type = Generics.cast(pImplementation);
        } else {
            type = Generics.cast(pInterface);
        }
        final Key<Object> key;
        if (Strings.isEmpty(pName)) {
            key = Key.get(type);
        } else {
            key = Key.get(type, Names.named(pName));
        }
        final Provider<Object> provider = new Provider<Object>() {
            private Object instance;

            @Override
            public synchronized Object get() {
                if (instance == null) {
                    try {
                        instance = pImplementation.newInstance();
                    } catch (Throwable t) {
                        throw Exceptions.show(t);
                    }
                }
                return instance;
            }
        };
        pBinder.bind(key).toProvider(provider).in(Scopes.SINGLETON);
    }

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/d/optout.

Reply via email to