Should I use more than one IOC containers within one class

1 view
Skip to first unread message

jokoul webster

unread,
Nov 25, 2009, 5:42:14 AM11/25/09
to jEmbedded Discussion Group
Hi Adolfo:
If I wanna use more than one IOC containers(e.g Spring and
jEmbedded) within one class,could I do that?
===================================================
@SpringRepository(...)
@Repository(....iocProviders = {"springRepository"})
public class MyTest{

@Inject(ref = "aServiceFromSpring")
private Object....


@Inject(ref = "bServiceFromJembedded")
private Object....

}
===================================================


JK.Webster

Adolfo Estevez

unread,
Nov 25, 2009, 7:15:55 AM11/25/09
to jEmbedded Discussion Group
Hi Jokoul,

I suppose you mean another jEmbedded container apart from the one that
is creating the class MyTest?

If that's what you mean, you can do that using the @Repository
annotation as it creates another container (well almost).

@Repository(id="container", resources={ServiceFromJembedded.class},...
managedElements={bServiceFromJembedded})
public class Container{

}

@SpringRepository(...)
@Repository(....iocProviders = {"springRepository"})
@Include(resources=Container.class)
public class MyTest{

@Inject(ref = "bServiceFromJembedded")
private Object....
}

Also you can create a hierarchy:


@SpringRepository(...)
@Repository(....iocProviders = {"springRepository"},
parent="container")

public class MyTest{

@Inject(ref = "bServiceFromJembedded")
private Object....
}

Hope this helps.

Adolfo
Reply all
Reply to author
Forward
0 new messages