use of com.tvd12.ezyfox.bean.EzyBeanContextBuilder in project calabash by youngmonkeys.
the class ServerCoreBaseTest method newBeanContext.
protected EzyBeanContext newBeanContext() {
MongoClient mongoClient = newMongoClient();
EzyBeanContextBuilder builder = EzyBeanContext.builder().addSingleton("mongoClient", mongoClient).scan("com.tvd12.calabash.local.test.mappersist");
addAutoImplMongoRepo(builder, mongoClient);
return builder.build();
}
use of com.tvd12.ezyfox.bean.EzyBeanContextBuilder in project ezyfox-server-example by tvd12.
the class PluginEntry method setupBeanContext.
@Override
protected void setupBeanContext(EzyPluginContext context, EzyBeanContextBuilder builder) {
EzyPluginSetting setting = context.getPlugin().getSetting();
String pluginConfigFile = getConfigFile(setting);
PluginConfig pluginConfig = readPluginConfig(pluginConfigFile);
logger.info("simple-chat plugin config: {}", pluginConfig);
}
use of com.tvd12.ezyfox.bean.EzyBeanContextBuilder in project ezyfox-server by youngmonkeys.
the class EzySimpleAppEntry method createBeanContext.
protected EzyBeanContext createBeanContext(EzyAppContext context) {
EzyBindingContext bindingContext = createBindingContext();
EzyMarshaller marshaller = bindingContext.newMarshaller();
EzyUnmarshaller unmarshaller = bindingContext.newUnmarshaller();
EzyResponseFactory appResponseFactory = createAppResponseFactory(context, marshaller);
ScheduledExecutorService executorService = context.get(ScheduledExecutorService.class);
EzyAppSetting appSetting = context.getApp().getSetting();
EzyBeanContextBuilder beanContextBuilder = EzyBeanContext.builder().addSingleton("appContext", context).addSingleton("marshaller", marshaller).addSingleton("unmarshaller", unmarshaller).addSingleton("executorService", executorService).addSingleton("zoneContext", context.getParent()).addSingleton("serverContext", context.getParent().getParent()).addSingleton("userManager", context.getApp().getUserManager()).addSingleton("appResponseFactory", appResponseFactory).addSingleton("featureCommandManager", new EzyFeatureCommandManager()).addSingleton("requestCommandManager", new EzyRequestCommandManager()).activeProfiles(appSetting.getActiveProfiles());
Class[] singletonClasses = getSingletonClasses();
beanContextBuilder.addSingletonClasses(singletonClasses);
Class[] prototypeClasses = getPrototypeClasses();
beanContextBuilder.addPrototypeClasses(prototypeClasses);
Set<String> scanablePackages = internalGetScanableBeanPackages();
if (appSetting.getPackageName() != null) {
scanablePackages.add(appSetting.getPackageName());
}
EzyReflection reflection = new EzyReflectionProxy(scanablePackages);
beanContextBuilder.addSingletonClasses((Set) reflection.getAnnotatedExtendsClasses(EzyEventHandler.class, EzyAppEventController.class));
beanContextBuilder.addSingletonClasses((Set) reflection.getAnnotatedClasses(EzyRequestController.class));
beanContextBuilder.addSingletonClasses((Set) reflection.getAnnotatedClasses(EzyExceptionHandler.class));
beanContextBuilder.addSingletonClasses((Set) reflection.getAnnotatedClasses(EzyRequestInterceptor.class));
beanContextBuilder.scan(scanablePackages);
setupBeanContext(context, beanContextBuilder);
return beanContextBuilder.build();
}
use of com.tvd12.ezyfox.bean.EzyBeanContextBuilder in project ezyfox-server by youngmonkeys.
the class EzySimplePluginEntry method createBeanContext.
private EzyBeanContext createBeanContext(EzyPluginContext context) {
EzyBindingContext bindingContext = createBindingContext();
EzyMarshaller marshaller = bindingContext.newMarshaller();
EzyUnmarshaller unmarshaller = bindingContext.newUnmarshaller();
EzyResponseFactory pluginResponseFactory = createPluginResponseFactory(context, marshaller);
ScheduledExecutorService executorService = context.get(ScheduledExecutorService.class);
EzyPluginSetting pluginSetting = context.getPlugin().getSetting();
EzyBeanContextBuilder beanContextBuilder = EzyBeanContext.builder().addSingleton("pluginContext", context).addSingleton("marshaller", marshaller).addSingleton("unmarshaller", unmarshaller).addSingleton("executorService", executorService).addSingleton("zoneContext", context.getParent()).addSingleton("serverContext", context.getParent().getParent()).addSingleton("pluginResponseFactory", pluginResponseFactory).addSingleton("featureCommandManager", new EzyFeatureCommandManager()).addSingleton("requestCommandManager", new EzyRequestCommandManager()).activeProfiles(pluginSetting.getActiveProfiles());
Class[] singletonClasses = getSingletonClasses();
beanContextBuilder.addSingletonClasses(singletonClasses);
Class[] prototypeClasses = getPrototypeClasses();
beanContextBuilder.addPrototypeClasses(prototypeClasses);
Set<String> scanablePackages = internalGetScanableBeanPackages();
if (pluginSetting.getPackageName() != null) {
scanablePackages.add(pluginSetting.getPackageName());
}
EzyReflection reflection = new EzyReflectionProxy(scanablePackages);
beanContextBuilder.addSingletonClasses((Set) reflection.getAnnotatedExtendsClasses(EzyEventHandler.class, EzyPluginEventController.class));
beanContextBuilder.addSingletonClasses((Set) reflection.getAnnotatedClasses(EzyRequestController.class));
beanContextBuilder.addSingletonClasses((Set) reflection.getAnnotatedClasses(EzyExceptionHandler.class));
beanContextBuilder.addSingletonClasses((Set) reflection.getAnnotatedClasses(EzyRequestInterceptor.class));
beanContextBuilder.scan(scanablePackages);
setupBeanContext(context, beanContextBuilder);
return beanContextBuilder.build();
}
use of com.tvd12.ezyfox.bean.EzyBeanContextBuilder in project ezyhttp by youngmonkeys.
the class GraphQLConfigurationTest method test.
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void test() throws NoSuchFieldException, IllegalAccessException {
// given
EzyBeanContextBuilder builder = new EzySimpleBeanContext.Builder();
Set<String> packagesToScan = RandomUtil.randomSet(8, String.class);
packagesToScan.add("com.tvd12.ezyhttp.server.graphql.test.config");
for (String p : packagesToScan) {
builder.scan(p);
}
EzyBeanContext context = builder.build();
GraphQLConfiguration sut = new GraphQLConfiguration();
EzySingletonFactory singletonFactory = context.getSingletonFactory();
sut.setSingletonFactory(singletonFactory);
sut.setObjectMapper(new ObjectMapper());
sut.setGraphQLEnable(true);
// when
sut.config();
GraphQLController controller = (GraphQLController) singletonFactory.getSingleton(GraphQLController.class);
Field dataFetcherManagerField = GraphQLController.class.getDeclaredField("dataFetcherManager");
dataFetcherManagerField.setAccessible(true);
GraphQLDataFetcherManager dataFetcherManager = (GraphQLDataFetcherManager) dataFetcherManagerField.get(controller);
Field dataFetchersField = GraphQLDataFetcherManager.class.getDeclaredField("dataFetchers");
dataFetchersField.setAccessible(true);
Map<String, GraphQLDataFetcher> dataFetchers = (Map<String, GraphQLDataFetcher>) dataFetchersField.get(dataFetcherManager);
// then
Asserts.assertNotNull(controller);
Asserts.assertTrue(dataFetchers.containsKey("A"));
}
Aggregations