Re: How do I create two EntityManager binding, one without any annotation and one with annotation?

2016-06-13 Thread Stephan Classen
This is not possible. You need to define an notation for both entitymanagers.

Also have a look at onami-persist for enhanced multi pu support

Am 13. Juni 2016 12:11:42 MESZ, schrieb Kohei Nozaki :
>Hello,
>
>I want to create two EntityManager binding with guice-persist as
>follows:
>
>1. Without any annotation
>2. With an annotation (say, @SlaveDatabase)
>
>So, I have created following module:
>
>public class MyModule extends AbstractModule {
>
>@Override
>protected void configure() {
>install(new MasterPrivateModule());
>install(new SlavePrivateModule());
>}
>
>private static class MasterPrivateModule extends PrivateModule {
>@Override
>protected void configure() {
>install(new JpaPersistModule("masterPU"));
>
>expose(EntityManager.class);
>}
>}
>
>private static class SlavePrivateModule extends PrivateModule {
>@Override
>protected void configure() {
>install(new JpaPersistModule("slavePU"));
>
>final Provider entityManagerProvider = 
>binder().getProvider(EntityManager.class);
>
>bind(EntityManager.class).annotatedWith(SlaveDatabase.class).toProvider(entityManagerProvider);
>expose(EntityManager.class).annotatedWith(SlaveDatabase.class);
>}
>}
>}
>
>But it doesn't work. Guice produces following error:
>
>com.google.inject.CreationException: Unable to create injector, see the
>
>following errors:
>
>1) A binding to javax.persistence.EntityManager was already configured
>at 
>mypkg.MyModule$MasterPrivateModule.configure(MyModule.java:25) (via 
>modules: mypkg.MyModule -> mypkg.MyModule$MasterPrivateModule).
>  at 
>com.google.inject.persist.jpa.JpaPersistModule.configurePersistence(JpaPersistModule.java:69)
>
>(via modules: mypkg.MyModule -> mypkg.MyModule$SlavePrivateModule -> 
>com.google.inject.persist.jpa.JpaPersistModule)
>...
>
>How do I write a module to achieve this requirement?
>
>I have pushed a reproducer (testcase) and entire project to GitHub:
>
>* Entire project: 
>https://github.com/lbtc-xxx/guice-persist-multiple-pu/tree/simplified
>* Reproducer (testcase): 
>https://github.com/lbtc-xxx/guice-persist-multiple-pu/blob/simplified/src/test/java/mypkg/MyModuleTest.java
>
>Thanks.
>
>-- 
>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 google-guice+unsubscr...@googlegroups.com.
>To post to this group, send email to google-guice@googlegroups.com.
>Visit this group at https://groups.google.com/group/google-guice.
>To view this discussion on the web visit
>https://groups.google.com/d/msgid/google-guice/84ba2ff6-eb3e-42c0-96d1-b48e8075659e%40googlegroups.com.
>For more options, visit https://groups.google.com/d/optout.

-- 
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/EE708736-9BF3-4A7C-AFDA-853FA30726A3%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.


Re: Changing the injection key for a binding

2016-03-30 Thread Stephan Classen
I only allow usage of the EDSL within the abstract method 
PersistenceModule.configurePersistence().
All EDSL methods have a check as the very first statement to ensure that 
they are called from within the configurePersistence().


The configurePersistence() itself is a callback which will be called 
when the injector is created (i.e. during Module.configure() )


I know this is a very strong limitation. I don't know how strict you 
want to hide guice from the user of the EDSL. If they are awear of guice 
then they know about the configure() method. So the concept of your own 
configureXxx() method is nothing new.



On 31.03.2016 01:25, John Gardiner Myers wrote:



On Tuesday, March 29, 2016 at 2:07:30 PM UTC-7, scl wrote:

OK, I read you post several times still I am not 100% sure if I
understood your problem entirely.
Maybe some more code or concrete examples would be helpful...


I was trying to avoid posting a wall of code. A non-working attempt of 
mine is at 
https://github.com/johngmyers/platform/commit/ffac3e042bbf530f3af09f7072eba91e742e6471



From what I think you are trying to achieve I have done something
similar myself once before.
Have a look at the following classes:


This looks pretty close to what I am attempting. How do you ensure 
that Guice doesn't configure your PersistenceModule until all users of 
the EDSL are done? In my attempt, the ReportCollectionModule is 
configured immediately upon installation, before the calling Module 
finishes calling the EDSL methods.


--
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 google-guice+unsubscr...@googlegroups.com 
.
To post to this group, send email to google-guice@googlegroups.com 
.

Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/583e2768-ac57-4e6a-8702-ab8bb99251fb%40googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.


--
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/56FC63FD.5010504%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.


Re: Multiple modules, conflicting on @Provides

2016-03-22 Thread Stephan Classen

Private modules is the way to go.
A binding in a private module can see all other bindings in the same 
private module and all bindings of all non private modules.




On 22.03.2016 21:58, Chris Kessel wrote:
I'm adding two Guice modules, but they both have an @Provides for the 
same item. They're both 3rd party modules, so I can't modify the code. 
How do I prevent the collision? I really need each module to use it's 
own provided version. I guess the equivalent of each living within 
it's own "scope" where it's provided items aren't visible to the other 
modules.


Guice.createInjector(Stage.DEVELOPMENT, Arrays.asList(moduleA, moduleB));

I've tried wrapping them in a PrivateModule, but then they don't seem 
to even see their own @Provides...maybe I'm not understanding how to 
configure a PrivateModule? I'll actually want expose one specific 
class from each module to to my module that I'm developing, but my 
first step was trying to get these two other modules to coexist.


The injector supports creation with multiple modules and it seems like 
provider collision would happen now and then, so presumably there's 
some way to deal with that I'm not groking...


Thanks,
Chris

--
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 google-guice+unsubscr...@googlegroups.com 
.
To post to this group, send email to google-guice@googlegroups.com 
.

Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/26e2e40f-3b26-4ec5-bd20-1c3a2f67fd1e%40googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.


--
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/56F1DAF2.7020608%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.


Re: inject object into module

2016-03-27 Thread Stephan Classen
There are several points to mention. But don't worry we will get you 
where you want to be.


1. Guice modules do not get injected. Modules define what is binded in 
the injector. This means the modules are used to construct the injector. 
So they exist before the injector does. This makes it impossible for 
them to have anything injected into them.
PlayFramework does its own magic. It creates the injector for you. To do 
this you can pass it a list of module classes in the PlayFramework 
application.conf. If you read the documentation of PlayFramework [1] it 
states that it optionally will pass the Play Configuration to the 
constructor of the module. This is done by PlayFramework and has nothing 
to do with Guice. Note that there is not @Inject annotation on the 
constructor of the module.


2. Getting instances of module A into module B. This may sound logical 
in the beginning but it is not how Guice works. If the injector is 
constructed from multiple modules then it knows the union of the binding 
defined in all modules. This is also the reason why you cannot bind the 
same class twice. The injector simply wouldn't know which binding to 
use. So a single module may not know all bindings but the injector which 
is created in the end will.


3. Passing the DAO service to the Mail class. As you mention it in a 
comment this is the actual goal and this is the core competence of 
Guice. Your only misconception was that you try to do this in the 
binding. You need to do this in the Mail class. I recommend using 
constructor injection:


|
@Singleton
publicclassMail {
private finalDAOdao;

|@Inject
| publicMail(DAOdao){
this.dao = dao;
}
}
|

That's it. Technically you don't even need to bind the Mail class in 
your module. Guice will simply create a just in time binding. Never the 
less I would recommend creating an interface for the mail service and 
then specify which class implements the interface. This is especially 
useful for testing since you can replace the actual implementation with 
a mock or a stub for testing services depending on the mail service.


|
publicclassEmailModuleextendsAbstractModule{

@Override
protectedvoidconfigure(){
   bind(Mail.class).to(|MailImpl.class|);
}
}
|

Hope this gets you started and if you encounter more questions report back.


[1] 
https://www.playframework.com/documentation/2.5.x/JavaDependencyInjection#Providing-custom-bindings


--
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/56F83A1D.2020301%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.


Re: Changing the injection key for a binding

2016-03-29 Thread Stephan Classen
OK, I read you post several times still I am not 100% sure if I 
understood your problem entirely.

Maybe some more code or concrete examples would be helpful...

From what I think you are trying to achieve I have done something 
similar myself once before.

Have a look at the following classes:
- PersistenceModule [1]
- PersistenceUnitModuleConfiguration [2]
- PersistenceUnitModule [3]

An example of the usage of above classes can be found here [4].

The idea behind my approach is that the PersistenceModule holds the EDSL 
(bunch of protected methods).
The EDSL methods store the configuration in the 
PersistenceUnitModuleConfiguration. When the injector is created the 
PersistenceUnitModuleConfigurations are used to create 
PersistenceUnitModules (see PersistenceModule. configurePersistenceUnits).

The PersistenceUnitModule will add the bindings to the injector.

I hope I am not totally off topic with my response.

Cheers


[1] 
https://svn.apache.org/viewvc/onami/tags/org.apache.onami.persist-1.0.1/src/main/java/org/apache/onami/persist/PersistenceModule.java?revision=1633051=markup
[2] 
https://svn.apache.org/viewvc/onami/tags/org.apache.onami.persist-1.0.1/src/main/java/org/apache/onami/persist/PersistenceUnitModuleConfiguration.java?revision=1633051=markup
[3] 
https://svn.apache.org/viewvc/onami/tags/org.apache.onami.persist-1.0.1/src/main/java/org/apache/onami/persist/PersistenceUnitModule.java?revision=1633051=markup

[4] http://onami.apache.org/persist/complexWebApp.html


On 29.03.2016 21:16, John Gardiner Myers wrote:
I am attempting to implement some auxiliary EDSLs for accessing a 
library through Guice. I am having trouble figuring out how to 
implement .annotatedWith() in situations where the caller doesn't have 
to specify an implementation.


This is easy enough to do when the library needs to consume a 
mapping--one can have


reportBinder(binder).export(SomeClass.class);

throw into a multibinder a package local Mapping object containing a 
field with Key.get(SomeClass.class) and defaults for other fields, 
then .annotatedWith(...) can later replace that injection key field. 
Other EDSL methods can later replace other fields to have non-default 
values. So a caller could do:


reportBinder(binder).export(SomeClass.class).annotatedWith(SomeAnnotation.class).withTags(whatever); 



What I can't figure out how to implement is the situation where I need 
the EDSL to create a new binding.


reportBinder(binder).createReportCollection(SomeInterface.class);

needs to bind Key.get(SomeInterface.class) to some default 
implementation the library constructs, but


reportBinder(binder).createReportCollection(SomeInterface.class).annotatedWith(SomeAnnotation.class); 



needs to bind Key.get(SomeInterface.class, SomeAnnotation.class) to a 
default implementation, but not provide any binding for 
Key.get(SomeInterface.class).


Any suggestions for how to accomplish this?



--
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/56FAEE8F.1040203%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.


Re: TypeListener does not detect Map instance

2016-04-23 Thread Stephan Classen
You canot intercept methods on instances created by a provider. What guice does 
is to create a subclass of the thing you want to to intercept. But when you use 
a provider to create this object you are calling new yourself which makes it 
impossible for guice to sneak in the subclass.

Therefore interception of methods only works on instances created by guice 
(there is no 'new' in your code)

Am 23. April 2016 19:44:05 MESZ, schrieb Pablo perez :
>
>
>I´m using Guice TypeListener to intercept a map instance generated by a
>
>provider.
>
>Here the config method where I bind my listener
>
>@Overridepublic void addConfig() {
>MapListener mapListener = new MapListener();
>requestInjection(mapListener);
>bindListener(Matchers.any(), mapListener);}
>
>This is the map instance created by this provider
>
>  @Provides
>  Map mapTest(){
>return new HashMap<>();
>  }
>
>This is the listener class to detect the map instance
>
>public class MapListener implements TypeListener {
>
>@Override
>public  void hear(final TypeLiteral typeLiteral, TypeEncounter
>typeEncounter) {
>typeEncounter.register((InjectionListener) i -> {
>if(i.getClass().isAssignableFrom(Map.class)){
>  System.out.println("DI:"+ i.getClass()
>.getName());
> //TODO:Logic to modify map
>}
>});
>}}
>
>The problem is the Map is never passed to the hear method. Am I doing 
>something wrong?
>
>Regards.
>
>-- 
>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 google-guice+unsubscr...@googlegroups.com.
>To post to this group, send email to google-guice@googlegroups.com.
>Visit this group at https://groups.google.com/group/google-guice.
>To view this discussion on the web visit
>https://groups.google.com/d/msgid/google-guice/dd19c60f-b7a0-4e25-8fb0-eac9d9fcbc80%40googlegroups.com.
>For more options, visit https://groups.google.com/d/optout.

-- 
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/7253D50F-0805-4FA7-9CA8-278A199C2B13%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.


Re: When to close an injected Closeable resource?

2016-05-02 Thread Stephan Classen
If this is about testing:
My recomendation is to use constructor injection. And then in the unit test I 
simply call the constructor. This way I have full controll over what is passed 
to the subject under test.
As a consequence of this. I do not make use of dependency injection during unit 
testing. Which then removes the need to bind different objects for production 
and testing.

Integration testing is different but there it is most of the time sufficient to 
change bindings to a few external resources such as DB, mail, etc.

Am 3. Mai 2016 02:45:47 MESZ, schrieb Andree Surya :
>Thanks for the responses.
>
>*"Look at guice-persist or onami-persist. They deal wir DB connections
>which also need to be closed after it has been used. To do so they both
>use
>the concept of UnitOfWork. The application is then responsible for
>spanning
>the UnitOfWork around the code which needs the resource."*
>
>Thanks for the reference. *UnitOfWork* is a new concept to me and I'll
>take
>some time to read on it.
>
>*"But in general I'd say binding something like a Reader is
>questionable.
>I'd rather bind something stateless like a Path, which can be used to
>open
>a Reader by whoever needs to."*
>
>My original intention was to make it easy replace a FileReader with a
>StringReader during unit test, thus avoiding dependency to the file
>system.
>I agree, though, that injecting a stateful object like a Reader could
>possibly create confusion concerning state management. The Parser
>depends
>on the Reader, but because the Reader is injected from outside,
>somebody
>else could have messed it up (closing, moving the cursor, etc).
>
>*"bind something that can give you the resource rather than the
>resource
>itself (unless the lifetime is super well defined, like
>servletoutputstream). For example, guava ByteSource/CharSource would
>work
>great."*
>
>Thank you, I think I'll proceed this approach. This way, I can can
>easily
>replace file-based input source to an in-memory data during unit test,
>while encapsulating the responsibility of opening/closing the stream
>within
>the Parser object.
>
>Andree
>
>On Tue, May 3, 2016 at 3:44 AM Luke Sandberg 
>wrote:
>
>> +1 to that.
>>
>> bind something that can give you the resource rather than the
>resource
>> itself (unless the lifetime is super well defined, like
>> servletoutputstream).  For example,  guava ByteSource/CharSource
>would work
>> great
>>
>> On Mon, May 2, 2016 at 8:47 AM Tavian Barnes 
>wrote:
>>
>>> On Friday, 29 April 2016 19:40:44 UTC-4, Andree Surya wrote:

 Is it a commonplace to inject a resource that should be cleaned-up
>after (e.g. Closable)? In general, who has the responsibility for the
>clean-up?


>>> If the Reader is unscoped, then everybody who injects it gets a
>different
>>> instance, so it's up to the class that injects it to close it.
>>>
>>> But in general I'd say binding something like a Reader is
>questionable.
>>> I'd rather bind something stateless like a Path, which can be used
>to open
>>> a Reader by whoever needs to.
>>>
>>> --
>>>
>> 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 google-guice+unsubscr...@googlegroups.com.
>>
>>
>>> To post to this group, send email to google-guice@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/google-guice.
>>> To view this discussion on the web visit
>>>
>https://groups.google.com/d/msgid/google-guice/f293df1e-0653-4bcf-9841-e1c5dc281838%40googlegroups.com
>>>
>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
>> You received this message because you are subscribed to a topic in
>the
>> Google Groups "google-guice" group.
>> To unsubscribe from this topic, visit
>>
>https://groups.google.com/d/topic/google-guice/rcUWE--TfRQ/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> google-guice+unsubscr...@googlegroups.com.
>> To post to this group, send email to google-guice@googlegroups.com.
>> Visit this group at https://groups.google.com/group/google-guice.
>> To view this discussion on the web visit
>>
>https://groups.google.com/d/msgid/google-guice/CAO9V1MKVE96AxX6vYftRA92o7ObQn-K%2BO1jDbf4%2B-PeStmqu_g%40mail.gmail.com
>>
>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>-- 
>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 

Re: When to close an injected Closeable resource?

2016-05-01 Thread Stephan Classen
Look at guice-persist or onami-persist. They deal wir DB connections which also 
need to be closed after it has been used.
To do so they both use the concept of UnitOfWork. The application is then 
responsible for spanning the UnitOfWork around the code which needs the 
resource.

Am 30. April 2016 01:40:44 MESZ, schrieb Andree Surya :
>Hi there,
>
>I have the following Guice binding in my application.
>
>bind(Reader.class)
>.annotatedWith(DictionarySourceReader.class)
>.toProvider(DictionarySourceProvider.class);
>
>DictionarySourceProvider will provide a FileReader object, which will
>be injected to a DictionarySourceParser.
>
>
>public class DictionarySourceParser {
>
>private Reader sourceReader;
>
>@Inject
>  DictionarySourceParser(@DictionarySourceReader Reader sourceReader) {
>this.sourceReader = sourceReader;
>}
>
>public List parse() {
>
>// Parsing entries from the reader 
>
>return entries;
>}
>}
>
>I have two questions:
>
>
>1. When DictionarySourceParser is done with the Reader, who has the
>responsibility to close the reader? Should the parser be responsible?
>2. Is it a commonplace to inject a resource that should be cleaned-up
>after (e.g. Closable)? In general, who has the responsibility for the
>clean-up?
>
>Cheers,
>Andree
>
>-- 
>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 google-guice+unsubscr...@googlegroups.com.
>To post to this group, send email to google-guice@googlegroups.com.
>Visit this group at https://groups.google.com/group/google-guice.
>To view this discussion on the web visit
>https://groups.google.com/d/msgid/google-guice/bc764248-c00d-47c2-8207-2fd45087b352%40googlegroups.com.
>For more options, visit https://groups.google.com/d/optout.

-- 
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/D554D6B0-87B5-4BDF-A61C-0F5C03B0742E%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.


Re: Object is injected only once, but it's constructor is called twice :(

2016-08-10 Thread Stephan Classen
I had such a behavior once. In the end I had one point in the code where I 
injected the interface and another where I injected the concrete instance. 
Guice created a just in time binding for the concrete inatance. This was the 
reason the constructor was called twice.

Am 10. August 2016 16:43:32 MESZ, schrieb Luke Sandberg 
:
>Can you share a test case that demonstrates this?
>
>On Tue, Aug 9, 2016, 8:36 PM Yashiro Nanakase 
>wrote:
>
>> hi Witold,
>>
>> I'm having this problem too, did you get it solved? Can you please
>share
>> the solution? thanks.
>>
>> Regards,
>> Yashiro
>>
>> On Friday, December 18, 2009 at 7:37:27 PM UTC+8, Witold Szczerba
>wrote:
>>>
>>> 2009/12/18 Witold Szczerba :
>>> > threads! So, I placed breakpoint inside TaskBrowserCtr constructor
>and
>>> > it was caught TWICE during Guice's Injector initialization
>>> > (Stage.PRODUCTION).
>>>
>>> Now I can see it happens only when Stage.PRODUCTION is used.
>>> Going back to the above problem, the MainFrame singleton's
>constructor
>>> itself was called twice, not just the TaskBrowserCtrTimer...
>>> In the constructor of MainFrame I have entered
>Thread.dumpStackTrace()
>>> and two dumps were printed (see attachments). Third attachment was
>>> taken during initialization of Stage.DEVELOPMENT injector.
>>>
>> --
>> 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 google-guice+unsubscr...@googlegroups.com.
>> To post to this group, send email to google-guice@googlegroups.com.
>> Visit this group at https://groups.google.com/group/google-guice.
>> To view this discussion on the web visit
>>
>https://groups.google.com/d/msgid/google-guice/b76baba6-578a-453e-b7a5-30c10c06555d%40googlegroups.com
>>
>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>-- 
>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 google-guice+unsubscr...@googlegroups.com.
>To post to this group, send email to google-guice@googlegroups.com.
>Visit this group at https://groups.google.com/group/google-guice.
>To view this discussion on the web visit
>https://groups.google.com/d/msgid/google-guice/CAO9V1ML2CWEFsEgcAWZr%2B31Mn6ozbZ7vRpce8xLOw7YYWUO6cQ%40mail.gmail.com.
>For more options, visit https://groups.google.com/d/optout.

-- 
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/1FE397A3-E79D-4AA4-BD6C-41AA99321B42%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.


Re: PrivateModule

2016-07-19 Thread Stephan Classen
While reading the code example I assumed you would get an exception 
because you bind IResourceSetProvider twice.


Anyways the thing you are looking for is Modules.override()
https://google.github.io/guice/api-docs/latest/javadoc/com/google/inject/util/Modules.html#override-com.google.inject.Module...-





On 19.07.2016 08:39, adambialas1...@gmail.com wrote:

Hi guys,

Is there a way to provide custom binding in my own Module which will 
override binding from other nested PrivateModule .


More precisely:

I have a module  with implementation:

void configure() {
   binder().install(new PrivateModule() {
@Override
protected void configure() {
bind(IResourceSetProvider.class).to(XtextResourceSetProvider.class);
bind(XtextResourceSet.class).to(SynchronizedXtextResourceSet.class);
expose(IResourceSetProvider.class);
}
});
}

I would like to provide my custom implementation for 
IResourceSetProvider.class.

This is how I try to make it:

void configure(Binder binder) {
binder.bind(IResourceSetProvider.class).to(ExtXtextResourceSetProvider.class);
super.configure(binder);
}


When the IResourceSetProvider instance is injected it returns all the 
time XtextResourceSetProvider. Is there any way to implement my module 
to return ExtXtextResourceSetProvider?



Adam
--
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 google-guice+unsubscr...@googlegroups.com 
.
To post to this group, send email to google-guice@googlegroups.com 
.

Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/caa50ca8-bd15-4ed6-819d-9928ac6c3f17%40googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.


--
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/578E136E.3040909%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.


Re: JPA entity with custom annotations

2016-08-15 Thread Stephan Classen

Yes the entityManager is created by guice.

But the entities that you retrieve from the DB are not created by guice 
and therefore the interceptor does not work.



On 14.08.2016 16:51, Travis Collins wrote:
I'm running a small test that uses a Guice managed JPA context. It's 
working very well.


I have created some custom annotations on the entity classes. These 
annotations are generally used to validate values on setters. I'm 
using the Guice binder.bindInterceptor(...) method to intercept method 
calls and validate values.


When I use a Guice Provider<> to instantiate new instances of these 
classes, the annotation interceptors are working correctly.


However, when I retrieve a JPA object from the persistence context, 
the custom annotation interceptors are not being called. For example, 
if I get an entity instance using the JPA entity manager, and then try 
to set an invalid value on that object - the interceptor is not called 
and the invalid value is allowed.


I have verified that the entityManager being used is Guice provided.

Any ideas?
--
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 google-guice+unsubscr...@googlegroups.com 
.
To post to this group, send email to google-guice@googlegroups.com 
.

Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/7c493f80-dcf4-427f-9706-36283ae7160d%40googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.


--
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/fa9eb442-483f-71f2-6300-3f2f3685b840%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.


Re: Module overrides don't work with MapBinder

2017-01-16 Thread Stephan Classen
If you only want to add server to the MapBinder then there is no need to 
overwrite modules.


From the JavaDoc [1]:
Contributing mapbindings from different modules is supported. For 
example, it is okay to have both |CandyModule| and |ChipsModule| both 
create their own |MapBinder|, and to each contribute 
bindings to the snacks map. When that map is injected, it will contain 
entries from both modules.


[1] 
http://google.github.io/guice/api-docs/latest/javadoc/com/google/inject/multibindings/MapBinder.html



On 17.01.2017 00:52, Rchytas wrote:
I was wondering where does override go (Sorry if its a dumb question, 
I'm new to Guice). I've module deployed in web app as below -



import com.google.inject.multibindings.MapBinder;

public class ExternalDatabaseModule extends AbstractModule implements 
com.abc.Module {

  public void configure() {
MapBinder m = 
MapBinder.newMapBinder(binder(), String.class, 
ExternalDatabaseConnection.class);

m.addBinding("DBServer1).to(ExternalDBServer1Connection.class);
m.addBinding("DBServer2").to(ExternalDBServer2Connection.class);
  }
}

I then created another module and exported this to a jar file and then 
added this jar to tomcat/web-inf/lib. But my new binding did not get 
discovered


public class ABCExternalDatabaseModule extends AbstractModule implements
com.abc.Module {
@Override
public void configure() {
MapBinder m = MapBinder
.newMapBinder(binder(), String.class,
ExternalDatabaseConnection.class);
m.addBinding("DBServer3").to(ExternalDBServer3Connection.class);

}

public ABCExternalDatabaseModule() {
Guice.createInjector(Modules.override(
new ExternalDatabaseModule()).with(
new ABCExternalDatabaseModule()));
}

}


On Monday, January 17, 2011 at 11:27:39 PM UTC-8, Reinhard Nägele wrote:

I just discovered that bindings created with a MapBinder cannot be
overridden. Here's an example:

Module module1 = new AbstractModule() {
@Override
protected void configure() {
MapBinder mapBinder =
MapBinder.newMapBinder(binder(), String.class,
String.class);
mapBinder.addBinding("foo").toInstance("foo1");
}
};

Module module2 = new AbstractModule() {
@Override
protected void configure() {
MapBinder mapBinder =
MapBinder.newMapBinder(binder(), String.class,
String.class);
mapBinder.addBinding("foo").toInstance("foo2");
}
};

Guice.createInjector(Modules.override(module1).with(module2));


Executing the above code yields the following error in Guice 2.0 and
3.0-rc2:

Exception in thread "main" com.google.inject.CreationException: Guice
creation errors:

1) Map injection failed due to duplicated key "foo"
  at com.google.inject.multibindings.MapBinder$RealMapBinder
$1.initialize(MapBinder.java:355)
  at spielplatz.TestApp$2.configure(TestApp.java:31)

1 error
at

com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:

416)
at

com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:

175)
at

com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:

109)
at com.google.inject.Guice.createInjector(Guice.java:95)
at com.google.inject.Guice.createInjector(Guice.java:72)
at com.google.inject.Guice.createInjector(Guice.java:62)
at spielplatz.TestApp.main(TestApp.java:36)


Is this intended behavior? It looks like a bug to me, or am I missing
something?

Reinhard

--
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 google-guice+unsubscr...@googlegroups.com 
.
To post to this group, send email to google-guice@googlegroups.com 
.

Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/7d227d88-812a-4abe-92e7-77e79d2f644c%40googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.


--
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 

Re: Problem binding Base abstract class

2017-02-26 Thread Stephan Classen
So far this code looks correct. Can you also provide some of the test methods. 
Maybe something is hiding there.

Am 27. Februar 2017 03:45:39 MEZ schrieb Nandish MC :
>
>
>I have multiple hierarchical class like below
>
>public abstract class Page extends SelPage
>{
>public method 1{}
>public method 2{}
>public method 3{}
>}
>
>Class DashboardPage extens Class Page{
>{ }
>
>Here I need to bind new Page class
>Class ProjPage extends Page{
>public method1{} /* change method implementation 
>*/public method 2{} /* change method implementation 
>*/public method 3{} /* change method implementation */
>}
>
>public class ProjSeleniumSuite extends SeleniumSuite {
>
>private static Injector injector;
>
>@BeforeClass
>public static void setUp() throws Exception {
>injector = Guice.createInjector(new AbstractModule() {
>@Override
>protected void configure() {
>System.out.println("configuriung");
>bind(Page.class).to(ProjPage.class);
>}
>});
>}
>@AfterClass
>public static void tearDown() throws Exception {
>injector = null;
>}
>
>}
>
>The above code runs fine..but it is not binding the Page class method 
>implementation with ProjPage class methods
>Can i achieve this using Guice binder like above?
>
>The thing i need to achieve is, when i instantiate DashboardPage , i
>want 
>ProjPage methods to be called instead of Page class methods.
>
>Please help
>
>-- 
>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 google-guice+unsubscr...@googlegroups.com.
>To post to this group, send email to google-guice@googlegroups.com.
>Visit this group at https://groups.google.com/group/google-guice.
>To view this discussion on the web visit
>https://groups.google.com/d/msgid/google-guice/5da962c5-74da-466d-b96f-53cb647a0eb1%40googlegroups.com.
>For more options, visit https://groups.google.com/d/optout.

-- 
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/644FC308-ACCF-4D20-AC7E-B3C93DE30A55%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.


Re: Problem binding Base abstract class

2017-02-27 Thread Stephan Classen
I see in you code how you construct the injector. But I never see you 
making use of it.
I am not familiar with the Selenium library. Does it make use of the 
injector in the SeleniumTest.getCurrentPage() method?
I rather doubt that Selenium will use you injector. So where do you use 
the injector?



On 27.02.2017 21:46, Nandish MC wrote:

public abstract class Page extends SelPage
{
   public void logOut() {
System.out.println("inside Product");
WebDriverWait wait = new WebDriverWait(getDriver(), 
getWaitTime());
WebElement element = 
wait.until(ExpectedConditions.elementToBeClickable(By.id("logout")));

element.click();

// this is typically not recommended, but logout is an 
oddball; because
// we don't know where we're going after logout, we can't do a 
"wait"

// for something on that page
try {
Thread.sleep(200);
} catch (InterruptedException e) {
// eat it
}
}
}


Class ProjPage extends Page{

 @Override
public void logOut() {
System.out.println("Inside Project");
WebDriverWait wait = new WebDriverWait(getDriver(), getWaitTime());
WebElement element = 
wait.until(ExpectedConditions.elementToBeClickable(By.id("logout")));

element.click();

// this is typically not recommended, but logout is an 
oddball; because
// we don't know where we're going after logout, we can't do a 
"wait"

// for something on that page
try {
Thread.sleep(200);
} catch (InterruptedException e) {
// eat it
}
}
}

@RunWith(Suite.class)
@Suite.SuiteClasses({ Login.class,
ProjectLogout.class,
})
public class ProjSeleniumSuite extends SeleniumSuite {
private static Injector injector;
/*
 * No code is needed in here. Add new tests to the suite by 
putting them in

 * the @Suite.SuiteClasses() declaration above.
 */

@BeforeClass
public static void setUp() throws Exception {
System.out.println("setting up");
injector = Guice.createInjector(new AbstractModule() {

@Override
protected void configure() {
System.out.println("configuriung");
bind(Page.class).to(ProjPage.class);
}
});
}

@AfterClass
public static void tearDown() throws Exception {
System.out.println("tearing down");
injector = null;
}
}

public class ProjLogout extends ProjTest {

/**
 * Log out of the application.
 */
@Test
public void logout() {
System.out.println("inside CBC logout");
getCurrentPage().logout();
}
 }

Class DashboardPage extends Class Page{
{
//inherits Page logout method
methods 1
methods 2
methods 3
 }

public abstract class ProjTest extends SeleniumTest{
   public Page getCurrentPage() {
   try{
Page dashBoardPage =(Page) super.getCurrentPage(); // This 
gets the Dashboard page instance

}catch(Exception e){
setCurrentPage(null);
}
return (Page) super.getCurrentPage();
  }
}


Above are the set of classes used, here I am trying to get ProjPage 
logout method to be executed instead of Page.logout() method.


This method is an inherited method for Dashboard Page.

currently, even after binding I see Page.logout() method is executed


On Monday, February 27, 2017 at 1:01:58 AM UTC-5, scl wrote:

So far this code looks correct. Can you also provide some of the
test methods. Maybe something is hiding there.

Am 27. Februar 2017 03:45:39 MEZ schrieb Nandish MC
:

I have multiple hierarchical class like below

public abstract class Page extends SelPage
{
public method 1{}
public method 2{}
public method 3{}
}


Class DashboardPage extens Class Page{
{ }

Here I need to bind new Page class
Class ProjPage extends Page{
public method1{} /* change method implementation //
public method 2{} // change method implementation //
public method 3{} // change method implementation */
}

public class ProjSeleniumSuite extends SeleniumSuite {

|private static Injector injector; @BeforeClass public static
void setUp() throws Exception { injector =
Guice.createInjector(new AbstractModule() { @Override
protected void configure() {
System.out.println("configuriung");
bind(Page.class).to(ProjPage.class); } }); } @AfterClass
public static void tearDown() throws Exception { injector =
null; } |

}

The above code runs fine..but it is not binding the Page class
method implementation with ProjPage class methods Can i
achieve this using Guice binder like above?

The thing i need to achieve is, when i instantiate
DashboardPage , i want ProjPage methods to be called instead
of Page class methods.

  

Re: Guice Persist support for Neo4j

2016-09-16 Thread Stephan Classen
I was using guice-persist in an environment with multiple databases and 
ran into some limitations (see the guice bug tracker).


Since there was not much effort from the official developers I decided 
to write my own persist extension. I supports out of the box:


- All features of guice-persist
- JPA with multiple databases
- JTA (multi resource transactions)
- resolved some of the issues from the Guice bug tracker

So if you have questions, need hints just ask on this list.

Feel like browsing more code:
https://svn.apache.org/viewvc/onami/trunk/persist/

Cheers
Stephan



On 16.09.2016 03:17, Mark Angrish wrote:

Hi Thomas,

Yeah I saw yours. I will look through it more carefully when i get the 
chance.


I think there are a number of bugs in the core guice-persist framework 
that I'd like to iron out (it doesn't seem to update much so i might 
fork it) but other than that it's just straight up transactional support.


::mark

On Wednesday, 14 September 2016 15:46:45 UTC+10, Thomas Broyer wrote:

Hi,

A few years ago, I did a similar thing at
https://github.com/tbroyer/guice-persist-neo4j

Feel free to borrow some code, but IIRC it didn't do more than yours.

--
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 google-guice+unsubscr...@googlegroups.com 
.
To post to this group, send email to google-guice@googlegroups.com 
.

Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/f1482282-576f-4ed4-b6c6-8e1a817e0c02%40googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.


--
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/4084191b-77dc-daeb-865a-699dabcccf9d%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.


Re: Injecting an EntityManager specifying the persistence unit with @javax.inject.Qualifier

2016-09-28 Thread Stephan Classen
Where do you bind the EntityManager? Is it bound just in time? At runtime do 
you have a container or similar which provides the EntityManager?

Am 28. September 2016 17:20:16 MESZ, schrieb "Robério Cardoso Fernandes" 
:
>Hi folks,
>I'm doing the unit tests in my project, and I'm trying to use the
>Google 
>Guice. My repository classes have your EntityManagers, and, in my
>project, 
>to specify the persistence unit I have an annotation:
>
>@javax.inject.Qualifier
>@java.lang.annotation.Retention(RUNTIME)
>@java.lang.annotation.Target({FIELD, TYPE, METHOD})
>public @interface ConnectionDatabase {
>}
>
>
>In my repositories the entity managers are injected like this:
>
>public class MyRepository implements IMyRepository {
>
>@javax.inject.Inject
>@ConnectionDatabase
>private javax.persistence.EntityManager entityManager;
>}
>
>
>M ResourceProducer, like this:
>
>public class ResourceProducer {
>
>@javax.enterprise.inject.Produces
>@Inject
>@ConnectionDatabase
>private javax.persistence.EntityManager entityManager;
>}
>
>
>My Module of Google Guice is like this:
>
>public class ModuleTest extends AbstractModule {
>
>@Override
>public void configure() {
>  bind(new TypeLiteral() {}).to(MyRepository.class);
>}
>}
>
>
>I have a persistence.xml with a persistence unit called "TestPU".
>
>
>In my unit tests (or cintegration tests), using the Google Guice, the 
>EntityManager is not injected, and the following error is occurring:
>No implementation for javax.persistence.EntityManager annotated with 
>@ConnectionDatabase() was bound.
>  while locating javax.persistence.EntityManager annotated with 
>@ConnectionDatabase()
>for field at MyRepository.entityManager()
>  at ModuloTest.configure(TypeLiteral() {}).to(MyRepository.class)">)
>
>
>Someone here can help me, please?
>
>-- 
>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 google-guice+unsubscr...@googlegroups.com.
>To post to this group, send email to google-guice@googlegroups.com.
>Visit this group at https://groups.google.com/group/google-guice.
>To view this discussion on the web visit
>https://groups.google.com/d/msgid/google-guice/aa4d80df-40be-4e47-ba75-89833b20536f%40googlegroups.com.
>For more options, visit https://groups.google.com/d/optout.

-- 
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/C7227655-8A6A-499D-A5B7-FB3D241839E2%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.


Re: Injecting an EntityManager specifying the persistence unit with @javax.inject.Qualifier

2016-09-29 Thread Stephan Classen

The binding

bind(EntityManager.class).annotatedWith(ConnectionDatabase.class).to(EntityManager.class);

tells guice to use the default binding of defined for EntityManager. So 
there must be somewhere a binding or a provider method which defines how 
to get an implementation of the EntityManager interface.


If you need JPA with guice have a look at onami-persist.


On 29.09.2016 18:51, Robério Cardoso Fernandes wrote:
My project have some maven modules, one of that is the repository 
module, an other is the web module.
In repository module I'm using the google guice to do the dependency 
injection, and any more.
In web module I'm using the tomEE, and that module have all others 
(api, services and repositories).
My problem was in repository module, when I would inject the 
EntityManager object in repositories, to solve this problem I put in 
the implementation of Guice AbstractModule it:

bind(EntityManager.class).annotatedWith(ConnectionDatabase.class).to(EntityManager.class);

What do you thing about?


Thank you for the attention!


Em quarta-feira, 28 de setembro de 2016 19:47:57 UTC-3, scl escreveu:

I am not 100% sure but I think guice does not support the
@Produces annotation.
So far I only used @Provides

Also if you are using tomEE you already have a CDI container. What
is your reason to use guice in such an environment.

Don't missunderstand me. I prefer guice over CDI but why chose
tomEE and then don't use its feature...

Am 28. September 2016 19:36:28 MESZ, schrieb "Robério Cardoso
Fernandes" :

I'm doing the integration tests with Apache OpenEJB (tomee).
The bind is done when the container is started.



Em quarta-feira, 28 de setembro de 2016 14:12:46 UTC-3, scl
escreveu:

Where do you bind the EntityManager? Is it bound just in
time? At runtime do you have a container or similar which
provides the EntityManager?

Am 28. September 2016 17:20:16 MESZ, schrieb "Robério
Cardoso Fernandes" :

Hi folks,
I'm doing the unit tests in my project, and I'm trying
to use the Google Guice. My repository classes have
your EntityManagers, and, in my project, to specify
the persistence unit I have an annotation:

@javax.inject.Qualifier
@java.lang.annotation.Retention(RUNTIME)
@java.lang.annotation.Target({FIELD, TYPE, METHOD})
public @interface ConnectionDatabase {
}


In my repositories the entity managers are injected
like this:

public class MyRepository implements IMyRepository {

@javax.inject.Inject
@ConnectionDatabase
private javax.persistence.EntityManager entityManager;
}


M ResourceProducer, like this:

public class ResourceProducer {

@javax.enterprise.inject.Produces
@Inject
@ConnectionDatabase
private javax.persistence.EntityManager entityManager;
}


My Module of Google Guice is like this:

public class ModuleTest extends AbstractModule {

@Override
public void configure() {
bind(new TypeLiteral()
{}).to(MyRepository.class);
}
}


I have a persistence.xml with a persistence unit
called "TestPU".


In my unit tests (or cintegration tests), using the
Google Guice, the EntityManager is not injected, and
the following error is occurring:
No implementation for javax.persistence.EntityManager
annotated with @ConnectionDatabase() was bound.
  while locating javax.persistence.EntityManager
annotated with @ConnectionDatabase()
for field at MyRepository.entityManager()
  at ModuloTest.configure(()
{}).to(MyRepository.class)">)


Someone here can help me, please?

--
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 google-guice+unsubscr...@googlegroups.com 
.
To post to this group, send email to google-guice@googlegroups.com 
.

Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/eeb80f3e-2d84-429a-9a08-721dd314b72b%40googlegroups.com 

Re: Injecting an EntityManager specifying the persistence unit with @javax.inject.Qualifier

2016-09-28 Thread Stephan Classen
I am not 100% sure but I think guice does not support the @Produces annotation.
So far I only used @Provides

Also if you are using tomEE you already have a CDI container. What is your 
reason to use guice in such an environment.

Don't missunderstand me. I prefer guice over CDI but why chose tomEE and then 
don't use its feature...

Am 28. September 2016 19:36:28 MESZ, schrieb "Robério Cardoso Fernandes" 
:
>I'm doing the integration tests with Apache OpenEJB (tomee). The bind
>is 
>done when the container is started.
>
>
>
>Em quarta-feira, 28 de setembro de 2016 14:12:46 UTC-3, scl escreveu:
>>
>> Where do you bind the EntityManager? Is it bound just in time? At
>runtime 
>> do you have a container or similar which provides the EntityManager?
>>
>> Am 28. September 2016 17:20:16 MESZ, schrieb "Robério Cardoso
>Fernandes" <
>> robe...@gmail.com >:
>>>
>>> Hi folks,
>>> I'm doing the unit tests in my project, and I'm trying to use the
>Google 
>>> Guice. My repository classes have your EntityManagers, and, in my
>project, 
>>> to specify the persistence unit I have an annotation:
>>>
>>> @javax.inject.Qualifier
>>> @java.lang.annotation.Retention(RUNTIME)
>>> @java.lang.annotation.Target({FIELD, TYPE, METHOD})
>>> public @interface ConnectionDatabase {
>>> }
>>>
>>>
>>> In my repositories the entity managers are injected like this:
>>>
>>> public class MyRepository implements IMyRepository {
>>>
>>> @javax.inject.Inject
>>> @ConnectionDatabase
>>> private javax.persistence.EntityManager entityManager;
>>> }
>>>
>>>
>>> M ResourceProducer, like this:
>>>
>>> public class ResourceProducer {
>>>
>>> @javax.enterprise.inject.Produces
>>> @Inject
>>> @ConnectionDatabase
>>> private javax.persistence.EntityManager entityManager;
>>> }
>>>
>>>
>>> My Module of Google Guice is like this:
>>>
>>> public class ModuleTest extends AbstractModule {
>>>
>>> @Override
>>> public void configure() {
>>> bind(new TypeLiteral()
>{}).to(MyRepository.class);
>>> }
>>> }
>>>
>>>
>>> I have a persistence.xml with a persistence unit called "TestPU".
>>>
>>>
>>> In my unit tests (or cintegration tests), using the Google Guice,
>the 
>>> EntityManager is not injected, and the following error is occurring:
>>> No implementation for javax.persistence.EntityManager annotated with
>
>>> @ConnectionDatabase() was bound.
>>>   while locating javax.persistence.EntityManager annotated with 
>>> @ConnectionDatabase()
>>> for field at MyRepository.entityManager()
>>>   at ModuloTest.configure(>> TypeLiteral() {}).to(MyRepository.class)">)
>>>
>>>
>>> Someone here can help me, please?
>>>
>>>
>
>-- 
>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 google-guice+unsubscr...@googlegroups.com.
>To post to this group, send email to google-guice@googlegroups.com.
>Visit this group at https://groups.google.com/group/google-guice.
>To view this discussion on the web visit
>https://groups.google.com/d/msgid/google-guice/fc26fa51-d3c1-4f17-a4f5-cd7f72c6eade%40googlegroups.com.
>For more options, visit https://groups.google.com/d/optout.

-- 
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/A2CDA87D-7E87-48C6-B232-FB55F3658F84%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.


Re: Inject a sequence of components that implement the same interface and have dependencies themselves

2016-11-08 Thread Stephan Classen

  
  
Have a look at
https://github.com/google/guice/wiki/Multibindings

this does not solve the problem of how to configure them. But it
allows you to inject a set/map of things.


On 11/07/2016 11:42 PM, Dominik wrote:


  I want to inject a sequence of components where
each component implements the same interface. Each of the
components may have dependencies themselves which may vary
amongst the different implementations of the interface. The
actual sequence shall be configurable by the user by means of a
configuration file or any mechanism that is made available
through the dependency injection framework (guice).

To be more concrete I'll give an example:



interface Machine {...}
  
class Dishwasher implements Machine {
      // Here some dependencies
  should be injected.
}
class VacuumCleaner implements Machine {
    //
Here some dependencies should be injected.
  }
  
class Household {
      // Here I want to inject a
  sequence of `Machine`s.
}
  
// Now the user may specify
  in whatever way which machines are present in the
  household,
// and this setting is not
  changing during runtime.
  // For example (using an arbitrary notation):
  //
//   
  Household
//   
  |
//   
  | Machines
// 
  |
// 
  | Dishwasher
// 
  |     |
// 
  |     |- SomeDepedencyForDishwasher
  // 
|     |- AnotherDepedencyForDishwasher
// 
  |
// 
  |- VacuumCleaner
  // 
|     |
  // 
|     |- SomeDependencyForVacuumCleaner
  // 
|
  // 
|- VacuumCleaner
// 
  |     |
// 
  |     |-
  AnotherDependencyForVacuumCleaner
//
  //
  // So the household would have three `Machine`s, two
  of which are `VacuumCleaner`s
  // (where each `VacuumCleaner` itself depends on a
  different implementation of another interface)
  // and one `Dishwasher`.

  

How can I realize this using guice? I could write a custom
provider for the `Machine`s (i.e. a `MachineFactory`), however
the pattern that "a component depends on a sequence of others
with dependencies themselves" may repeat further down the chain,
so I would be forced to write providers/factories for all of
them. This somehow breaks the purpose of dependency injection
where I can request a component and all dependencies are
resolved automatically by the framework. Furthermore it requires
the factory to have knowledge about the possible dependencies of
all implementations of the interface which breaks the separation
of dependencies from the application: whenever I add a new
implementation (a new Machine, e.g. `WashingMaschine`) I need to
check whether the factory already requests all required
dependencies for the `WashingMaschine` in order to "inject" them
manually into the `WashingMaschine` later on. If a new
dependency is introduced I need to fix the factory accordingly.

Any ideas? Thanks! Cheers, Dominik
  
  -- 
  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 google-guice+unsubscr...@googlegroups.com.
  To post to this group, send email to google-guice@googlegroups.com.
  Visit this group at https://groups.google.com/group/google-guice.
  To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/dc7b7e5c-9019-408e-b883-526bc3120802%40googlegroups.com.
  For more options, visit https://groups.google.com/d/optout.


  




-- 
You 

Re: Is guice-persist alive?

2017-04-04 Thread Stephan Classen

Hard to say

I'm not working for Google but last time I asked this question it 
remained unanswered.
Last real development I see in 2011. After this only whitespace 
refactorings.


The Issues in the issue tracker are also open since a very long time.

Because of this I wrote my own persistence extension for guice. This 
project has never attracted much attention and is by now also kind of 
abandoned. If you decide to resurrect it, I will gladly give you a hand

src: https://svn.apache.org/viewvc/onami/trunk/persist/
doc: https://onami.apache.org/persist/index.html

On 05.04.2017 00:16, Serega Sheypak wrote:

Hi, is it alive? I made it work, looks nice, but:
1. I need Finder stuff. Seems like warp is dead?
2. Will google-persist get new features?
--
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 google-guice+unsubscr...@googlegroups.com 
.
To post to this group, send email to google-guice@googlegroups.com 
.

Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/252e3cf5-3fdf-417b-aa1b-671fd25bdb21%40googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.


--
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/5625b04d-42f2-aba6-255f-7a9a7cf2bc87%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.


Re: Inject into a being injected class

2017-04-18 Thread Stephan Classen
You would need to bind the dependencies of your fancy email service. If those 
are configuration values like "url", "port" or similiar I recommend looking ate 
some of the 3rd party extensions which allow you to easily bind values from a 
properties file to a @Named singleton.

Maybe you find something at the apache onami project.

Am 18. April 2017 21:40:42 MESZ schrieb Balaraj V :
>
>
>I'm using Google Guice for dependency injection in my application. I
>have a 
>class structure like this,
>
>Example is taken from here 
>
>
>
>This is my interface,
>
>package com.journaldev.di.services;
>@ImplementedBy(EmailService.class)public interface MessageService {
>
>boolean sendMessage(String msg, String receipient);}
>
>Which I will implement here
>
>package com.journaldev.di.services;
>import javax.inject.Singleton;
>//import com.google.inject.Singleton;
>@Singletonpublic class EmailService implements MessageService {
>
>public boolean sendMessage(String msg, String receipient) {
>//some fancy code to send email
>System.out.println("Email Message sent to "+receipient+" with
>message="+msg);
>return true;
>}}
>
>If I inject EmailService here.
>
>package com.journaldev.di.consumer;
>import javax.inject.Inject;
>import com.journaldev.di.services.MessageService;
>public class MyApplication {
>
>private MessageService service;
>
>@Inject
>public void setService(MessageService svc){
>this.service=svc;
>}
>
>public boolean sendMessage(String msg, String rec){
>//some business logic here
>return service.sendMessage(msg, rec);
>}}
>
>If suppose my EmailService class looked like this,
>
>package com.journaldev.di.services;
>import javax.inject.Singleton;
>//import com.google.inject.Singleton;
>@Singletonpublic class EmailService implements MessageService {
>public EmailService(int someValue) {
>FancyEmailService fancyEmailService = new FancyEmailService(someValue);
>}
>public boolean sendMessage(String msg, String receipient) {
>fancyEmailService.doSomething();
>System.out.println("Email Message sent to "+receipient+" with
>message="+msg);
>return true;
>}}
>
>In order to test the above EmailService code, I need to inject 
>FancyEmailService than instantiating from the constructor. How do I
>inject 
>FancyEmailService into EmailService code? and still be able to inject 
>EmailService into MyApplication.
>
>I posted the same question in Stackoverflow could not find any answers.
>
>
>-- 
>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 google-guice+unsubscr...@googlegroups.com.
>To post to this group, send email to google-guice@googlegroups.com.
>Visit this group at https://groups.google.com/group/google-guice.
>To view this discussion on the web visit
>https://groups.google.com/d/msgid/google-guice/241faaeb-f5a5-4b93-930c-db977a929899%40googlegroups.com.
>For more options, visit https://groups.google.com/d/optout.

-- 
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/A2FE91ED-46F4-4AD1-9618-51D7B6E18EFD%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.


Re: Guice module integration issue with REST

2017-04-24 Thread Stephan Classen
Set a breakpoint or add a log statement at the end of the WorkerBean.findAll() 
to see what this method returns and if it is differen from what you see 
returned by the methodInvocation.proceed call

Am 24. April 2017 17:56:21 MESZ schrieb pradrone dev :
>Thanks it does work but now methodInvocation.proceed return [] (empty 
>object) where it should return list values.
>Any idea for such behaviour ?
>
>
>On Sunday, 23 April 2017 14:34:53 UTC+5:30, pradrone dev wrote:
>>
>> Guice module integration issue with REST I have define one AOP guice
>based 
>> module, but when I tried to integrate with REST code, 
>> methodInvocation.proceed retun null. What might be best way to solve
>this 
>> issue.
>>
>> Define AOP Guice based module as below
>>
>> @Retention (RetentionPolicy.RUNTIME)
>> @Target (ElementType.METHOD)
>> @interface  NotOnWeekends {}
>> public class WeekendBlocker implements MethodInterceptor {
>>
>> public Object invoke(MethodInvocation invocation) throws Throwable {
>>
>> Calendar today = new GregorianCalendar();
>>
>> if (today.getDisplayName(DAY_OF_WEEK, LONG, ENGLISH).startsWith("S"))
>{
>>
>>   throw new IllegalStateException(
>>
>>   invocation.getMethod().getName() + " not allowed on
>weekends!");
>> }
>>
>> return invocation.proceed();
>>
>> }
>>
>> }
>>
>> public class NotOnWeekendsModule extends AbstractModule {
>> protected void configure() {
>>
>> bindInterceptor(Matchers.any(),
>Matchers.annotatedWith(NotOnWeekends.class), 
>>
>> new WeekendBlocker());
>>
>> }
>> }
>>
>> But I tried to Integrate this with my REST API
>>
>> public class WorkerBean implements Worker {
>>
>> @Autowired
>> private WorkerRepository workerRepository;
>>
>> @Override
>> @NotOnWeekends
>> public Collection findAll() {
>>
>> Collection workers = workerRepository.findAll();
>>
>> return workers;
>> }
>>
>> @RestController 
>> public class WorkerController {
>>
>> @RequestMapping(
>> value = "/api/workers",
>> method = RequestMethod.GET,
>> produces = MediaType.APPLICATION_JSON_VALUE)
>> public ResponseEntity getWorkers() {
>>
>>
>> Worker worker = Guice.createInjector(new
>NotOnWeekendsModule()).getInstance(Worker.class);
>>
>> Collection worker = worker.findAll(); // return null 
>>
>> 
>> }
>>
>>
>
>-- 
>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 google-guice+unsubscr...@googlegroups.com.
>To post to this group, send email to google-guice@googlegroups.com.
>Visit this group at https://groups.google.com/group/google-guice.
>To view this discussion on the web visit
>https://groups.google.com/d/msgid/google-guice/fb70b5e4-27e5-4296-95ef-06c84fc6c0fb%40googlegroups.com.
>For more options, visit https://groups.google.com/d/optout.

-- 
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/E13AB7A0-169D-447E-A951-F3BB32AB9182%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.


Re: Is guice-persist alive?

2017-07-25 Thread Stephan Classen

Cool to see my code still is alive :)

My offer still stands. I can help anybody who wants to use it.
If it helps I can also migrate it to my github account so you have an 
issue tracker and can create pull requests




On 25.07.2017 11:34, Asier wrote:

Hi

There's a fork of onami-persist, which has some enhacements. We are not using
it, but thinking about to migrate from onami-persist to "tocktix"-persist.

https://github.com/tocktix/onami-persist

We miss an open-session-in-view library with support, but hey, your library
works very well for us and we don't have the knowledge to maintain it so
thanks for releasing it.

This is another matter, but lack of extensions make us think about leaving
Guice and start with Spring, as most projects are using it because of its rich
ecosystem.

Regards

El miércoles, 5 de abril de 2017 0:52:48 (CEST) Stephan Classen escribió:

Hard to say

I'm not working for Google but last time I asked this question it
remained unanswered.
Last real development I see in 2011. After this only whitespace
refactorings.

The Issues in the issue tracker are also open since a very long time.

Because of this I wrote my own persistence extension for guice. This
project has never attracted much attention and is by now also kind of
abandoned. If you decide to resurrect it, I will gladly give you a hand
src: https://svn.apache.org/viewvc/onami/trunk/persist/
doc: https://onami.apache.org/persist/index.html

On 05.04.2017 00:16, Serega Sheypak wrote:

Hi, is it alive? I made it work, looks nice, but:
1. I need Finder stuff. Seems like warp is dead?
2. Will google-persist get new features?




--
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/d2272c1e-16a9-093f-3083-7041a6c02b1c%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.


Re: Profiling Modules

2017-07-01 Thread Stephan Classen
While Guice AOP is a nice and cool feature and I love to use it for certain use 
cases I also found that it becomes a performance issue if used to heavely.
Because of this and the limitations you mention in your question I recommend 
using a classic profiler to investigate performance issues. For a list of 
populare ones see 
https://zeroturnaround.com/rebellabs/top-5-java-profilers-revealed-real-world-data-with-visualvm-jprofiler-java-mission-control-yourkit-and-custom-tooling/

Also let me add the following advice:
- keep your modules dumb. Having little to none logic in your guice modules is 
the way to go. This increases performanc and also helps to reason about what is 
happening when in your application.
- singeltons are by far the fastest objects to inject. Try to make your 
dependencies state less and immutable. Then you can turn them into singeltons 
making them fast to inject.

Good luck. Performance issues can be very hard to track down. But sometimes if 
you found the bottleneck a small change can make a big difference.

Am 30. Juni 2017 23:53:01 MESZ schrieb Max Aller :
>We're trying to improve performance of our Guice Modules, and to do
>that 
>we'd like to figure out how long Guice is taking calling our @Provides 
>methods. `bindListener` *almost* lets us do that, but it only works for
>
>objects instantiated with Guice, not Guice modules themselves, of
>course, 
>and even if that worked, it doesn't surface any timing information.
>Does 
>anyone have a clever AOP way figuring out how fast or slow code in 
>user-specified Modules is taking?
>
>Thanks,
>Max
>
>-- 
>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 google-guice+unsubscr...@googlegroups.com.
>To post to this group, send email to google-guice@googlegroups.com.
>Visit this group at https://groups.google.com/group/google-guice.
>To view this discussion on the web visit
>https://groups.google.com/d/msgid/google-guice/3b0a86dc-d1c1-43f6-806d-0694b6c613bb%40googlegroups.com.
>For more options, visit https://groups.google.com/d/optout.

-- 
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/EDB9F815-1DDD-4B47-9ACF-71E5048AD102%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.


Re: Guice module integration issue with REST

2017-04-24 Thread Stephan Classen
I think you problem is that you are mixing spring an guice (in an 
inappropriate way).


I reproduced your above example (by the way, can you tell me from which 
library you use Worker and WorkerRepository?).


The code is missing the binding for the worker. I added it.

Next problem is the @Autowire. This is a spring annotation and Guice 
will not react to it.
If you replace it with @Inject the sample code is working as expected. 
(By the way I would recommend to favor constructor injection over field 
injection).


If this does not help. I would suggest you create a minimal reproducible 
case and publish it on a github repo so we can fiddle around with it.




On 23.04.2017 11:04, pradrone dev wrote:


Guice module integration issue with REST I have define one AOP guice 
based module, but when I tried to integrate with REST code, 
methodInvocation.proceed retun null. What might be best way to solve 
this issue.


Define AOP Guice based module as below

@Retention (RetentionPolicy.RUNTIME)
@Target (ElementType.METHOD)
@interface  NotOnWeekends {}
public class WeekendBlocker implements MethodInterceptor {

public Object invoke(MethodInvocation invocation) throws Throwable {

|Calendar today = new GregorianCalendar(); if 
(today.getDisplayName(DAY_OF_WEEK, LONG, ENGLISH).startsWith("S")) { 
throw new IllegalStateException( invocation.getMethod().getName() + " 
not allowed on weekends!"); } return invocation.proceed(); |


}

}

public class NotOnWeekendsModule extends AbstractModule {
protected void configure() {

|bindInterceptor(Matchers.any(), 
Matchers.annotatedWith(NotOnWeekends.class), new WeekendBlocker()); |


}
}

But I tried to Integrate this with my REST API

|public class WorkerBean implements Worker { @Autowired private 
WorkerRepository workerRepository; @Override @NotOnWeekends public 
Collection findAll() { Collection workers = 
workerRepository.findAll(); return workers; } |


@RestController 
public class WorkerController {

|@RequestMapping( value = "/api/workers", method = RequestMethod.GET, 
produces = MediaType.APPLICATION_JSON_VALUE) public 
ResponseEntity getWorkers() { Worker worker = 
Guice.createInjector(new 
NotOnWeekendsModule()).getInstance(Worker.class); Collection 
worker = worker.findAll(); // return null  }|

--
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 google-guice+unsubscr...@googlegroups.com 
.
To post to this group, send email to google-guice@googlegroups.com 
.

Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/cb641bf9-7ada-4021-aa73-20cfe1e15787%40googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.


--
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/33550657-d897-01db-58c2-e9d99c50b8b2%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.


Re: Guice module integration issue with REST

2017-04-25 Thread Stephan Classen
Sorry I have no Spring experience what so ever. So I guess I will not be 
of any help here.


Hopefully someone else can jump in.



On 25.04.2017 09:49, pradrone dev wrote:
Can you please guide me steps how to Integrate Guice with Spring ? 
Tried few more stuff but it is unclear ?


For your reference attaching sample problem. Waiting for you 
suggestion and inputs.


Guice Integration .
//Collection greetings = greetingService.findAll();

GreetingServiceBean greetingservicebean = 
InjectorInstance.getInstance().getInstance(GreetingServiceBean.class);


Collection greetings = greetingservicebean.findAll();

Thanks Alot,

On Monday, 24 April 2017 22:38:50 UTC+5:30, scl wrote:

Set a breakpoint or add a log statement at the end of the
WorkerBean.findAll() to see what this method returns and if it is
differen from what you see returned by the
methodInvocation.proceed call

Am 24. April 2017 17:56:21 MESZ schrieb pradrone dev
:

Thanks it does work but now methodInvocation.proceed return []
(empty object) where it should return list values.
Any idea for such behaviour ?


On Sunday, 23 April 2017 14:34:53 UTC+5:30, pradrone dev wrote:

Guice module integration issue with REST I have define one
AOP guice based module, but when I tried to integrate with
REST code, methodInvocation.proceed retun null. What might
be best way to solve this issue.

Define AOP Guice based module as below

@Retention
(RetentionPolicy.RUNTIME)
@Target (ElementType.METHOD)
@interface  NotOnWeekends {}
public class WeekendBlocker implements MethodInterceptor {

public Object invoke(MethodInvocation invocation) throws
Throwable {

|Calendar today = new GregorianCalendar(); if
(today.getDisplayName(DAY_OF_WEEK, LONG,
ENGLISH).startsWith("S")) { throw new
IllegalStateException( invocation.getMethod().getName() +
" not allowed on weekends!"); } return invocation.proceed(); |

}

}

public class NotOnWeekendsModule extends AbstractModule {
protected void configure() {

|bindInterceptor(Matchers.any(),
Matchers.annotatedWith(NotOnWeekends.class), new
WeekendBlocker()); |

} }

But I tried to Integrate this with my REST API

|public class WorkerBean implements Worker { @Autowired
private WorkerRepository workerRepository; @Override
@NotOnWeekends public Collection findAll() {
Collection workers = workerRepository.findAll();
return workers; } |

@RestController  public
class WorkerController {

|@RequestMapping( value = "/api/workers", method =
RequestMethod.GET, produces =
MediaType.APPLICATION_JSON_VALUE) public
ResponseEntity getWorkers() { Worker
worker = Guice.createInjector(new
NotOnWeekendsModule()).getInstance(Worker.class);
Collection worker = worker.findAll(); // return
null  }|

-- 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 
google-guice+unsubscr...@googlegroups.com 
. To post to this 
group, send email to google-guice@googlegroups.com 
. Visit this group at 
https://groups.google.com/group/google-guice. To view this discussion 
on the web visit 
https://groups.google.com/d/msgid/google-guice/ee30385f-bf60-47ba-af5e-4f5af1bdfe2e%40googlegroups.com 
. 
For more options, visit https://groups.google.com/d/optout. 


--
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/b27d492f-244c-7ba2-c189-7603c3d539e6%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.


Re: MethodInterceptor for class extending ebean Model not working

2017-05-15 Thread Stephan Classen
Be aware that AOP adds overhead onto these operations. I had to revert 
usage of AOP in a project once where we some of the methods were called 
very frequent. In most cases it is no problem but if you application 
will make heavy use of these getters and setters it could become noticeable.


To your concrete problem:

Guice can only intercept method on objects it has created. This means if 
you want to be able to intercept methods on objects which are of type 
Company (or a subclass of it) then you must use Guice to create this 
object. Either by having Guice inject it into your code or by calling 
injector.getInstance().




On 15.05.2017 17:27, shishir gowda wrote:

No, I am not injecting instances of Company into classes.
I am actually trying intercept methods of Company which is extending 
Ebean Model.

I have tried AspectJ too, but with little luck.
Ack wrt foo.

I am basically trying to write a cache layer, which uses redis as 
cache, and ebean as backend, so the plan is to intercept 
getters/setters of ebean model, and perform cache ops.



On Monday, 15 May 2017 17:09:53 UTC+5:30, Thomas Broyer wrote:

Are you really using Guice to inject instances of Company into
your classes? Guice will only intercept methods on objects that it
instantiates itself (see
https://github.com/google/guice/wiki/AOP#limitations
) If you
want broader use of AOP, you'll have to use another tool, such as
AspectJ.
Oh, and I see your foo method is 'static', that's not going to
work either, as it cannot be overridden.

On Monday, May 15, 2017 at 1:30:07 PM UTC+2, shishir gowda wrote:

I have ebean entity:

@Entity
public class Company extends Model {
@Id
 public Long id;
 static void foo {
   Logger.info("in company");
 }
...
}

A guice Module defining the interceptor:

public class Module extends AbstractModule {
protected void configure() {

CacheImpl cache = new CacheImpl();
requestInjection(cache);
bindInterceptor(subclassesOf(Company.class),
any(), cache);

}
}

This does not intercept any calls made to Company (foo(),
save(),get(), find()..)

When I change bindInterceptor to a class extending Play
Controller, it works by intercepting the calls.

Can some one tell me if I am missing anything?

my methodInterceptor:

@Component
public class CacheImpl implements MethodInterceptor {

public Object invoke(MethodInvocation method) throws
Throwable{
Logger.info("class {}",method.getClass().getName());
if (method.getMethod().getName() == "list") {
Logger.info("interceptor in list");
} else {
Logger.info("in interceptor for  {}",
method.getMethod().getName());

}
return method.proceed();

}
}

--
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 google-guice+unsubscr...@googlegroups.com 
.
To post to this group, send email to google-guice@googlegroups.com 
.

Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/e7028ea4-0a6f-48ea-9a94-e6fcd75273c6%40googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.


--
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/97a37734-23aa-b070-18f8-00f192ca9383%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.


Re: RequestScoped and background threads

2017-06-13 Thread Stephan Classen
The request scope uses internally a thread local. So when you run stuff in a 
background thread you are not in a request as guice sees it. You need to call 
the same method as the mentioned filter does inorder to begin and end a request.

Am 13. Juni 2017 20:21:00 MESZ schrieb Arun Thirupathi 
:
>In one of our projects we are binding an implementation in
>RequestScope. 
>But when this is run from a background thread, it fails with the
>exception 
>below. 
>
>Error in custom provider, com.google.inject.OutOfScopeException: Cannot
>
>access scoped object.
>Either we are not currently inside an HTTP Servlet request, or you may
>have 
>forgotten to apply
>com.google.inject.servlet.GuiceFilter as a servlet filter for this
>request.
>
>Can I bind different implementations based on the scope ? I want to
>provide 
>one implementation in RequestScope and other implementation in another 
>scope.
>
>Is there a way to configure Guice to ignore these errors silently. 
>
>Currently I am thinking of the naive way of, try/catch all the usage of
>
>this object, which is far too many and there are new interactions with
>this 
>object.
>
>I run my project inside Google App Engine, if that matters.
>
>Thanks,
>Arun.
>
>-- 
>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 google-guice+unsubscr...@googlegroups.com.
>To post to this group, send email to google-guice@googlegroups.com.
>Visit this group at https://groups.google.com/group/google-guice.
>To view this discussion on the web visit
>https://groups.google.com/d/msgid/google-guice/2238b96f-0b42-408b-8bbb-08d58f3a0d1a%40googlegroups.com.
>For more options, visit https://groups.google.com/d/optout.

-- 
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/EA5D362D-7206-443F-9AA1-CC261370124E%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.


Re: Is guice-persist alive?

2017-09-12 Thread Stephan Classen

So a quick search on github finds 3 forks of onami-persist.

https://github.com/tocktix/onami-persist
https://github.com/FingolfinTEK/onami-persist
https://github.com/davidsowerby/krail-jpa

Is there interest in joining forces? If so I would suggest I start a new 
github organization for onami-persist and scratch together the history 
from my local repo (the apache SVN is not very helpfull, as all onami 
sub-projects shared a single SVN).
As a next step we can bring in the existing additions/features/bugfixes 
from the different forks.


Of course I will add all contributors to the organization.

What do you think?


On 10.09.2017 12:08, David Sowerby wrote:
On the general topic of persistence for Guice - I did integrate 
onami-persist as a persistence component 
<https://github.com/davidsowerby/krail-jpa> for my own project 
<https://github.com/davidsowerby/krail> quite a while ago - there have 
been a few downloads, though I cannot claim it is a raging success!


However, I am getting back to developing my work further and would not 
want to lose what seems to be the only Guice based persistence 
available - I would certainly like to see onami-persist kept alive if 
that's possible


On Saturday, 9 September 2017 09:39:05 UTC+1, Asier wrote:

Hi Stephan


(Sorry for the delay)


Our main concern with onami-persist is related to this:

"AOP synthetic warnings after Java 8 upgrade" -
https://groups.google.com/

forum/#!topic/google-guice/-DH5fBD7M30


The "easy" patch seems the one pointed in the e-mail but, if I had

understanded the PersistenceModule#configurePersistenceUnits
method and bind a

custom method matcher to exclude synthetic methods. Something like
this (bolded text):


*private static final class TransactionMethodMatcher extends
AbstractMatcher {*

**

*@Override*

**

*public boolean matches(final Method method) {*

**

*return method.isAnnotationPresent(Transactional.class) &&
!method.isSynthetic();*

**

*}*

**

*}*

**


/**

* Configures the persistence units.

*/

private void configurePersistenceUnits() {

this.configurePersistence();

this.bind(PersistenceFilter.class).to(PersistenceFilterImpl.class)
.in(Scopes.SINGLETON);


final AllPersistenceUnits allPersistenceUnits = new
AllPersistenceUnits();

this.requestInjection(allPersistenceUnits);

this.bind(AllPersistenceServices.class).toInstance(allPersistenceUnits);

this.bind(AllUnitsOfWork.class).toInstance(allPersistenceUnits);


for (final PersistenceUnitModuleConfiguration config :
this.configurations) {

final TxnInterceptor txnInterceptor = new TxnInterceptor();


this.install(new PersistenceUnitModule(config, txnInterceptor,
allPersistenceUnits));


*this.bindInterceptor(any(), new TransactionMethodMatcher(), *

**

*txnInterceptor);*

**

*this.bindInterceptor(annotatedWith(Transactional.class), new *

**

*TransactionMethodMatcher(), txnInterceptor);*

}

}


But this is a bit overkill because basically we are excluding all
the synthetic methods - perhaps the best workaround should be able
to give a class matcher to this method with the classes to exclude?


Regards
El martes, 25 de julio de 2017, 14:45:05 (UTC+2), scl escribió:

Cool to see my code still is alive :)

My offer still stands. I can help anybody who wants to use it.
If it helps I can also migrate it to my github account so you
have an
issue tracker and can create pull requests



On 25.07.2017 11:34, Asier wrote:
> Hi
>
> There's a fork of onami-persist, which has some enhacements.
We are not using
> it, but thinking about to migrate from onami-persist to
"tocktix"-persist.
>
> https://github.com/tocktix/onami-persist
<https://github.com/tocktix/onami-persist>
>
> We miss an open-session-in-view library with support, but
hey, your library
> works very well for us and we don't have the knowledge to
maintain it so
> thanks for releasing it.
>
> This is another matter, but lack of extensions make us think
about leaving
> Guice and start with Spring, as most projects are using it
because of its rich
> ecosystem.
    >
    > Regards
>
> El miércoles, 5 de abril de 2017 0:52:48 (CEST) Stephan
Classen escribió:
>> Hard to say
>>
>> I'm not working for Google but last time I asked this
question it
>> remained unanswered.
>> Last real development I see in 2011. After this only
whitespace
>> refacto

Re: Is guice-persist alive?

2017-09-12 Thread Stephan Classen
Agree the more collaborators and users we attract the better. Lack of 
users and collaborators was the reason why apache onami was discontinued 
and went to attic.



On 12.09.2017 10:47, David Sowerby wrote:
I agree about the single focus - I wasn't suggesting diluting the 
purpose of the library - I was thinking more that those who have 
developed libraries based on guice-persist who may be wondering about 
being dependent on it, and possibly also willing to collaborate


On 12 September 2017 at 09:43, Stephan Classen <st.clas...@gmx.ch 
<mailto:st.clas...@gmx.ch>> wrote:


Maybe in a second phase. I would first concentrate on pulling the
different efforts for onami-persist together. But personally I
prefer to focus on one responsibility with such libraries. And I
see the main responsibility of onami-persist in providing JPA and
JTA integration for guice.



On 12.09.2017 10:38, David Sowerby wrote:

Seems like a good plan to me. Persistence isn't my strong suit,
but I am certainly happy to help, and contribute where I can.

Do you think it  is worth contacting people who have Guice
integrations with guice-persist, as that seems to be defunct? 
I'm thinking of projects like this one

<https://github.com/xvik/guice-persist-orient>

On 12 September 2017 at 09:01, Stephan Classen <st.clas...@gmx.ch
<mailto:st.clas...@gmx.ch>> wrote:

So a quick search on github finds 3 forks of onami-persist.

https://github.com/tocktix/onami-persist
<https://github.com/tocktix/onami-persist>
https://github.com/FingolfinTEK/onami-persist
<https://github.com/FingolfinTEK/onami-persist>
https://github.com/davidsowerby/krail-jpa
<https://github.com/davidsowerby/krail-jpa>

Is there interest in joining forces? If so I would suggest I
start a new github organization for onami-persist and scratch
together the history from my local repo (the apache SVN is
not very helpfull, as all onami sub-projects shared a single
SVN).
As a next step we can bring in the existing
additions/features/bugfixes from the different forks.

Of course I will add all contributors to the organization.

What do you think?


On 10.09.2017 12:08, David Sowerby wrote:

On the general topic of persistence for Guice - I did
integrate onami-persist as a persistence component
<https://github.com/davidsowerby/krail-jpa> for my own
project <https://github.com/davidsowerby/krail> quite a
while ago - there have been a few downloads, though I cannot
claim it is a raging success!

However, I am getting back to developing my work further and
would not want to lose what seems to be the only Guice based
persistence available - I would certainly like to see
onami-persist kept alive if that's possible

On Saturday, 9 September 2017 09:39:05 UTC+1, Asier wrote:

Hi Stephan


(Sorry for the delay)


Our main concern with onami-persist is related to this:

"AOP synthetic warnings after Java 8 upgrade" -
https://groups.google.com/

forum/#!topic/google-guice/-DH5fBD7M30


The "easy" patch seems the one pointed in the e-mail
but, if I had

understanded the
PersistenceModule#configurePersistenceUnits method and
bind a

custom method matcher to exclude synthetic methods.
Something like this (bolded text):


*private static final class TransactionMethodMatcher
extends AbstractMatcher {*

**

*@Override*

**

*public boolean matches(final Method method) {*

**

*return method.isAnnotationPresent(Transactional.class)
&& !method.isSynthetic();*

**

*}*

**

*}*

**


/**

* Configures the persistence units.

*/

private void configurePersistenceUnits() {

this.configurePersistence();

this.bind(PersistenceFilter.class).to(PersistenceFilterImpl.class)
.in(Scopes.SINGLETON);


final AllPersistenceUnits allPersistenceUnits = new
AllPersistenceUnits();

this.requestInjection(allPersistenceUnits);


this.bind(AllPersistenceServices.class).toInstance(allPersistenceUnits);

this.bind(AllUnitsOfWork.class).toInstance(allPersistenceUnits);


for (final PersistenceUnitModuleConfiguration config :
this.configurations) {

final TxnInterceptor txnInterceptor = new TxnInterceptor();


this.install(new PersistenceUnitModule(config

Re: Is guice-persist alive?

2017-09-12 Thread Stephan Classen
Maybe in a second phase. I would first concentrate on pulling the 
different efforts for onami-persist together. But personally I prefer to 
focus on one responsibility with such libraries. And I see the main 
responsibility of onami-persist in providing JPA and JTA integration for 
guice.




On 12.09.2017 10:38, David Sowerby wrote:
Seems like a good plan to me.  Persistence isn't my strong suit, but I 
am certainly happy to help, and contribute where I can.


Do you think it  is worth contacting people who have Guice 
integrations with guice-persist, as that seems to be defunct? I'm 
thinking of projects like this one 
<https://github.com/xvik/guice-persist-orient>


On 12 September 2017 at 09:01, Stephan Classen <st.clas...@gmx.ch 
<mailto:st.clas...@gmx.ch>> wrote:


So a quick search on github finds 3 forks of onami-persist.

https://github.com/tocktix/onami-persist
<https://github.com/tocktix/onami-persist>
https://github.com/FingolfinTEK/onami-persist
<https://github.com/FingolfinTEK/onami-persist>
https://github.com/davidsowerby/krail-jpa
<https://github.com/davidsowerby/krail-jpa>

Is there interest in joining forces? If so I would suggest I start
a new github organization for onami-persist and scratch together
the history from my local repo (the apache SVN is not very
helpfull, as all onami sub-projects shared a single SVN).
As a next step we can bring in the existing
additions/features/bugfixes from the different forks.

Of course I will add all contributors to the organization.

What do you think?


On 10.09.2017 12:08, David Sowerby wrote:

On the general topic of persistence for Guice - I did integrate
onami-persist as a persistence component
<https://github.com/davidsowerby/krail-jpa> for my own project
<https://github.com/davidsowerby/krail> quite a while ago - there
have been a few downloads, though I cannot claim it is a raging
success!

However, I am getting back to developing my work further and
would not want to lose what seems to be the only Guice based
persistence available - I would certainly like to see
onami-persist kept alive if that's possible

On Saturday, 9 September 2017 09:39:05 UTC+1, Asier wrote:

Hi Stephan


(Sorry for the delay)


Our main concern with onami-persist is related to this:

"AOP synthetic warnings after Java 8 upgrade" -
https://groups.google.com/

forum/#!topic/google-guice/-DH5fBD7M30


The "easy" patch seems the one pointed in the e-mail but, if
I had

understanded the PersistenceModule#configurePersistenceUnits
method and bind a

custom method matcher to exclude synthetic methods. Something
like this (bolded text):


*private static final class TransactionMethodMatcher extends
AbstractMatcher {*

**

*@Override*

**

*public boolean matches(final Method method) {*

**

*return method.isAnnotationPresent(Transactional.class) &&
!method.isSynthetic();*

**

*}*

**

*}*

**


/**

* Configures the persistence units.

*/

private void configurePersistenceUnits() {

this.configurePersistence();

this.bind(PersistenceFilter.class).to(PersistenceFilterImpl.class)
.in(Scopes.SINGLETON);


final AllPersistenceUnits allPersistenceUnits = new
AllPersistenceUnits();

this.requestInjection(allPersistenceUnits);

this.bind(AllPersistenceServices.class).toInstance(allPersistenceUnits);

this.bind(AllUnitsOfWork.class).toInstance(allPersistenceUnits);


for (final PersistenceUnitModuleConfiguration config :
this.configurations) {

final TxnInterceptor txnInterceptor = new TxnInterceptor();


this.install(new PersistenceUnitModule(config,
txnInterceptor, allPersistenceUnits));


*this.bindInterceptor(any(), new TransactionMethodMatcher(), *

**

*txnInterceptor);*

**

*this.bindInterceptor(annotatedWith(Transactional.class), new *

**

*TransactionMethodMatcher(), txnInterceptor);*

}

}


But this is a bit overkill because basically we are excluding
all the synthetic methods - perhaps the best workaround
should be able to give a class matcher to this method with
the classes to exclude?


Regards
El martes, 25 de julio de 2017, 14:45:05 (UTC+2), scl escribió:

Cool to see my code still is alive :)

My offer still stands. I can help anybody who wants to
use it.
If it helps I can also migrate it to my github account so
you have an
issue tracker 

Re: Guice#bindMembers() and listeners initialized by the class itself cause NPEs

2017-11-28 Thread Stephan Classen
First of all I would not inject a model. Model classes are not meant to 
be handled with DI.
Second you can use assisted injection to use constructor injection if 
you have both parameters and dependencies in a constructor.


Non of the above helps clarify you question. But maybe it helps you 
think about your design.


Regarding your code:
Guice has no hidden mechanism which magically does things if you do not 
ask for it.
So after your framework has called injectMembers() guice will not change 
the controller unless your ask it to do it again.

I assume there is no other code which will later set the model back to null.

This boils it down to one most likely scenario"

Something happens before your framework calls injectMembers(). This 
something triggers the listener.propertyChange() method.
To be able to debug this a little better I would suggest that you add a 
setter for model and annotate the setter method with @Inject instead of 
the field.
This way you can add a breakpoint (and/or log output) to the setter. Do 
the same with the init() and the propertyChange() method and watch 
carefully in which order they are called.


Another less likely scenario is that you have more than one instance of 
MyController. In one instance you have a model and in the other instance 
model is null.


If you code is open source I can have a look into the issue




On 28.11.2017 11:54, Evgeny Chesnokov wrote:

Hi all!


I'm having a problem with Guice injection in one particular 
corner-case. I use Guice to inject model to the controller instances 
that are parameterized in the constructor, hence I'm using 
#bindMembers() and not the constructor injection. It seems that if a 
model callback field in the controller instance was instantiated 
before #bindMembers() call, then it fails to see the injected model 
classes. Here's a quick sample:


class MyController extends MyAbstractController {
  private int param;

  @Inject private MyModel model;

  private /*could also be final*/ PropertyChangeListener listener = 
new PropertyChangeListener() {

      @Override public void propertyChange( PropertyChangeEvent evt ) {
          model.doStuff(); *// fails with NPE because model is null!*
      }
  };

  public MyController(int param) {
    this.param = param;
  }

  // Injector#injectMembers(myController) gets called by my framework 
and then myController#init()

  public init() {
model.addPropertyChangeListener("prop", listener); // *does NOT fail* 
with NPE during initialization

  }
}

So I've been wondering which internal mechanims I keep missing that 
allow for this kind of a strange behaviour? Any ideas welcome.



Thanks in advance,
Evgeny.
--
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 google-guice+unsubscr...@googlegroups.com 
.
To post to this group, send email to google-guice@googlegroups.com 
.

Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/e66a5a5e-5fad-4605-9ae7-71b2634212d0%40googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.


--
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/e043fea4-5298-0774-fef2-7001138a453f%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.


Re: current status of Guice

2017-11-22 Thread Stephan Classen

Guice never had a lot of activity in the open source area.
There was once a Apache project (Onami) which became abandoned a few 
years ago.


I feel Google is not very interested in a vivid community around Guice. 
Maybe they have enough internal factors driving Guice and do not want 
too many community driven changes which may conflict with their internal 
needs.


Never the less Guice is a very mature and stable piece of software.

As you mentioned the two alternatives are Spring and Dagger.

Spring is a framework where as Guice is a library. This means with 
Spring you not only get dependency injection but can easily add many 
more functionalities.


Dagger on the other end is focusing on performance over functionality. 
Also they have a annotation processor which does compile time 
validation. As a consequence of this they cannot offer all the 
functionalities Guice does (like injecting unannotated classes with an 
empty default constructor).


Hope this helps, and as always we would like to hear more about how the 
future of Guice is seen by Google ;)



On 22.11.2017 15:10, Ron wrote:

Hi All

It seems the activities around Guice, both in terms of the discussions 
here and the commits in the Github repo seems to have slowed right down.


What is the current status, are people moving away?

I successfully delivered a number of projects using Guice in it's 
early days, around 6 years ago. Then I moved away from Java but came 
back to it last year. The project I picked up had code running on 
Struts and Spring, I ripped that all out and put in a simple action 
based framework on top of Guice. The final result had 5 times original 
functionality with at least 50% reduction in dependencies and a slight 
reduction in total code base size. Also zero XML based configuration. 
(Not saying that this will always be the case, a lot is probably due 
to the state of the current code, and the project requirements)


I'm about to embark on a new project and would be keen to use the same 
framework again.


However, I'm concerned as to why activities have completely died down, 
are people moving away? If so to what? Dagger? Spring?


Thanks
Ron

--
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 google-guice+unsubscr...@googlegroups.com 
.
To post to this group, send email to google-guice@googlegroups.com 
.

Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/8c56151c-e895-481a-9384-d85842fb5590%40googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.


--
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/6332640f-180a-7710-a95c-7d75478b29aa%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.


Re: When is the google guice injector garbage collected?

2017-11-17 Thread Stephan Classen
They will also get garbage collected unless they have been injected somewhere. 
Then they only get garbage collected once the objects holding these references 
are also garbage collectable.
In short. Guice does not change any behavior of the GC. The injector and all 
created instances (singleton or not) will get collected when they are not 
reachable. Just like any other java object.
And because this question may arise as a follow up:
Singletons are not global singletons. They are singletons per injector 
instance. So guice will not hold a reference in some static field.

Am 17. November 2017 06:54:59 MEZ schrieb vishesh gupta 
:
>
>
>When we are no more referencing a google guice injector in the
>application, 
>when will be the resources held by the injector, like Singletons,
>released 
>or garbage collected?
>
>To illustrated more, consider this code snippet:
>
>public void someFunction() {Injector injector =
>Guice.createInjector(new DataStoreBindings());DataTransactor transactor
>= 
>injector.getInstance(DataInfoTransactor.class);
>transactor.doSomething();}
>
>Some singleton bindings are also created by this injector. When this 
>function ends the Injector instance will go out of scope and
>application 
>has no way to refer this Injector again.
>
>I want to know, if the injector will be garbage collected? If yes, then
>
>what will happen to the singletons held by the injector?
>
>-- 
>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 google-guice+unsubscr...@googlegroups.com.
>To post to this group, send email to google-guice@googlegroups.com.
>Visit this group at https://groups.google.com/group/google-guice.
>To view this discussion on the web visit
>https://groups.google.com/d/msgid/google-guice/b2ec2692-0833-45b4-a85d-23adb6900ae4%40googlegroups.com.
>For more options, visit https://groups.google.com/d/optout.

-- 
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/17D931C3-5136-4C2D-ACAC-3B23833B68F6%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.


Re: NullPointerException in JpaPersistService

2017-12-04 Thread Stephan Classen

This is what I mentioned before.

You cannot use any of the JPA stuff until PersistService.start() has 
been called.

This will be called by the PersistFilter.init().
So you have to wait with the appLifeCycle.init() until after the init() 
method of PersistFilter




On 04.12.2017 16:58, Diogo Luzzardi de Carvalho wrote:
Unfortunately it is not. I notice that when I change my code to do the 
following:

|
injector = Guice.createInjector(new 
MainModule(String.format("%s/WEB-INF/app", 
getServletContext().getRealPath("/")), getServletContext()));

UnitOfWork unitOfWork = injector.getInstance(UnitOfWork.class);
System.out.println(unitOfWork);
unitOfWork.begin();
try {
appLifeCycle = injector.getInstance(AppLifeCycle.class);
appLifeCycle.init(getServletContext());
} finally {
unitOfWork.end();
}

return injector;
|

 The injector was able to inject the UnitOfWork but when I call the 
method unitOfWork.begin() the exception occurs at line 77 of the 
JpaPersistService.


On Monday, December 4, 2017 at 1:24:10 PM UTC-2, scl wrote:

Is this an open source project?
If sou you could point me to the repo and I can have a look.



On 04.12.2017 16:22, Diogo Luzzardi de Carvalho wrote:

Hi,

I tried both of your solutions, and the nullpointer keeps happen.
Also I debug the application and I installed the JpaPersistModule
before I try to run the code when the exception happens.

regards
Diogo

On Friday, December 1, 2017 at 8:42:53 PM UTC-2, scl wrote:

A second cause could be that the PersistenceService has not
been started yet.
The persistence service is started by the PersistFiler.init()
method.

Unfortunately there is no way of checking if the
PersistanceService is already started. And trying to start it
twice will cause an exception the be thrown.


So my advice:
Make sure to delay the accessing of the DB until after the
PersistFiler.init() method and wrap your code in a UnitOfWork.
The simplest trick is to register another ServletFilter after
the PersistFilter and place your code in the init() method of
this filter...


You may also have a look at Onami Persist which is an
alternative implementation (but without @Finder)



On 01.12.2017 23:25, Diogo Luzzardi de Carvalho wrote:



On Friday, December 1, 2017 at 8:18:46 PM UTC-2, Diogo
Luzzardi de Carvalho wrote:

|

java.lang.NullPointerException


at

com.google.inject.persist.jpa.JpaPersistService.begin(JpaPersistService.java:77)


at

com.google.inject.persist.jpa.JpaLocalTxnInterceptor.invoke(JpaLocalTxnInterceptor.java:53)


at

com.app.guice.AppGuiceServletContextListener.contextInitialized(AppGuiceServletContextListener.java:60)


at

org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:548)


at
org.mortbay.jetty.servlet.Context.startContext(Context.java:136)


at

org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1234)


at

org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)


at

org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:460)


at

org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)


at

org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)


at org.mortbay.jetty.Server.doStart(Server.java:222)


at

org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)


at com.app.Start.start(Start.java:126)


at com.app.Start.main(Start.java:194)

|

Follows my servlet context listener:
|

package com.app.guice;


import javax.servlet.ServletContext;

import javax.servlet.ServletContextEvent;


import org.mortbay.jetty.Server;


import com.app.setup.AppLifeCycle;

import com.google.inject.Guice;

import com.google.inject.Injector;

import com.google.inject.Provides;

import com.google.inject.Singleton;

import
com.google.inject.servlet.GuiceServletContextListener;


public class AppGuiceServletContextListener extends
GuiceServletContextListener {


private AppLifeCycle appLifeCycle;


private Server server;


private ServletContext servletContext;


private Injector injector;


public AppGuiceServletContextListener(Server server) {

super();

this.server = server;

}


@Override

public void 

Re: NullPointerException in JpaPersistService

2017-12-04 Thread Stephan Classen

Is this an open source project?
If sou you could point me to the repo and I can have a look.



On 04.12.2017 16:22, Diogo Luzzardi de Carvalho wrote:

Hi,

I tried both of your solutions, and the nullpointer keeps happen. Also 
I debug the application and I installed the JpaPersistModule before I 
try to run the code when the exception happens.


regards
Diogo

On Friday, December 1, 2017 at 8:42:53 PM UTC-2, scl wrote:

A second cause could be that the PersistenceService has not been
started yet.
The persistence service is started by the PersistFiler.init() method.

Unfortunately there is no way of checking if the
PersistanceService is already started. And trying to start it
twice will cause an exception the be thrown.


So my advice:
Make sure to delay the accessing of the DB until after the
PersistFiler.init() method and wrap your code in a UnitOfWork.
The simplest trick is to register another ServletFilter after the
PersistFilter and place your code in the init() method of this
filter...


You may also have a look at Onami Persist which is an alternative
implementation (but without @Finder)



On 01.12.2017 23:25, Diogo Luzzardi de Carvalho wrote:



On Friday, December 1, 2017 at 8:18:46 PM UTC-2, Diogo Luzzardi
de Carvalho wrote:

|

java.lang.NullPointerException


at

com.google.inject.persist.jpa.JpaPersistService.begin(JpaPersistService.java:77)


at

com.google.inject.persist.jpa.JpaLocalTxnInterceptor.invoke(JpaLocalTxnInterceptor.java:53)


at

com.app.guice.AppGuiceServletContextListener.contextInitialized(AppGuiceServletContextListener.java:60)


at

org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:548)


at
org.mortbay.jetty.servlet.Context.startContext(Context.java:136)


at

org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1234)


at

org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)


at
org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:460)


at
org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)


at

org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)


at org.mortbay.jetty.Server.doStart(Server.java:222)


at
org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)


at com.app.Start.start(Start.java:126)


at com.app.Start.main(Start.java:194)

|

Follows my servlet context listener:
|

package com.app.guice;


import javax.servlet.ServletContext;

import javax.servlet.ServletContextEvent;


import org.mortbay.jetty.Server;


import com.app.setup.AppLifeCycle;

import com.google.inject.Guice;

import com.google.inject.Injector;

import com.google.inject.Provides;

import com.google.inject.Singleton;

import com.google.inject.servlet.GuiceServletContextListener;


public class AppGuiceServletContextListener extends
GuiceServletContextListener {


private AppLifeCycle appLifeCycle;


private Server server;


private ServletContext servletContext;


private Injector injector;


public AppGuiceServletContextListener(Server server) {

super();

this.server = server;

}


@Override

public void contextDestroyed(ServletContextEvent ctx) {

super.contextDestroyed(ctx);

if(appLifeCycle!= null) {

appLifeCycle.destroy();

}

}


@Override

public void contextInitialized(ServletContextEvent
servletContextEvent) {

servletContext = servletContextEvent.getServletContext();

super.contextInitialized(servletContextEvent);


appLifeCycle = injector.getInstance(AppLifeCycle.class);

appLifeCycle.init(servletContext);

}


@Provides

@Singleton

Server provideServer(Injector injector) {

final Server server = this.server;

injector.injectMembers(server);

returnserver;

}


@Override

protected Injector getInjector() {

System.out.println(servletContext);

if (injector == null)

injector = Guice.createInjector(new
MainModule(String.format("%s/WEB-INF/app",
servletContext.getRealPath("/")), servletContext));

returninjector;

}

}

|

-- 
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 google-guice...@googlegroups.com .
To post to this group, send email to google...@googlegroups.com
 

Re: NullPointerException in JpaPersistService

2017-12-11 Thread Stephan Classen

Did you make any progress on this issue?


On 04.12.2017 17:43, Diogo Luzzardi de Carvalho wrote:
humm, at moment I call the appLifeCycle.init() the PersistFilter is 
already configured in the application because it is configured at the 
MainModule class configure method. There is any other way to make the 
persistService to start?


On Monday, December 4, 2017 at 2:04:00 PM UTC-2, scl wrote:

This is what I mentioned before.

You cannot use any of the JPA stuff until PersistService.start()
has been called.
This will be called by the PersistFilter.init().
So you have to wait with the appLifeCycle.init() until after the
init() method of PersistFilter



On 04.12.2017 16:58, Diogo Luzzardi de Carvalho wrote:

Unfortunately it is not. I notice that when I change my code to
do the following:
|
injector = Guice.createInjector(new
MainModule(String.format("%s/WEB-INF/app",
getServletContext().getRealPath("/")), getServletContext()));
UnitOfWork unitOfWork = injector.getInstance(UnitOfWork.class);
System.out.println(unitOfWork);
unitOfWork.begin();
try {
appLifeCycle = injector.getInstance(AppLifeCycle.class);
appLifeCycle.init(getServletContext());
} finally {
unitOfWork.end();
}

return injector;
|

 The injector was able to inject the UnitOfWork but when I call
the method unitOfWork.begin() the exception occurs at line 77 of
the JpaPersistService.

On Monday, December 4, 2017 at 1:24:10 PM UTC-2, scl wrote:

Is this an open source project?
If sou you could point me to the repo and I can have a look.



On 04.12.2017 16:22, Diogo Luzzardi de Carvalho wrote:

Hi,

I tried both of your solutions, and the nullpointer keeps
happen. Also I debug the application and I installed the
JpaPersistModule before I try to run the code when the
exception happens.

regards
Diogo

On Friday, December 1, 2017 at 8:42:53 PM UTC-2, scl wrote:

A second cause could be that the PersistenceService has
not been started yet.
The persistence service is started by the
PersistFiler.init() method.

Unfortunately there is no way of checking if the
PersistanceService is already started. And trying to
start it twice will cause an exception the be thrown.


So my advice:
Make sure to delay the accessing of the DB until after
the PersistFiler.init() method and wrap your code in a
UnitOfWork.
The simplest trick is to register another ServletFilter
after the PersistFilter and place your code in the
init() method of this filter...


You may also have a look at Onami Persist which is an
alternative implementation (but without @Finder)



On 01.12.2017 23:25, Diogo Luzzardi de Carvalho wrote:



On Friday, December 1, 2017 at 8:18:46 PM UTC-2, Diogo
Luzzardi de Carvalho wrote:

|

java.lang.NullPointerException


at

com.google.inject.persist.jpa.JpaPersistService.begin(JpaPersistService.java:77)


at

com.google.inject.persist.jpa.JpaLocalTxnInterceptor.invoke(JpaLocalTxnInterceptor.java:53)


at

com.app.guice.AppGuiceServletContextListener.contextInitialized(AppGuiceServletContextListener.java:60)


at

org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:548)


at
org.mortbay.jetty.servlet.Context.startContext(Context.java:136)


at

org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1234)


at

org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)


at

org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:460)


at

org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)


at

org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)


at org.mortbay.jetty.Server.doStart(Server.java:222)


at

org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)


at com.app.Start.start(Start.java:126)


at com.app.Start.main(Start.java:194)

|

Follows my servlet context listener:
|

package com.app.guice;


import javax.servlet.ServletContext;

import javax.servlet.ServletContextEvent;


import org.mortbay.jetty.Server;


import com.app.setup.AppLifeCycle;

   

Re: NullPointerException in JpaPersistService

2017-12-01 Thread Stephan Classen

Can you please give more of the stack trace (all of it).
Because the cause of this NPE is different depending on where the call 
comes from.



On 01.12.2017 20:27, Diogo Luzzardi de Carvalho wrote:

The following exception is ocorring for me:
|

java.lang.NullPointerException


at 
com.google.inject.persist.jpa.JpaPersistService.begin(JpaPersistService.java:77)



at 
com.google.inject.persist.jpa.JpaLocalTxnInterceptor.invoke(JpaLocalTxnInterceptor.java:53)


|

Follows my persistence.xml:
|





Re: NullPointerException in JpaPersistService

2017-12-01 Thread Stephan Classen
A second cause could be that the PersistenceService has not been started 
yet.

The persistence service is started by the PersistFiler.init() method.

Unfortunately there is no way of checking if the PersistanceService is 
already started. And trying to start it twice will cause an exception 
the be thrown.



So my advice:
Make sure to delay the accessing of the DB until after the 
PersistFiler.init() method and wrap your code in a UnitOfWork.
The simplest trick is to register another ServletFilter after the 
PersistFilter and place your code in the init() method of this filter...



You may also have a look at Onami Persist which is an alternative 
implementation (but without @Finder)




On 01.12.2017 23:25, Diogo Luzzardi de Carvalho wrote:



On Friday, December 1, 2017 at 8:18:46 PM UTC-2, Diogo Luzzardi de 
Carvalho wrote:


|

java.lang.NullPointerException


at

com.google.inject.persist.jpa.JpaPersistService.begin(JpaPersistService.java:77)


at

com.google.inject.persist.jpa.JpaLocalTxnInterceptor.invoke(JpaLocalTxnInterceptor.java:53)


at

com.app.guice.AppGuiceServletContextListener.contextInitialized(AppGuiceServletContextListener.java:60)


at

org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:548)


at org.mortbay.jetty.servlet.Context.startContext(Context.java:136)


at
org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1234)


at
org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)


at
org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:460)


at
org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)


at
org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)


at org.mortbay.jetty.Server.doStart(Server.java:222)


at
org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)


at com.app.Start.start(Start.java:126)


at com.app.Start.main(Start.java:194)

|

Follows my servlet context listener:
|

package com.app.guice;


import javax.servlet.ServletContext;

import javax.servlet.ServletContextEvent;


import org.mortbay.jetty.Server;


import com.app.setup.AppLifeCycle;

import com.google.inject.Guice;

import com.google.inject.Injector;

import com.google.inject.Provides;

import com.google.inject.Singleton;

import com.google.inject.servlet.GuiceServletContextListener;


public class AppGuiceServletContextListener extends
GuiceServletContextListener {


private AppLifeCycle appLifeCycle;


private Server server;


private ServletContext servletContext;


private Injector injector;


public AppGuiceServletContextListener(Server server) {

super();

this.server = server;

}


@Override

public void contextDestroyed(ServletContextEvent ctx) {

super.contextDestroyed(ctx);

if(appLifeCycle!= null) {

appLifeCycle.destroy();

}

}


@Override

public void contextInitialized(ServletContextEvent
servletContextEvent) {

servletContext = servletContextEvent.getServletContext();

super.contextInitialized(servletContextEvent);


appLifeCycle = injector.getInstance(AppLifeCycle.class);

appLifeCycle.init(servletContext);

}


@Provides

@Singleton

Server provideServer(Injector injector) {

final Server server = this.server;

injector.injectMembers(server);

returnserver;

}


@Override

protected Injector getInjector() {

System.out.println(servletContext);

if (injector == null)

injector = Guice.createInjector(new
MainModule(String.format("%s/WEB-INF/app",
servletContext.getRealPath("/")), servletContext));

returninjector;

}

}

|

--
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 google-guice+unsubscr...@googlegroups.com 
.
To post to this group, send email to google-guice@googlegroups.com 
.

Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/4df2e8df-81e9-4523-80c6-b4c1cfafa763%40googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.


--
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at 

Re: NullPointerException in JpaPersistService

2017-12-01 Thread Stephan Classen

OK, this is easy to fix.

Guice JPA needs a running UnitOfWork in order to function. The 
UnitOfWork is a thread local context and therefore needs to be started 
and stopped for every thread which wants to make use of JPA.
Be advised that you must end the UnitOfWork because starting it a second 
time without ending it first will trigger an exception (and sadly there 
is no way to test if the UnitOfWork is already running...)

The PersistFilter takes care of this in 99% of the cases.
It is registerd as a ServletFilter and starts a UnitOfWork whenever a 
request enters the server and ends it when the result is returned to the 
client.


You are now starting a transaction from somewhere within the 
contextInitialized() method. So you are not in a request thread.

As a consequence you need to manually control the UnitOfWork.

This can be done easily:

@Inject the UnitOfWork and then add the following code:

    unitOfWork.begin();
    try {
  // do your work here
    } finally {
  unitOfWork.end();
    }


On 01.12.2017 23:18, Diogo Luzzardi de Carvalho wrote:

|

java.lang.NullPointerException


at 
com.google.inject.persist.jpa.JpaPersistService.begin(JpaPersistService.java:77)



at 
com.google.inject.persist.jpa.JpaLocalTxnInterceptor.invoke(JpaLocalTxnInterceptor.java:53)



at 
com.eckertcaine.bridge.guice.BridgeGuiceServletContextListener.contextInitialized(AppGuiceServletContextListener.java:60)



at 
org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:548)



at org.mortbay.jetty.servlet.Context.startContext(Context.java:136)


at 
org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1234)



at 
org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)



at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:460)


at 
org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)



at 
org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)



at org.mortbay.jetty.Server.doStart(Server.java:222)


at 
org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)



at com.eckertcaine.bridge.Start.start(Start.java:126)


at com.eckertcaine.bridge.Start.main(Start.java:194)

|

Follows my servlet context listener:
|

packagecom.app.guice;




importjavax.servlet.ServletContext;


importjavax.servlet.ServletContextEvent;




importorg.mortbay.jetty.Server;




importcom.app.setup.AppLifeCycle;


importcom.google.inject.Guice;


importcom.google.inject.Injector;


importcom.google.inject.Provides;


importcom.google.inject.Singleton;


importcom.google.inject.servlet.GuiceServletContextListener;




publicclassAppGuiceServletContextListenerextendsGuiceServletContextListener{




privateAppLifeCycleappLifeCycle;




privateServerserver;




privateServletContextservletContext;




privateInjectorinjector;




publicAppGuiceServletContextListener(Serverserver){


super();


this.server=server;


}




@Override


publicvoidcontextDestroyed(ServletContextEventctx){


super.contextDestroyed(ctx);


if(appLifeCycle!=null){


appLifeCycle.destroy();


}


}



@Override


publicvoidcontextInitialized(ServletContextEventservletContextEvent){


servletContext=servletContextEvent.getServletContext();


super.contextInitialized(servletContextEvent);




appLifeCycle=injector.getInstance(AppLifeCycle.class);


appLifeCycle.init(servletContext);


}




@Provides


@Singleton


ServerprovideServer(Injectorinjector){


finalServerserver=this.server;


injector.injectMembers(server);


returnserver;


}




@Override


protectedInjectorgetInjector(){


if(injector==null)


injector=Guice.createInjector(newMainModule(String.format("%s/WEB-INF/app",servletContext.getRealPath("/")),servletContext));


returninjector;


}


}

|

the line that points the error on the context listener is 
appLifeCycle.init(servletContext);



On Friday, December 1, 2017 at 7:44:45 PM UTC-2, scl wrote:

Can you please give more of the stack trace (all of it).
Because the cause of this NPE is different depending on where the
call comes from.


On 01.12.2017 20:27, Diogo Luzzardi de Carvalho wrote:

The following exception is ocorring for me:
|

java.lang.NullPointerException


at

com.google.inject.persist.jpa.JpaPersistService.begin(JpaPersistService.java:77)


at

com.google.inject.persist.jpa.JpaLocalTxnInterceptor.invoke(JpaLocalTxnInterceptor.java:53)

|

Follows my persistence.xml:
|





Re: Help with @Inject, for some reason it doesn't work.

2018-05-24 Thread Stephan Classen

The question is:

How are you creating the instance of Blob?

Most likely the instance of Blob was not created by guice. This happens 
when you call "new". In order to have guice create the instance you must 
do either one of the following:

- ask the injector for an instance -- injector.getInstance(Blob.class)
- have Blob injected into another class.

To avoid such situations it is always a possibility to use constructor 
injection instead of field injection:


public class Blob {
    private final Applications applications;

    @Inject
    Blobb(Applications applications) {
        this.applications = applications;
    }

.
}

Now the compile will force you to pass an instance of Applications when 
you call new Blob.
Guice will happily pass all arguments to the constructor annotate with 
@Inject.






On 24.05.2018 15:49, po...@mailarchiva.ru wrote:


I have a class i wan't inject
For legacy code support it is like this.

@Singleton
public class Applications extends AbstractModule {
    private Applications() {}
    private static class ApplicationsLoader {
        static final Applications INSTANCE = new Applications();
    }
    @Override    protected void configure() {}
    @Provides @Singleton
    public Applications get() {
        return ApplicationsLoader.INSTANCE;
    }
   public static Applications getApps() {
        return ApplicationsLoader.INSTANCE;
    }
}

On application startup , I create injector.

public void startup() throws Exception {
initLogging();
Injector injector = Guice.createInjector(Stage.PRODUCTION,
Applications.getApps());
}

but some while after, when I need Applications.class i always get a null

public class Blob {
    @Inject private Applications applications;
.
}

Any suggestions how to share Applications.class singleton?
injector.getInstance(Applications.class) working fine.

Regards,

Valentin.

--
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 google-guice+unsubscr...@googlegroups.com 
.
To post to this group, send email to google-guice@googlegroups.com 
.

Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/d02fdaa7-59e9-4b4e-8f47-4a43a04d53db%40googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.


--
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/6e966ba5-10cf-59a1-dad4-c604df112767%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.


Re: Guice injection not working in web application

2018-06-18 Thread Stephan Classen
Unless you tell guice that a dependency is optional it will never inject null. 
It would fail with an exception if it could not fullfil a dependency.

So for me the most likely cause of you seeing null is that the instance you are 
inspecting is created by calling new, using reflection or by another DI 
framework (like CDI or Spring).

Best strategy to debug this would be to make the field
_bankAccountProvider final. Then create a constructor to pass in the instance 
and annotate the constructor with @Inject.

Now you can place a breakpoint in the constructor. This will show you who is 
creating the instance. And if somebody is calling new the compiler may already 
tell you before you execute the code.

By the way: I would always favour constructor injection over field injection
- because it makes writing tests simpler (just call the constructor from your 
test class)
- an ugly constructor with 5+ arguments smells stronger than 5+ fields with 
annotation. And this is good because having that many dependency is often a 
sign that a class has too many responsebilities...

Am 18. Juni 2018 17:19:46 MESZ schrieb Adil Quraish :
>
>
>I am trying to get Guice to work in a web application deployed on JBoss
>EAP 
>6.4 When I try to step through the Guice code, I notice that the
>binding is 
>happening. However, when I try to inject the bound object, I always get
>
>null. The following are the code changes I have done to enable Guice -
>
>
>1) *web.xml*
>
>
>com.univeris.guice.GuiceConfig
>
>
>
>guiceFilter
>com.google.inject.servlet.GuiceFilter
>
>
>
>guiceFilter
>/*
>
>
>
>2) *GuiceConfig*
>
>@Singleton
>public class GuiceConfig extends GuiceServletContextListener {
>@Override
>protected Injector getInjector() {
>Injector injector = Guice.createInjector(
>new ServletModule() {
>@Override
>protected void configureServlets() {
>serve("/uif/*").with(UIFInitializeServlet.class);
>serve("/upm/*").with(IDPServlet.class,
>ImmutableMap.of("instance-name","upm"));
>serve("/uiw/*").with(IDPServlet.class,
>ImmutableMap.of("instance-name","uiw"));
>}
>},
>new MainModule()
>);
>
>return injector;
>  }
>}
>
>
>3) *MainModule*
>
>public class MainModule extends AbstractModule {
>
>@Override
>protected void configure() {
>install(new BankAccountModule());
>install(new CoreModule());
>}
>}
>
>
>4) *BankAccountModule*
>
>public class BankAccountModule extends AbstractModule {
>@Override
>protected void configure() {
>bind(BankAccountProvider.class).toProvider(BankAccountGuiceProvider.class);
> 
>bind(BankAccountService.class).toProvider(BankAccountServiceProvider.class);
>}
>}
>
>
>5) *BankAccountGuiceProvider*
>
>public class BankAccountGuiceProvider implements
>Provider {
>@Override
>public BankAccountProvider get() {
>  return ProviderLocator.locateProvider(BankAccountProvider.class);
>}
>}
>
>
>6) *BankAccountServiceUVS*
>
>@Stateless
>@Interceptors(ServiceInterceptor.class)
>public class BankAccountServiceUVS implements BankAccountService {
>
>@Inject
>private BankAccountProvider _bankAccountProvider;
>
>@Override
>public BankAccountCollection getAllBankAccounts(final Integer entityId,
>final String entityType) {
>BankAccountCollection retVal =
>_bankAccountProvider.getAllBankAccounts(entityId, 
>return PojoHelper.cloneObject(retVal);
>}
>}
>
>
>The *_bankAccountProvider* is always injected as null. I have been
>pouring 
>through several forums for several days to no avail. Can someone point
>out 
>what I am missing?
>
>-- 
>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 google-guice+unsubscr...@googlegroups.com.
>To post to this group, send email to google-guice@googlegroups.com.
>Visit this group at https://groups.google.com/group/google-guice.
>To view this discussion on the web visit
>https://groups.google.com/d/msgid/google-guice/674dcd19-115c-43b3-bf58-572193bb619b%40googlegroups.com.
>For more options, visit https://groups.google.com/d/optout.

-- 
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/78D9B98B-AAD4-44C0-A466-17E8441D9B2B%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.


Re: Guice pattern for long lived dynamic 1:1 relationships?

2018-06-14 Thread Stephan Classen
Scopes are surely a way to handle this situation. But Scopes are also 
hard to get right and they introduce a little "magic" because you need 
to know that a dependency is scoped. Because if you cache the instance 
you get from guice in a field it may not be the one you expect at a 
later state...


Therefore I like to make such things a bit more explicit. In your case I 
would create a Class called CurrentWorlds. Make that class a singleton 
and have it implement the following 3 methods:

- add(World world)
- remove(World world)
- Collection get()

In you EventListener you can then add and remove worlds as they get 
loaded and unloaded and in your regular code you can always get the 
current worlds which is the collection of worlds loaded at that very moment.




On 14.06.2018 03:32, Ryan Leach wrote:
In Minecraft, specifically SpongeAPI, There are a series of Worlds 
that are simulated in game.


These worlds are generally in an update cycle known as 'ticking' that 
world.


Worlds are generally loaded at startup, and unloaded on shutdown, but 
can have repeating life cycles on the client, where someone might 
return to the main menu, then load up a new game save loading new worlds.


On the server, worlds can be added or removed by the admins while the 
game is running.


If I have Services(onStart,onEnd,onTick) and virtual game entities 
(not true entities that live in the world, but are simulated like they 
are by the services that depend on world)


And SpongeAPI provides World load/unload events.

What would be the best strategy using Guice to manage dependencies on 
worlds?


If I listen for the world load/unload events, I have the world needed 
pretty easily to do the DI manually for the services, but under Guice 
I'm not sure how to correctly bind classes that need a world, to be 
using the correct world?


Most Guice tutorials I've seen handle Request scopes, or application 
bootup, but never really multiple anonymous dependencies with a 1:1 
relationship, that can be dynamically loaded / unloaded.


Or am I right in thinking this needs to be handled manually, and all 
Guice can do to help in this situation, is inject the world that I 
explicitly provide in a ReentrantScope 
(https://github.com/timboudreau/scopes) and somehow keep that scope 
around for children of the service?



--
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 google-guice+unsubscr...@googlegroups.com 
.
To post to this group, send email to google-guice@googlegroups.com 
.

Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/a121d04e-7edc-46fc-b943-72e7427d7cc7%40googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.


--
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/8f06049f-a20f-91a2-c792-472bd0259572%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.


Re: Hierarchical lookup

2018-06-05 Thread Stephan Classen

Multibindings are the way Guice is implementing plug-in mechanism.

The best I can think of is having a single SetBinder and add all 
pluggable classes there.
Then implement your own methods which iterate over all binded classes 
and filter for the criteria you need.


class Fruity {

@Inject Set fruits;

Set getAllFruitsWithSeed() {
    Set result = new HashSet<>();
    for (Object candidate : fruits) {
        if (candidate instanceof HasSeed) {
            result.add((HasSeed) candidate);
        }
    }
}




On 05.06.2018 23:57, 'Mariano Gonzalez' via google-guice wrote:

Hello,

I want to perform a hierarchical lookup. Suppose I have the following 
code:


|
bind(Apple.class).in(Singleton.class);
bind(Banana.class).in(Singleton.class);
bind(Grape.class).in(Singleton.class);
|

Now suppose that Apple and Grape implement the JuiceFactory interface, 
which Banana does not.


How do I programmatically lookup all the JuiceFactory instances? In 
Spring there's a getBeansOfType() method which allows for any random 
hierarchical queries, I'm wondering how to achieve the same with 
Guice. Reason why I need this is that my modules will be pluggable so 
I don't know the fruits I'll be handling before hand. Also, I might 
later want to do a lookup by the HasSeed interface, where I also 
expect the Apple and Grape instances to be returned, so MultiBinder is 
not really an option.


Thanks!
--
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 google-guice+unsubscr...@googlegroups.com 
.
To post to this group, send email to google-guice@googlegroups.com 
.

Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/7e728a22-0d39-44a1-852e-b2dc2a62909a%40googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.


--
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/25e84044--5ed3-43ce-da80562a2c38%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.


Re: Dynamic binding inference

2018-06-19 Thread Stephan Classen

You could have a look at multi binders.
https://github.com/google/guice/wiki/Multibindings

Then bind all possible implementations of an interface and use the value 
from the properties to select the one out of the set.




On 19.06.2018 16:33, 'Mariano Gonzalez' via google-guice wrote:

Hello,

I have a case in which a portion of the binding are dynamically 
provided through a properties file with the following format:


|
exampleService=ExampleServiceImpl
fooService=FooServiceImpl

|

Unlike Guice's approach, the key is not a type but an actual Name. For 
now, I'm just binding those concrete types to themselves, like 
/bind(FooServiceImpl.class).to(bindFooServiceImpl.class)/


Of course this approach doesn't work because then the following 
injection would fail:


|
publicclassFoo{


@Inject
privateFooServicefooService;


}
|

There's no default way in which Guice would figure out that FooService 
can actually be served by FooServiceImpl. The alternative that I have 
thought about so far is to introspect those types and generate 
bindings for each superclass and implemented interface.


I was wondering is there's a less "brute force" approach.

Thanks
--
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 google-guice+unsubscr...@googlegroups.com 
.
To post to this group, send email to google-guice@googlegroups.com 
.

Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/7d2ec09b-9702-4615-85f2-82f47329c9b5%40googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.


--
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/09b132e0-2d0b-40ac-2537-16b5a88f7d77%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.


Re: Dynamic binding inference

2018-06-19 Thread Stephan Classen
I don't think this would be a good approach. And I am not even sure if 
guice would allow it.
I would rather propose that every plugin comes with a Module which is 
then passed to the injector creation method.

This way every plugin can bind whatever it needs.
If multiple plugins try to bind the same thing you could always 
encapsulate a plugin in a private module and only expose a limited set 
of bindings.


If I miss the point here then maybe try to explain why you are passing 
bindings in properties files...




On 19.06.2018 16:45, 'Mariano Gonzalez' via google-guice wrote:

Thank you.

Yes I looked at Multibinders but this still requires the brute force 
approach. Each of my plugins can register any random object, I don't 
know the universe of interfaces before hand. I was more looking in the 
direction of somehow tapping into how the bindings are processed  so 
that when Guice realises that it cannot serve @Inject FooService I can 
catch that and calculate that binding on demand?


Is this or something like that possible?

Thanks

On Tuesday, June 19, 2018 at 11:36:08 AM UTC-3, scl wrote:

You could have a look at multi binders.
https://github.com/google/guice/wiki/Multibindings


Then bind all possible implementations of an interface and use the
value from the properties to select the one out of the set.



On 19.06.2018 16:33, 'Mariano Gonzalez' via google-guice wrote:

Hello,

I have a case in which a portion of the binding are dynamically
provided through a properties file with the following format:

|
exampleService=ExampleServiceImpl
fooService=FooServiceImpl

|

Unlike Guice's approach, the key is not a type but an actual
Name. For now, I'm just binding those concrete types to
themselves, like
/bind(FooServiceImpl.class).to(bindFooServiceImpl.class)/

Of course this approach doesn't work because then the following
injection would fail:

|
publicclassFoo{


@Inject
privateFooServicefooService;


}
|

There's no default way in which Guice would figure out that
FooService can actually be served by FooServiceImpl. The
alternative that I have thought about so far is to introspect
those types and generate bindings for each superclass and
implemented interface.

I was wondering is there's a less "brute force" approach.

Thanks
-- 
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 google-guice...@googlegroups.com .
To post to this group, send email to google...@googlegroups.com
.
Visit this group at https://groups.google.com/group/google-guice
.
To view this discussion on the web visit

https://groups.google.com/d/msgid/google-guice/7d2ec09b-9702-4615-85f2-82f47329c9b5%40googlegroups.com

.
For more options, visit https://groups.google.com/d/optout
.


--
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 google-guice+unsubscr...@googlegroups.com 
.
To post to this group, send email to google-guice@googlegroups.com 
.

Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/c528fae0-28b9-41fa-a08f-7635416ff42f%40googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.


--
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/f2c8a553-ea1c-95c7-5e39-8cd319eb78fe%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.


Re: Dynamic binding inference

2018-06-20 Thread Stephan Classen

I guess then you are on your own.

I don't think Guice provide such a feature out of the box.
You could write a custom Module which reads the properties files and 
creates bindings for each and every one.
As long as all of them are simple just like the examples you gave I 
think you should be able to get this done in a few lines of code.
But I don't know Spring enough to tell if there are complex cases which 
you would also need to support...


Good luck

And if you have any concrete question don't hesitate to ask



On 19.06.2018 17:17, 'Mariano Gonzalez' via google-guice wrote:
The reason for binding as properties is basically backwards 
compatibility. This is a legacy system originally built with spring. 
I'm trying to move to guice because spring is way too heavy and takes 
a long time to start, but all of this works out of the box.


Unfortunately, having each plugin ship with a module is not an option 
in this case, which is why I'm looking for a way to leverage guice 
goodies while while keeping spring's behavior.


Thanks

On Tue, Jun 19, 2018, 12:09 PM Stephan Classen <mailto:st.clas...@gmx.ch>> wrote:


I don't think this would be a good approach. And I am not even
sure if guice would allow it.
I would rather propose that every plugin comes with a Module which
is then passed to the injector creation method.
This way every plugin can bind whatever it needs.
If multiple plugins try to bind the same thing you could always
encapsulate a plugin in a private module and only expose a limited
set of bindings.

If I miss the point here then maybe try to explain why you are
passing bindings in properties files...



On 19.06.2018 16:45, 'Mariano Gonzalez' via google-guice wrote:

Thank you.

Yes I looked at Multibinders but this still requires the brute
force approach. Each of my plugins can register any random
object, I don't know the universe of interfaces before hand. I
was more looking in the direction of somehow tapping into how the
bindings are processed  so that when Guice realises that it
cannot serve @Inject FooService I can catch that and calculate
that binding on demand?

Is this or something like that possible?

Thanks

On Tuesday, June 19, 2018 at 11:36:08 AM UTC-3, scl wrote:

You could have a look at multi binders.
https://github.com/google/guice/wiki/Multibindings

Then bind all possible implementations of an interface and
use the value from the properties to select the one out of
the set.



On 19.06.2018 16:33, 'Mariano Gonzalez' via google-guice wrote:

Hello,

I have a case in which a portion of the binding are
dynamically provided through a properties file with the
following format:

|
exampleService=ExampleServiceImpl
fooService=FooServiceImpl

|

Unlike Guice's approach, the key is not a type but an actual
Name. For now, I'm just binding those concrete types to
themselves, like
/bind(FooServiceImpl.class).to(bindFooServiceImpl.class)/

Of course this approach doesn't work because then the
following injection would fail:

|
publicclassFoo{


@Inject
privateFooServicefooService;


}
|

There's no default way in which Guice would figure out that
FooService can actually be served by FooServiceImpl. The
alternative that I have thought about so far is to
introspect those types and generate bindings for each
superclass and implemented interface.

I was wondering is there's a less "brute force" approach.

Thanks
-- 
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 google-guice...@googlegroups.com.
To post to this group, send email to google...@googlegroups.com.
Visit this group at
https://groups.google.com/group/google-guice.
To view this discussion on the web visit

https://groups.google.com/d/msgid/google-guice/7d2ec09b-9702-4615-85f2-82f47329c9b5%40googlegroups.com

<https://groups.google.com/d/msgid/google-guice/7d2ec09b-9702-4615-85f2-82f47329c9b5%40googlegroups.com?utm_medium=email_source=footer>.
For more options, visit https://groups.google.com/d/optout.


-- 
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 google-guice+unsubscr...@googlegroups.com
<mailto:google-guice+unsubscr...@googlegroups.com>.
To post to this group, send email to
google-guice@googlegroups.com <mailto:google-guice@googlegroups.c

Re: Providers - generation ?

2018-02-12 Thread Stephan Classen
There are many different implementations depending on the scope and the 
binding.

An incomplete list is:
- InjectorImpl.getProviderOrThrow()
- Scopes.SINGLETON
- ProviderLookup.getProvider()
- Providers.of()
- Providers.gucify()

In the end it doesn't matter which implementation is actually injected.
The main things you need to know is what a provider is good for:
- Delayed injection (because something is expensive to create or only 
available in a specific scope)
- Multiple injection (because you need more than one instance off it. If 
this is the case think twice if you need DI for this class or rather a 
factory)

- Provide your own Provider (if you implement a custom scope)


On 12.02.2018 13:38, competitiveprogramming.pie...@gmail.com wrote:
I was reading that page but I can't find where it explicitly says they 
are generated. Would you know where the code that generates them is ?


On Monday, February 12, 2018 at 12:32:33 PM UTC, scl wrote:

Yes, Providers are generated on the fly by guice.

https://github.com/google/guice/wiki/InjectingProviders




On 12.02.2018 13:19, competitivepro...@gmail.com  wrote:

Hi all,

I apologise if my question sounds silly or badly grounded.

I am working on a project which makes intense use of Google Guice
and I've seen several places where the class I am working with
uses injected providers, such as:

|
classWhatEver{
@Inject
WhatEver(ProviderproviderOfA ...){...}

}
|

I do not understand how/what implements the provider as I do not
see any class around my module explicitly implementing the interface.

|
Provider
|


I am pretty sure there is not any.

How does that work ? Are providers synthesised/generated ? If yes
I would like to see where this is done - so I can have a better
idea about how the whole thing works.

Thanks in advance,
Pietro.

-- 
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 google-guice...@googlegroups.com .
To post to this group, send email to google...@googlegroups.com
.
Visit this group at https://groups.google.com/group/google-guice
.
To view this discussion on the web visit

https://groups.google.com/d/msgid/google-guice/df1847bb-6125-434a-b00c-53614000aeb8%40googlegroups.com

.
For more options, visit https://groups.google.com/d/optout
.


--
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 google-guice+unsubscr...@googlegroups.com 
.
To post to this group, send email to google-guice@googlegroups.com 
.

Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/2f4ed289-ed7c-458e-bce3-ba4e64994438%40googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.


--
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/19f31fed-0425-3308-a05c-847f041ec53f%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.


Re: JpaPersistModule, Hibernate and URL Variables

2018-02-14 Thread Stephan Classen

When are you passing this string?
Is it part of you Giuce Module??

Could you read the environment variable before creating the string and 
than manually create the URL string?




On 14.02.2018 11:38, Evan Ruff wrote:

Hey guys,

I've got what I think is a pretty straightforward task but I'm having 
a little issue figuring out where to attach in my code.


I've got an embedded H2 database being used in an installed 
application to manage state of some objects. I'm using Hibernate as my 
JPA implementation and everything is working great. The one issue I 
have is that the path of the database file is set in my URL as:


jdbc:h2:file:./data/application_db;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE;

which changes depending on how the application is executed. I'd like 
to have the database file be written in a location set by 
an environment variable, so that I'd have:


jdbc:h2:file:*$APP_DB_PATH*/data/application_db;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE;

I've tried several different forms and it doesn't seem to be taking.

Has anyone encountered this and could give me a pointer on how to 
implement?


Thanks!

E
--
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 google-guice+unsubscr...@googlegroups.com 
.
To post to this group, send email to google-guice@googlegroups.com 
.

Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/ed5b261c-62de-41b1-872f-7585ca134d0f%40googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.


--
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/ef884498-fa77-e37d-ca1b-2bc0bd6b5e81%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.


Re: JpaPersistModule, Hibernate and URL Variables

2018-02-14 Thread Stephan Classen
Maybe you can make your path relative to the user directory as described here:
http://www.h2database.com/html/faq.html#database_files


Am 14. Februar 2018 21:06:34 MEZ schrieb Evan Ruff :
>Hey guys,
>
>So I'm actually just letting Guice Persist pull it straight out of 
>META-INF/persistence.xml file. 
>
>I'm wondering where I can either change the URL or set it explicitly,
>while 
>still using Guice Persist.
>
>thanks!
>
>E
>
>On Wednesday, February 14, 2018 at 10:58:11 AM UTC-5, Sondre Bjornebekk
>
>wrote:
>>
>> If you always want to use h2, you could just simply build the string
>using 
>>
>https://docs.oracle.com/javase/8/docs/api/java/lang/System.html#getenv--?
>>
>> If you wanted to inject different JPA providers, you could certainly
>use 
>> Guice for that (since you posted here) - I have a
>HibernateSessionFactory 
>> that provides a session per request like this:
>>
>> @Provides
>> @RequestScoped
>> private Session provideSession() {
>>
>>
>>
>> And then for my jUnit tests I have:
>>
>> @Provides
>> @Singleton
>> private Session provideSession() {
>>
>>
>> in a
>>
>> public class TestGuiceModule extends AbstractModule
>>
>>
>> Would that fit your use case?
>>
>> Cheers,
>>
>> -S-
>>
>> On Wednesday, February 14, 2018 at 10:38:16 AM UTC, Evan Ruff wrote:
>>>
>>> Hey guys,
>>>
>>> I've got what I think is a pretty straightforward task but I'm
>having a 
>>> little issue figuring out where to attach in my code.
>>>
>>> I've got an embedded H2 database being used in an installed
>application 
>>> to manage state of some objects. I'm using Hibernate as my JPA 
>>> implementation and everything is working great. The one issue I have
>is 
>>> that the path of the database file is set in my URL as:
>>>
>>>
>>>
>jdbc:h2:file:./data/application_db;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE;
>>>
>>> which changes depending on how the application is executed. I'd like
>to 
>>> have the database file be written in a location set by an
>environment 
>>> variable, so that I'd have:
>>>
>>> jdbc:h2:file:*$APP_DB_PATH*
>>> /data/application_db;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE;
>>>
>>> I've tried several different forms and it doesn't seem to be taking.
>
>>>
>>> Has anyone encountered this and could give me a pointer on how to 
>>> implement?
>>>
>>> Thanks!
>>>
>>> E
>>>
>>
>
>-- 
>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 google-guice+unsubscr...@googlegroups.com.
>To post to this group, send email to google-guice@googlegroups.com.
>Visit this group at https://groups.google.com/group/google-guice.
>To view this discussion on the web visit
>https://groups.google.com/d/msgid/google-guice/5c35a644-645a-4419-85c3-9a3a159fc87d%40googlegroups.com.
>For more options, visit https://groups.google.com/d/optout.

-- 
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/CC173E92-331F-4CC5-BD39-2F2430BFFF38%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.


Re: JpaPersistModule, Hibernate and URL Variables

2018-02-15 Thread Stephan Classen
Only way you can try to achieve this is the methode: 
JpaPersistModule.setProperties()
The properties passed in will be used to create the entity manager 
factory (see JpaPersistService.start())


Maybe you can overwrite the URL in the properties you pass.



On 15.02.2018 12:05, Evan Ruff wrote:
I'd really like to be able to define the location of the DB, as 
multiple services will be accessing it.


I'm okay with moving away from the persistence.xml file and rolling 
the configuration in code, but I'm not sure where to do that while 
still using JpaPersistModule. Has anyone tried a declarative approach? 
Any examples anywhere?


E

On Wednesday, February 14, 2018 at 6:13:43 PM UTC-5, scl wrote:

Maybe you can make your path relative to the user directory as
described here:
http://www.h2database.com/html/faq.html#database_files



Am 14. Februar 2018 21:06:34 MEZ schrieb Evan Ruff
:

Hey guys,

So I'm actually just letting Guice Persist pull it straight
out of META-INF/persistence.xml file.

I'm wondering where I can either change the URL or set it
explicitly, while still using Guice Persist.

thanks!

E

On Wednesday, February 14, 2018 at 10:58:11 AM UTC-5, Sondre
Bjornebekk wrote:

If you always want to use h2, you could just simply build
the string using

https://docs.oracle.com/javase/8/docs/api/java/lang/System.html#getenv--

?

If you wanted to inject different JPA providers, you could
certainly use Guice for that (since you posted here) - I
have a HibernateSessionFactory that provides a session per
request like this:

@Provides @RequestScoped private SessionprovideSession() {



And then for my jUnit tests I have:

@Provides @Singleton private SessionprovideSession() {


in a

public class TestGuiceModuleextends AbstractModule


Would that fit your use case?

Cheers,

-S-

On Wednesday, February 14, 2018 at 10:38:16 AM UTC, Evan
Ruff wrote:

Hey guys,

I've got what I think is a pretty straightforward task
but I'm having a little issue figuring out where to
attach in my code.

I've got an embedded H2 database being used in an
installed application to manage state of some objects.
I'm using Hibernate as my JPA implementation and
everything is working great. The one issue I have is
that the path of the database file is set in my URL as:


jdbc:h2:file:./data/application_db;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE;

which changes depending on how the application is
executed. I'd like to have the database file be
written in a location set by an environment variable,
so that I'd have:


jdbc:h2:file:*$APP_DB_PATH*/data/application_db;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE;

I've tried several different forms and it doesn't seem
to be taking.

Has anyone encountered this and could give me a
pointer on how to implement?

Thanks!

E

--
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 google-guice+unsubscr...@googlegroups.com 
.
To post to this group, send email to google-guice@googlegroups.com 
.

Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/359f8de0-3a51-4ca0-8209-50252d136788%40googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.


--
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/32d4dd9d-c41e-1ca1-9333-635c5ab5916f%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.


Re: JpaPersistModule, Hibernate and URL Variables

2018-02-15 Thread Stephan Classen

Can't you simply do the following??

public class MyModule extends ServletModule {
  protected void configureServlets() {
    install(new JpaPersistModule("myJpaUnit").setProperties(myProperties));
  }
}


On 15.02.2018 14:46, Evan Ruff wrote:

scl,

Thanks for the tip, this works as expected. JpaPersistModule is final 
(ARGH) but I created a static utility class with an install method 
that handles it. I build the database connection string using the env 
props and then I'm able to set it using the 
JpaPersistModule.properties(  prop ) method. Set a map of strings 
in there, and it appears that it will use those values to overwrite 
what comes out of the META-INF/persistence.xml file.


Best of both worlds!

Thanks!

E

On Thursday, February 15, 2018 at 6:47:33 AM UTC-5, scl wrote:

Only way you can try to achieve this is the methode:
JpaPersistModule.setProperties()
The properties passed in will be used to create the entity manager
factory (see JpaPersistService.start())

Maybe you can overwrite the URL in the properties you pass.



On 15.02.2018 12:05, Evan Ruff wrote:

I'd really like to be able to define the location of the DB, as
multiple services will be accessing it.

I'm okay with moving away from the persistence.xml file and
rolling the configuration in code, but I'm not sure where to do
that while still using JpaPersistModule. Has anyone tried a
declarative approach? Any examples anywhere?

E

On Wednesday, February 14, 2018 at 6:13:43 PM UTC-5, scl wrote:

Maybe you can make your path relative to the user directory
as described here:
http://www.h2database.com/html/faq.html#database_files



Am 14. Februar 2018 21:06:34 MEZ schrieb Evan Ruff
:

Hey guys,

So I'm actually just letting Guice Persist pull it
straight out of META-INF/persistence.xml file.

I'm wondering where I can either change the URL or set it
explicitly, while still using Guice Persist.

thanks!

E

On Wednesday, February 14, 2018 at 10:58:11 AM UTC-5,
Sondre Bjornebekk wrote:

If you always want to use h2, you could just simply
build the string using

https://docs.oracle.com/javase/8/docs/api/java/lang/System.html#getenv--

?

If you wanted to inject different JPA providers, you
could certainly use Guice for that (since you posted
here) - I have a HibernateSessionFactory that
provides a session per request like this:

@Provides @RequestScoped private SessionprovideSession() {



And then for my jUnit tests I have:

@Provides @Singleton private SessionprovideSession() {


in a

public class TestGuiceModuleextends AbstractModule


Would that fit your use case?

Cheers,

-S-

On Wednesday, February 14, 2018 at 10:38:16 AM UTC,
Evan Ruff wrote:

Hey guys,

I've got what I think is a pretty straightforward
task but I'm having a little issue figuring out
where to attach in my code.

I've got an embedded H2 database being used in an
installed application to manage state of some
objects. I'm using Hibernate as my JPA
implementation and everything is working great.
The one issue I have is that the path of the
database file is set in my URL as:


jdbc:h2:file:./data/application_db;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE;

which changes depending on how the application is
executed. I'd like to have the database file be
written in a location set by an environment
variable, so that I'd have:


jdbc:h2:file:*$APP_DB_PATH*/data/application_db;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE;

I've tried several different forms and it doesn't
seem to be taking.

Has anyone encountered this and could give me a
pointer on how to implement?

Thanks!

E

-- 
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 google-guice...@googlegroups.com .
To post to this group, send email to google...@googlegroups.com
.
Visit this group at 

Re: How do I retrieve an object injected through Guice

2018-08-29 Thread Stephan Classen
Checkout the tutorial in the guice github wiki:
https://github.com/google/guice/wiki/GettingStarted

Am 29. August 2018 18:56:14 MESZ schrieb Arul Prakasam Narasimhan 
:
>Under my Module Class, I inject objects
>
> @Override
>protected void configure() {
>bind(AuthorizationService.class).asEagerSingleton();
>bind(BasicAuthenticationService.class).asEagerSingleton();
>bind(BasicCredentialsHashingService.class).asEagerSingleton();
>   }
>
>Now how do I retrieve these objects if required inside my Plugin Class.
>I need to retrieve these objects, add another property value to it.
>
>Thanks
>Arul.
>
>-- 
>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 google-guice+unsubscr...@googlegroups.com.
>To post to this group, send email to google-guice@googlegroups.com.
>Visit this group at https://groups.google.com/group/google-guice.
>To view this discussion on the web visit
>https://groups.google.com/d/msgid/google-guice/f347df99-64c4-4aed-9c2b-5844fa569e21%40googlegroups.com.
>For more options, visit https://groups.google.com/d/optout.

-- 
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/9D691758-DC58-4A25-A942-78E35FA38282%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.


[no subject]

2018-07-12 Thread Stephan Classen
http://espace-bien-naitre.fr/knmdhgt.php?ckukz

-- 
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/trinity-7ae68217-27ec-4bba-ba43-57894d0d1138-1531393813521%403c-app-gmx-bs01.
For more options, visit https://groups.google.com/d/optout.


Re: Can I Inject x Class?

2018-06-21 Thread Stephan Classen
Jukito takes another approach. They use an ElementVisitor to collect all 
bindings and then decide if the required binding is in the module(s).

Have a look at the BindingsCollector.java class

https://github.com/ArcBees/Jukito/blob/master/jukito/src/main/java/org/jukito/BindingsCollector.java


On 20.06.2018 22:45, Joe DeSantis wrote:
I was working with a JUnit 5 extension for Guice, and we had the need 
to determine if a particular class was able to be injected by an 
injector.
The only solution we came up with is attempting to get an instance 
with that Injector. (Literally calling the getInstance method, in a 
try/catch block).
So my question is simply, what is the best way of determining if you 
can get an instance of a particular class given an injector.


The discussion on the implementation is here for anyone who is curious,
https://github.com/JeffreyFalgout/junit5-extensions/commit/adf2f4ece977e834ba9b4f1563ebc568784ad3a4#commitcomment-29425765

Thanks!
--
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 google-guice+unsubscr...@googlegroups.com 
.
To post to this group, send email to google-guice@googlegroups.com 
.

Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/dbbc0674-7e82-47de-97ee-6bdf9258d2fd%40googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.


--
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/c98854df-a81a-7053-c32a-692dde254fc9%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.


Re: dynamically reload the property bindings using guice .

2018-12-10 Thread Stephan Classen

Not when you are using Names.bindProperties.
What you could do is bind custom provider methods for the different 
config parameters.
This provider methods are then under your control and you can 
cache/reload the value as you like.



On 10.12.18 18:34, Bharath Vishnu Neelakantan wrote:
I load the key value pair for configs from a url and then bind it 
using guice Names.bindProperties . Is there a way to dynamically 
reload this binding when we make a post call to the app ?.

--
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 google-guice+unsubscr...@googlegroups.com 
.
To post to this group, send email to google-guice@googlegroups.com 
.

Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/1e926131-6b8d-4d22-8121-bd2c2204efbd%40googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.


--
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/299a2ef3-a968-3d43-e629-71082498a439%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.


Re: Two instances of the same class, different properties, is it possible?

2019-02-18 Thread Stephan Classen
Could you give some more details. Best would be some code example

Am 18. Februar 2019 22:16:20 MEZ schrieb jhertz :
>I have two instances of the same class. I want to inject them with two 
>different set of properties in the form of a Map. The 
>instances are read dynamically from and XML file so I won't know until
>run 
>time if there are 1, 2 or X amount of instances. Is this possible?
>
>Regards
>jhz
>
>-- 
>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 google-guice+unsubscr...@googlegroups.com.
>To post to this group, send email to google-guice@googlegroups.com.
>Visit this group at https://groups.google.com/group/google-guice.
>To view this discussion on the web visit
>https://groups.google.com/d/msgid/google-guice/ec31feaf-429f-40d1-bae0-fd699c32747f%40googlegroups.com.
>For more options, visit https://groups.google.com/d/optout.

-- 
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/27FDBB76-2A0B-4EF6-91AE-BFFBB1BDA31F%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.


Re: Delay initialization support

2019-03-07 Thread Stephan Classen
You cannot change the configuration of an injector after it has been created.
What you can do is create a child injector which inherits all bindings from its 
parent and can add extra bindings.

But I think the problem should be tackled by your bean container. Which one are 
you using. Can you influence the order of bean binding. Why are you using a 
bean container, would pojos be sufficient...

Am 7. März 2019 18:58:39 MEZ schrieb jiandai via google-guice 
:
>Hi there, 
>
>I have a Guice bean which need to preload some data from Spanner DB
>after 
>it initialized, but the Spanner DB connection may not been established
>yet 
>before that bean's binding. I was wondering if Guice allow to 
>post-initialization after all the binding finished. (I know Spring
>support 
>it)?
>
>Many thanks in advance for the nice help. 
>
>Jian
>
>-- 
>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 google-guice+unsubscr...@googlegroups.com.
>To post to this group, send email to google-guice@googlegroups.com.
>Visit this group at https://groups.google.com/group/google-guice.
>To view this discussion on the web visit
>https://groups.google.com/d/msgid/google-guice/b019b012-3a35-4b71-8cf9-617d3e3b3cb8%40googlegroups.com.
>For more options, visit https://groups.google.com/d/optout.

-- 
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/C5CC1288-82DB-4D9B-AE49-BF7C8FB8923E%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.


Re: How to override module

2019-01-29 Thread Stephan Classen

Look at the class Modules. There is a method "override"

Usage:
Modules.override(new WriterModule()).with(new AbcWriterModule())



On 29.01.19 12:21, Sammy wrote:

Hi,
I got below final module

public final class WriterModuleextends AbstractModule {
with below provides
@ProvidesIntoOptional(Type.DEFAULT)
public TopicNameFactory provideDefaultTopicNameFactory() {
 return new TopicNameFactory.Default();
}
This is from in-house library which can't be changed without affecting/testing 
many other application.
How do I override this TopicNameFactory to custom ABCTopicNameFactory.
--
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 google-guice+unsubscr...@googlegroups.com 
.
To post to this group, send email to google-guice@googlegroups.com 
.

Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/f1263a43-e3dc-4be6-bff7-d50d50f54d70%40googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.


--
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/ae5ba44d-102d-ee02-ef44-f6e964f6f575%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.


<    1   2