peaberry 1.0 RC1:Gucie的动态服务扩展
peaberry 1.0 RC1发布,它是Gucie的一个扩展库,支持动态服务的依赖注入。它为OSGi集成提供了一些创新的技术,而且还为其他的registry-based服务框架提供了插件。它可以被放置到任何R4的框架中,例如:Apache Felix 或 Eclipse/Equinox。
下面我们来看一个例子:
import static org.ops4j.peaberry.Peaberry.service;
import static org.ops4j.peaberry.util.TypeLiterals.export;
import static org.ops4j.peaberry.util.TypeLiterals.iterable;
Injecting a stock quote service
@Inject
StockQuote quote;
...
bind(StockQuote.class).to(service(StockQuote.class).single());
Injecting many stock quote services
@Inject
Iterable<StockQuote> quotes;
...
bind(iterable(StockQuote.class)).to(service(StockQuote.class).multiple());
Exporting an implementation as a stock quote service
@Inject
Export<StockQuote> exportedQuote;
...
bind(export(StockQuote.class)).to(service(myQuoteImpl).export());
Watching for a stock quote service
@Inject
StockQuote quote;
...
// the watching scope is notified as stock services are added, modified, or removed
bind(StockQuote.class).to(service(StockQuote.class).out(watchingScopeImpl).single());
点击查看更多例子:http://code.google.com/p/peaberry/wiki/UserGuide
如果发现任何错误,可以随时加入小组的讨论。