Re: The never-ending beta of Guice 4

2015-03-16 Thread James Roper
I don't always +1 things, but when I do, I +1 a stable release of Guice 4.

On Sunday, 15 March 2015 03:10:35 UTC+11, Sam Berlin wrote:

 ... Actually I guess today isn't really St Patrick's day... parades throw 
 you off. 

 But we still hear y'all. 

 sam
  
 -- Forwarded message -
 From: Sam Berlin sbe...@gmail.com javascript:
 Date: Sat, Mar 14, 2015, 11:58 AM
 Subject: Re: The never-ending beta of Guice 4
 To: google...@googlegroups.com javascript:


 Happy St Patrick's day. :-)

 We hear y'all, don't worry. 

 sam

 On Sat, Mar 14, 2015, 11:47 AM David Sowerby david.s...@gmail.com 
 javascript: wrote:

 +1 just in case the elves can hear from a long way off ...


 On Saturday, 14 March 2015 07:20:25 UTC, Tim Boudreau wrote:

 Is anybody from the Guice team at Google listening, or have the elves 
 left Middle-Earth?

 -Tim

 --
 http://timboudreau.com

   -- 
 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 javascript:.
 To post to this group, send email to google...@googlegroups.com 
 javascript:.
 Visit this group at http://groups.google.com/group/google-guice.
 To view this discussion on the web visit https://groups.google.com/d/
 msgid/google-guice/be028525-1ced-4247-a051-49eb5262b86e%
 40googlegroups.com 
 https://groups.google.com/d/msgid/google-guice/be028525-1ced-4247-a051-49eb5262b86e%40googlegroups.com?utm_medium=emailutm_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.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at http://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/612dbfdf-02ab-48a6-9cc1-46a6708aa6d2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Best way to implement factory with Guice

2015-03-16 Thread Laszlo Ferenczi
Hi,

There are many ways to solve this problem, one easy enough to understand:

@Inject
ProviderCrawlerOne crawlerOneProvider;

@Inject
ProviderCrawlerTwo crawlerTwo;


public Crawler getCrawler(String url) {
if (url...) {
return crawlerOneProvider.get();
}
else {
return crawlerTwoProvider.get();
}
}


As an alternative you can inject the injector itself and get the instance
from it.

Also a slightly more advanced, but much more elgant way is to use
AssistedInject (it's exectly for this use case) See the guice docs for more
info.

PS: no need to make everything static, the whole point of the DI framework
that you don't need static anchors in your code.

--
L

--
L

On Sun, Mar 15, 2015 at 4:37 PM, Barak Yaish barak.ya...@gmail.com wrote:

 Hi,

 Doing my first steps with Guice, I thought the fastest way to understand
 it would migrate parts of existing application to Guice style. The
 application is kind of web crawler, and I have factory creating crawlers
 based on the input url:

 public static Crawler getCrawler( String url )
 {
 try
 {
 if( url.contains( www.site1.com ) )
 return new Site1( AppConfig.getInstance() );
 else if( url.contains( www.site2.com ) )
 return new Site2( AppConfig.getInstance() );
 }
 catch ( Exception e )
 {
 logger.error( failure, e );
 }

 return null;
 }


 Is the Guice version is only take the crawler instances from the injector
 and injecting the AppConfig?

 public static Crawler getCrawler( String url )
 {
 try
 {
 if( url.contains( www.site1.com ) )
 return GuiceInjector.getInstance( Site1.class );
 else if( url.contains( www.site2.com ) )
 return GuiceInjector.getInstance( Site2.class );
 }
 catch ( Exception e )
 {
 logger.error( failure, e );
 }

 return null;
 }

 Is there a better and/or more elegant way?

 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 http://groups.google.com/group/google-guice.
 To view this discussion on the web visit
 https://groups.google.com/d/msgid/google-guice/8911e587-58bd-4631-80a2-7a5d91007431%40googlegroups.com
 https://groups.google.com/d/msgid/google-guice/8911e587-58bd-4631-80a2-7a5d91007431%40googlegroups.com?utm_medium=emailutm_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.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at http://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/CAD-udUBRuBzSYL9-228W87Ab4fNSijVMSkeH7o0r6x4uQ3TbYQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Best way to implement factory with Guice

2015-03-16 Thread Barak Yaish
Thanks. Is there a way to overcome the exhausting if-else if- else if 
structure, some magical way to support new crawlers in the system without 
register them in that factory?

On Monday, March 16, 2015 at 3:57:56 PM UTC+2, Laszlo Ferenczi wrote:

 Hi,

 There are many ways to solve this problem, one easy enough to understand:

 @Inject
 ProviderCrawlerOne crawlerOneProvider;

 @Inject
 ProviderCrawlerTwo crawlerTwo;


 public Crawler getCrawler(String url) {
 if (url...) {
 return crawlerOneProvider.get();
 }
 else {
 return crawlerTwoProvider.get();
 }
 }


 As an alternative you can inject the injector itself and get the instance 
 from it.

 Also a slightly more advanced, but much more elgant way is to use 
 AssistedInject (it's exectly for this use case) See the guice docs for more 
 info.

 PS: no need to make everything static, the whole point of the DI framework 
 that you don't need static anchors in your code.

 --
 L

 --
 L

 On Sun, Mar 15, 2015 at 4:37 PM, Barak Yaish barak...@gmail.com 
 javascript: wrote:

 Hi,

 Doing my first steps with Guice, I thought the fastest way to understand 
 it would migrate parts of existing application to Guice style. The 
 application is kind of web crawler, and I have factory creating crawlers 
 based on the input url:

 public static Crawler getCrawler( String url )
 {
 try
 {
 if( url.contains( www.site1.com ) )
 return new Site1( AppConfig.getInstance() );
 else if( url.contains( www.site2.com ) )
 return new Site2( AppConfig.getInstance() );
 }
 catch ( Exception e )
 {
 logger.error( failure, e );
 }

 return null;
 }


 Is the Guice version is only take the crawler instances from the injector 
 and injecting the AppConfig?

 public static Crawler getCrawler( String url )
 {
 try
 {
 if( url.contains( www.site1.com ) )
 return GuiceInjector.getInstance( Site1.class );
 else if( url.contains( www.site2.com ) )
 return GuiceInjector.getInstance( Site2.class );
 }
 catch ( Exception e )
 {
 logger.error( failure, e );
 }

 return null;
 }

 Is there a better and/or more elegant way? 

 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 javascript:.
 To post to this group, send email to google...@googlegroups.com 
 javascript:.
 Visit this group at http://groups.google.com/group/google-guice.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/google-guice/8911e587-58bd-4631-80a2-7a5d91007431%40googlegroups.com
  
 https://groups.google.com/d/msgid/google-guice/8911e587-58bd-4631-80a2-7a5d91007431%40googlegroups.com?utm_medium=emailutm_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.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at http://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/c809db73-6456-493c-8047-95543ee382ef%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Best way to implement factory with Guice

2015-03-16 Thread Sam Berlin
Take a look at MapBinder or Multibinder:
https://github.com/google/guice/wiki/Multibindings

sam

On Mon, Mar 16, 2015 at 11:42 AM Barak Yaish barak.ya...@gmail.com wrote:

 Thanks. Is there a way to overcome the exhausting if-else if- else if
 structure, some magical way to support new crawlers in the system without
 register them in that factory?


 On Monday, March 16, 2015 at 3:57:56 PM UTC+2, Laszlo Ferenczi wrote:

 Hi,

 There are many ways to solve this problem, one easy enough to understand:

 @Inject
 ProviderCrawlerOne crawlerOneProvider;

 @Inject
 ProviderCrawlerTwo crawlerTwo;


 public Crawler getCrawler(String url) {
 if (url...) {
 return crawlerOneProvider.get();
 }
 else {
 return crawlerTwoProvider.get();
 }
 }


 As an alternative you can inject the injector itself and get the instance
 from it.

 Also a slightly more advanced, but much more elgant way is to use
 AssistedInject (it's exectly for this use case) See the guice docs for more
 info.

 PS: no need to make everything static, the whole point of the DI
 framework that you don't need static anchors in your code.

 --
 L


 --
 L

 On Sun, Mar 15, 2015 at 4:37 PM, Barak Yaish barak...@gmail.com wrote:

 Hi,

 Doing my first steps with Guice, I thought the fastest way to understand
 it would migrate parts of existing application to Guice style. The
 application is kind of web crawler, and I have factory creating crawlers
 based on the input url:

 public static Crawler getCrawler( String url )
 {
 try
 {
 if( url.contains( www.site1.com ) )
 return new Site1( AppConfig.getInstance() );
 else if( url.contains( www.site2.com ) )
 return new Site2( AppConfig.getInstance() );
 }
 catch ( Exception e )
 {
 logger.error( failure, e );
 }

 return null;
 }


 Is the Guice version is only take the crawler instances from the
 injector and injecting the AppConfig?

 public static Crawler getCrawler( String url )
 {
 try
 {
 if( url.contains( www.site1.com ) )
 return GuiceInjector.getInstance( Site1.class );
 else if( url.contains( www.site2.com ) )
 return GuiceInjector.getInstance( Site2.class );
 }
 catch ( Exception e )
 {
 logger.error( failure, e );
 }

 return null;
 }

 Is there a better and/or more elegant way?

 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 http://groups.google.com/group/google-guice.
 To view this discussion on the web visit https://groups.google.com/d/
 msgid/google-guice/8911e587-58bd-4631-80a2-7a5d91007431%
 40googlegroups.com
 https://groups.google.com/d/msgid/google-guice/8911e587-58bd-4631-80a2-7a5d91007431%40googlegroups.com?utm_medium=emailutm_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.
 To post to this group, send email to google-guice@googlegroups.com.
 Visit this group at http://groups.google.com/group/google-guice.
 To view this discussion on the web visit
 https://groups.google.com/d/msgid/google-guice/c809db73-6456-493c-8047-95543ee382ef%40googlegroups.com
 https://groups.google.com/d/msgid/google-guice/c809db73-6456-493c-8047-95543ee382ef%40googlegroups.com?utm_medium=emailutm_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.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at http://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/CAJEBNUdf-ihw7Fc67Rno2-k5-_wrfShBjK5Tn7FbNHq0dxLcGg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Best way to implement factory with Guice

2015-03-16 Thread Stephan Classen
Don't inject the injector. Its almost always a code smell.

Am 16. März 2015 14:57:13 MEZ, schrieb Laszlo Ferenczi lferen...@gmail.com:
Hi,

There are many ways to solve this problem, one easy enough to
understand:

@Inject
ProviderCrawlerOne crawlerOneProvider;

@Inject
ProviderCrawlerTwo crawlerTwo;


public Crawler getCrawler(String url) {
if (url...) {
return crawlerOneProvider.get();
}
else {
return crawlerTwoProvider.get();
}
}


As an alternative you can inject the injector itself and get the
instance
from it.

Also a slightly more advanced, but much more elgant way is to use
AssistedInject (it's exectly for this use case) See the guice docs for
more
info.

PS: no need to make everything static, the whole point of the DI
framework
that you don't need static anchors in your code.

--
L

--
L

On Sun, Mar 15, 2015 at 4:37 PM, Barak Yaish barak.ya...@gmail.com
wrote:

 Hi,

 Doing my first steps with Guice, I thought the fastest way to
understand
 it would migrate parts of existing application to Guice style. The
 application is kind of web crawler, and I have factory creating
crawlers
 based on the input url:

 public static Crawler getCrawler( String url )
 {
 try
 {
 if( url.contains( www.site1.com ) )
 return new Site1( AppConfig.getInstance() );
 else if( url.contains( www.site2.com ) )
 return new Site2( AppConfig.getInstance() );
 }
 catch ( Exception e )
 {
 logger.error( failure, e );
 }

 return null;
 }


 Is the Guice version is only take the crawler instances from the
injector
 and injecting the AppConfig?

 public static Crawler getCrawler( String url )
 {
 try
 {
 if( url.contains( www.site1.com ) )
 return GuiceInjector.getInstance( Site1.class );
 else if( url.contains( www.site2.com ) )
 return GuiceInjector.getInstance( Site2.class );
 }
 catch ( Exception e )
 {
 logger.error( failure, e );
 }

 return null;
 }

 Is there a better and/or more elegant way?

 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 http://groups.google.com/group/google-guice.
 To view this discussion on the web visit

https://groups.google.com/d/msgid/google-guice/8911e587-58bd-4631-80a2-7a5d91007431%40googlegroups.com

https://groups.google.com/d/msgid/google-guice/8911e587-58bd-4631-80a2-7a5d91007431%40googlegroups.com?utm_medium=emailutm_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.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at http://groups.google.com/group/google-guice.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-guice/CAD-udUBRuBzSYL9-228W87Ab4fNSijVMSkeH7o0r6x4uQ3TbYQ%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 http://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/EECDE6C4-3B12-43C5-B33D-839F717B8E69%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.