io.github.factoryfx.microservice.rest.MicroserviceResourceFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of microserviceRestServer Show documentation
Show all versions of microserviceRestServer Show documentation
factoryfx dependency injection framework
package io.github.factoryfx.microservice.rest;
import io.github.factoryfx.factory.FactoryBase;
import io.github.factoryfx.factory.attribute.dependency.FactoryPolymorphicAttribute;
import io.github.factoryfx.server.Microservice;
import io.github.factoryfx.server.user.nop.NoUserManagement;
import io.github.factoryfx.server.user.UserManagement;
import io.github.factoryfx.server.user.nop.NoUserManagementFactory;
import io.github.factoryfx.server.user.persistent.PersistentUserManagementFactory;
/**
* usage example: (in a FactoryTreeBuilder)
*
* {@code
new JettyServerBuilder<>(new ShopJettyServerFactory())
.withHost("localhost").withPort(8089)
.withResource(context.getUnsafe(MicroserviceDomResourceFactory.class))
...
factoryTreeBuilder.addFactory(MicroserviceDomResourceFactory.class, Scope.SINGLETON, context -> {
return new MicroserviceDomResourceFactory();
});
* }
*
* (the messed up generics are caused by java limitations)
*
* @param root
* @param Summary Data form storage history
*/
public class MicroserviceResourceFactory,S> extends FactoryBase,R> {
public final FactoryPolymorphicAttribute userManagement = new FactoryPolymorphicAttribute().setupUnsafe(UserManagement.class, NoUserManagementFactory.class, PersistentUserManagementFactory.class).labelText("resource").nullable();
@SuppressWarnings("unchecked")
public MicroserviceResourceFactory(){
configLifeCycle().setCreator(() -> {
UserManagement userManagementInstance = userManagement.instance();
if (userManagementInstance==null) {
userManagementInstance=new NoUserManagement();
}
Microservice,R,S> microservice = (Microservice,R,S>) utility().getMicroservice();
return new MicroserviceResource<>(microservice, userManagementInstance);
});
config().setDisplayTextProvider(()->"Resource");
}
}