You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using peaberry, I always get the same instance of an object.
I don't specify the binding as being a Singleton Scope or use the @Singleton annotation
on the class. The binding is however annotated (with @Server).
How do I get a unique instance? (A non-singleton).
Am I using Peaberry wrongly?
Bundle1:
--------
Module1:
bind(export(IDataProvider.class)).annotatedWith(Server.class)
.toProvider(service(ServerCDODataProvider.class).export());
Activator1:
@Inject
@Server
Export<IDataProvider> dataProvider;
.... start(BundleContext ctx){
createInjector(osgiModule(ctx), new Module1()).injectMembers();
Bundle2:
-------
Module2:
bind(IDataProvider.class).annotatedWith(Server.class).toProvider(
service(IDataProvider.class).single());
ConsumerClass1:
@Inject
@Server
IDataProvider provider1
ConsumerClass2:
@Inject
@Server
IDataProvider provider2
provider1 == provider2 => true
Reported by bouhier.c on 2013-06-07 08:50:22
The text was updated successfully, but these errors were encountered:
Peaberry works on top of OSGi services, so the reason you only see one instance is because
the service is a singleton and not a ServiceFactory: http://www.osgi.org/javadoc/r4v43/core/org/osgi/framework/ServiceFactory.html
The multiple() method is for situations where there are multiple services registered
to the same interface and you want to see all these services. Otherwise with single()
you would only see the highest-ranked matching service.
If you want to get multiple copies of the same service then you need to implement ServiceFactory
- peaberry should then export the service as a ServiceFactory and you should then be
able to get a new instance per-bundle. If you want to generate multiple instances per-bundle
then you need to write your own factory API and export that as a service for the other
bundles to consume.
Originally reported on Google Code with ID 82
Reported by
bouhier.c
on 2013-06-07 08:50:22The text was updated successfully, but these errors were encountered: