Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [sisu-users] Multiple ClassSpaces

Hi Alex,

With Sisu you don’t need to create a child injector for new bundles - as long as you use the same BeanLocator across bundles they will share components.

For example, assuming you had a BeanLocator instance called “locator” and two bundles “bundleA” and “bundleB”:

LocatorModule locatorModule = new AbstractModule() {
@Override
protected void configure() {
bind(BeanLocator.class).toInstance(locator);
}
};

Guice.createInjector(
new WireModule(
locatorModule, new SpaceModule(new BundleClassSpace(bundleA))
)
);

Guice.createInjector(
new WireModule(
locatorModule, new SpaceModule(new BundleClassSpace(bundleB))
)
);

Then components in bundleA will be able to inject components from bundleB, and vice-versa.

If you really need to use a child injector for a particular reason then you should use ChildWireModule in place of WireModule:

parent.createChildInjector(
new ChildWireModule(
// … additional modules specific to the child
)
);

Note that bindings in the parent will take precedence over any supplied by the child (as in plain Guice).

-- 
Cheers, Stuart

On Friday, 4 September 2015 at 23:41, Alex Edwards wrote:

Hello,

We have an osgi bundle that uses sisu + peaberry to wire up the guice
injector with our beans and services. At runtime we are trying to create
a new child Injector for the new bundles and were expecting sisu to be
able to scan that bundle and do the wiring of those new beans but we get
an error:

[INFO] [talledLocalContainer] 1) A binding to
org.eclipse.sisu.space.ClassSpace was already configured at
org.eclipse.sisu.space.SpaceModule.configure(SpaceModule.java:121) (via
modules: org.eclipse.sisu.launch.BundleModule ->
org.eclipse.sisu.space.SpaceModule).
[INFO] [talledLocalContainer] at
org.eclipse.sisu.space.SpaceModule.configure(SpaceModule.java:121)
[INFO] [talledLocalContainer]

Is this expected behaviour?
Should we be able to scan multiple class spaces?

thanks
Alex


Alex Edwards, Software Engineer
Phone: +1.604.408.8078 ext. 158
LinkedIn:

Elastic Path Software Inc.

Confidentiality Notice: This message is intended only for the use of the designated addressee(s), and may contain information that is privileged, confidential and exempt from disclosure. Any unauthorized viewing, disclosure, copying, distribution or use of information contained in this e-mail is prohibited and may be unlawful. If you received this e-mail in error, please reply to the sender immediately to inform us you are not the intended recipient and delete the email from your computer system. Thank you.

_______________________________________________
sisu-users mailing list
To change your delivery options, retrieve your password, or unsubscribe from this list, visit


Back to the top