What if the provided type is supposed to be thread-local scoped?
It seems to me that the provider will be providing you with unscoped
objects, no?
For more information:
http://code.google.com/p/google-guice/wiki/InjectingProviders
Nevermind, I realized that the provider is scoped. Doh.
I created an EntityManagerProvider<EntityManager> to create an
EntityManager on demand for my application. Now I would like to write some
tests and I`m planing to define a test database. But my
EntityManagerProvider<EntityManager> generates an EntityManager that uses
my dev base, not the test one. How can I use an EntityManagerProvider to
inject my test database during the tests?
This is a nitpick and unrelated to the scoping example, but I think you
would want to rewrite the `logConnection` method as follows:
{{{public void logConnectException(UnreachableException e) {
int failCt = failureCount.incrementAndGet();
User user = userProvider.get();
System.out.println("Connection failed for " + user + ": " +
e.getMessage());
System.out.println("Failure count: " + failCt);
This is a nitpick and unrelated to the scoping example, but I think you
would want to rewrite the `logConnectionException` method in that example
as follows to avoid incrementing the counter twice:
This is a nitpick and unrelated to point of the scoping example, but I
think you would want to rewrite the `logConnectionException` method in that
example as follows to avoid incrementing the counter twice:
{{{
public void logConnectException(UnreachableException e) {
User user = userProvider.get();
System.out.println("Connection failed for " + user + ": " +
e.getMessage());
System.out.println("Failure count: " + failureCount.incrementAndGet());