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 [email protected].
To post to this group, send email to [email protected].
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.
For more options, visit https://groups.google.com/d/optout.