I decided to write my experience with Guice and how I have used it but before moving fwd Would like to announce it has nothing to do with Guice Tutorial or Guide. It's about my experience with Guice and it's usages as I conceived.
First I would like to announce that Guice has made my life hell lot easier and organised. I may not be the expert but would not mind to achieve the pinnacle :).
Without contradicting I model Guice into 2 parts. Binder and Injector.
"Without Binding no Injection" - was quite clear in first read.
But I wanted more. How I can use Binding along as I see it as a tool to provide me instance of class. But how to achive it was the question.
But I discovered the answer but may or may not be the best but who wants to be the best ?
"Best is degrading"
I create ClassInstanceLocator.
My life became so easy after this beautiful piece of code. Infact I sometime feel, I am abusing it and become so much addictive of it that I have stop using new. Any way the whole idea of life is to make it more simple.
I can count lot of benefit if I am using it like this.
Adios
Prabhat
First I would like to announce that Guice has made my life hell lot easier and organised. I may not be the expert but would not mind to achieve the pinnacle :).
Without contradicting I model Guice into 2 parts. Binder and Injector.
"Without Binding no Injection" - was quite clear in first read.
But I wanted more. How I can use Binding along as I see it as a tool to provide me instance of class. But how to achive it was the question.
But I discovered the answer but may or may not be the best but who wants to be the best ?
"Best is degrading"
I create ClassInstanceLocator.
public class ClassInstanceLocator { private static Injector injector = null; /** * Get Class Instance */ public static <T> T getInstance(final Class<T> t) { return injector.getInstance(t); } /** * Initialize Modules during bootstraping. * It should be initialized during bootstraping thus making it thread aware. * * @param modules */ public synchronized static void initializeModule(final AbstractModule... modules) { /* Common module should iniitialized as rest module depends on it * One can make it conditional so that once *commond is initialized should not be initialized again */ if(injector==null){ injector = Guice.createInjector(new CommonModule()); } if (modules != null) { injector = injector.createChildInjector(modules); } } /** * Destroys Guice injection tree */ public synchronized static void deInitializeModules() { injector = null; } /** * * @return - Are modules Initialized */ public static boolean isModulesInitialized() { return injector != null; } }
My life became so easy after this beautiful piece of code. Infact I sometime feel, I am abusing it and become so much addictive of it that I have stop using new. Any way the whole idea of life is to make it more simple.
I can count lot of benefit if I am using it like this.
- I can always change my implementation from single place without changing it's usages even if it's a concrete class.
- I can always make class instance as Singleton as and when I need.
There are many more I am sure. Without doubt it's Guice which gives me this liberty, But I am just trying to maximize on it.
Happy Injecting happyness in life.
Adios
Prabhat
I admire your work , regards for all of the valuable weblog posts….mobile repair training institute in hyderabad
ReplyDeleteyour blog is really nice and informative and it is really exclusive ,i got more information from your article please update this kind of information.
ReplyDeleteHadoop Training in Chennai
Great post!! This can be one particular of the most useful blogs We’ve ever arrive across on this subject. Basically Wonderful. I am also a specialist in this topic so I can understand your hard work.
ReplyDeleteLinux Training in Chennai Mylapore
I really appreciate the kind of topics post here. Thanks for sharing us a great information that is actually helpful. Good day! bandar judi bola
ReplyDeleteartikel yang bagus dan menarik
ReplyDeleteSekedar Sharing GUSTIBET PROMO DEPOSIT 10RB DAPAT FREECHIP 5B
Salam gustibet.net
Agen Togel Online
Markas Judi Online
Agen Bola Online
Situs Togel Online
Bandar Judi Online
Markas Casino Online
Markas Togel Online
Situs Slot Online
Agen Casino Online
Bandar Bola Online
Bandar Casino Online
You have a good articel , i really like it , because when i read your articel i can feel what you write.
ReplyDeletelets visit my our articel here :
Daftar Poker Online
Poker Online Terpercaya
Situs Poker Online
Capsa Susun Online
Poker Uang Asli
poker tanpa deposit
Bambu Poker
BambuPoker
Daftar Bambupoker
Link Alternatif BambuPoker
our alternatif link at here :
Daftar Poker Online
Poker Online Terpercaya
Situs Poker Online
Capsa Susun Online
Poker Uang Asli
poker tanpa deposit
Bambu Poker
BambuPoker
Daftar Bambupoker
Link Alternatif BambuPoker
thankyou , Bambupoker.