Maybe I'm going about this wrong and shouldn't be using custom scopes in 
the first place. 

Here is what I really need to do:

When handling user web requests, the ApplicationConfiguration needs to be 
looked up (it's stored in servlet context; there are many there, and the 
correct one needs to be picked) and injected.  That's why I use this 
binding:

bind(ApplicationConfiguration.class).toProvider(ApplicationConfigurationProvider.class).in(RequestScoped.class);

However, in a non user-request environment, I already have the instance of 
the ApplicationConfiguration that needs to be used.  How do I tell the 
injector to use that instance, instead of using the 
ApplicationConfigurationProvider?  I was thinking that I could tell Guice 
to use one Provider for one scope and something else for another scope, but 
that's apparently not how scopes work.

How can I accomplish this?


On Wednesday, February 12, 2014 11:37:42 AM UTC-6, Ryan Asleson wrote:
>
>
> I got a little further.  Now within my custom scope, I'm seeding both the 
> ApplicationConfiguration and the EntityManager:
>
>       scope.enter();
>       try
>       {
>         scope.seed(Key.get(ApplicationConfiguration.class), appConfig);
>         
>         EntityManagerFactory emf = 
> injector.getInstance(Key.get(EntityManagerFactory.class, 
> Names.named(appConfig.getAppCode())));
>         EntityManager em = emf.createEntityManager();
>         
>         scope.seed(Key.get(EntityManager.class), em);
>
>         //UserDao is bound with no scope, but to a provider....
>        UserDao userDao = injector.getInstance(UserDao.class);
>       }
>       finally
>       {
>         scope.exit();
>       }
>
> See the above.  UserDao is bound to a Provider that depends on the 
> Injector and ApplicationConfiguration being injected into it.  I'm 
> getting into UserDaoProvider, and the injector has been set, but the 
> ApplicationConfiguration on which it depends is null.
>
> Since I seeded an implementation of ApplicationConfiguration, shouldn't 
> that be injected into the UserDaoProvider?
>
>
>
>
>  
>

-- 
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/groups/opt_out.

Reply via email to