Loading... Cancel

LightObjectBOX IoC container — example R

October 29th, 2006

I usually like less xml configuration, i have a tiny project… IDEAStickyPlugin which is running as IntelliJ IDEA Plugin.

recently i got interest to support IDEASticky as a desktop standalone application, at least for my Ubuntu based pc, (i am not satisfy with Sticky notes and Tomboy).
these days i am working on this stuff. so i felt a tiny light weight IoC container,(though PicoContainer is better) no XML level configuration will be a good addition…

so yesterday evening i made the first test case and implemented the tiny container, here is few example code snaps:

@LightObjectName( name = “a” )
public class A {
……
@LightObjectKey( key = “b” )
public void setB(B b) {
this.b = b;
}
……
}

@LightObjectName( name = “b” )
public class B {
…..
@LightObjectKey( key = “a” )
public void setA(A a) {
this.a = a;
}
…..
}

here @LightObjectName annotation is used to define an object name, this name will be used to store in container.
@LightObjectKey annotation is used to define dependent object. it will be set through the setter on container initialization time.
also cyclic dependency has no problem.

sample usages:

mContainer = LightObjectBox.createBox();
mContainer.add( A.class );
mContainer.add( B.class );
mContainer.init();

here i have created an instance of LightObjectBox though createBox() and ..
add(
Class ) is used to register a component into container scope. later init(); invocation initialize all classes + dependencies …

so i can recall my object instance by “A a = mContainer.getObject( “a” );”
i will publish whole source code after completing my IDEASticky Standalone :) keep reading my blog :)

Total 1 response found

Close
  •   Aawaj

    Thu Jan 70 06:33

    Bhai jaan,
    I can't able to understand everyting ... :(
    Becouse i have no knowledge about JAVA Language. But i'll ... learn it...
    But i know you are well in JAVA. :)
    Go ahead Hasan bhai...
    Aawaj

Posted in Java, Java SE