google-code-export / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
2 stars 1 forks source link

com.google.inject.util.Providers.of() does not inject dependencies into it's instance #212

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Not very important, but one pitfall less for developers:

It would be nice, if the above mentioned Provider factory method for single
instances would inject dependencies via Injector.injectMembers() e.g. to
it's instance. Because the returned provider is subject to DI, I was
expecting this applies to the given instance too.

public final class Providers
{
    public static <T> Provider<T> of(final T instance)
    {
        return new Provider<T>()
        {
            public T get()
            {
                return instance;
            }

            @Inject
            void injectMembers(Injector injector)
            {
                injector.injectMembers(instance);
            }
        };
    }

    private Providers()
    {
    }
}

Original issue reported on code.google.com by sven.lin...@gmail.com on 23 Jun 2008 at 10:20

GoogleCodeExporter commented 9 years ago
I don't suspect this is very useful, since in this situation the user should 
bind toInstance() rather than 
toProvider().

Original comment by limpbizkit on 2 Nov 2008 at 9:09

GoogleCodeExporter commented 9 years ago

Original comment by limpbizkit on 31 Dec 2008 at 12:24