我有一个如下的集合
{
"state" : "VIC",
"sites" :
[
{
"name" : "VIC01",
"pes" :
[
{
"id" : "1",
"longname" : "rdnvej300exh0443",
"shortname" : "RVE4-E-043",
"location" : "Exhibition"
},
{
"id" : "2",
"longname" : "rdnvej160pee0343",
"shortname" : "RV3W-E-043",
"location" : "Windsor"
},
{
"id" : "3",
"location" : "my home"
}
],
"partners" :
[
{
"id" : "REACH",
"fnns" : ["N54321R","N24686R","N46818R","N10461R"]
},
{
"id" : "NCS_CORE",
"fnns" : [ "N54320R","N71311R","N35797R","N57919R"]
}
]
},
{
"name" : "CLAYTON",
"pes" …Run Code Online (Sandbox Code Playgroud) 我试图了解 HK2 Factory 在 Jersey 应用程序中的实现。
目标:如何实现单例工厂?
// Below is the simple factory implementation
public class MyFactory implements Factory<SomeObject> {
private static final Logger logger = LoggerFactory.getLogger(MyFactory.class);
private final CloseableService closeService;
@Inject
public MyFactory(CloseableService closeService) {
this.closeService = closeService;
}
@Override
public MyFactory provide() {
logger.debug("provide object from MyFactory");
SomeObject objectFromFactory = new SomeObject();
this.closeService.add(() -> dispose(objectFromFactory));
return objectFromFactory;
}
@Override
public void dispose(SomeObject instance) {
// destroy instance
logger.debug("dispose object from MyFactory");
}
}
// and binding
bindFactory(MyFactory.class).to(SomeObject.class).in(Singelton.class);
// …Run Code Online (Sandbox Code Playgroud)