use of org.b3log.latke.ioc.config.Configurator in project latke by b3log.
the class Lifecycle method startApplication.
/**
* Starts the application with the specified bean class and bean modules.
*
* @param classes the specified bean class, nullable
* @param beanModule the specified bean modules
*/
public static void startApplication(final Collection<Class<?>> classes, final BeanModule... beanModule) {
LOGGER.log(Level.DEBUG, "Initializing Latke IoC container");
beanManager = LatkeBeanManagerImpl.getInstance();
applicationContext.setActive(true);
beanManager.addContext(applicationContext);
final Configurator configurator = beanManager.getConfigurator();
if (null != classes && !classes.isEmpty()) {
configurator.createBeans(classes);
}
if (null != beanModule && 0 < beanModule.length) {
for (int i = 0; i < beanModule.length; i++) {
configurator.addModule(beanModule[i]);
}
}
LOGGER.log(Level.DEBUG, "Initialized Latke IoC container");
}
use of org.b3log.latke.ioc.config.Configurator in project latke by b3log.
the class SpeakerUnitTest method beforeTest.
@BeforeTest
@SuppressWarnings("unchecked")
public void beforeTest() throws Exception {
System.out.println("before SpeakerUnitTest");
Latkes.initRuntimeEnv();
beanManager = LatkeBeanManagerImpl.getInstance();
Lifecycle.startApplication(speakerPackageClasses);
final Configurator configurator = beanManager.getConfigurator();
// Create beans by APIs approach
configurator.createBean(HelloSpeaker.class).qualified(new HelloLiteral());
configurator.createBean(NightSpeaker.class).qualified(new NightLiteral());
configurator.createBean(MidnightSpeaker.class).qualified(new MidnightLiteral());
final Set<Annotation> helloSpeakerQualifiers = new HashSet<Annotation>();
helloSpeakerQualifiers.add(new HelloLiteral());
helloSpeakerQualifiers.add(new NamedLiteral("helloSpeaker"));
final LatkeBean<?> helloSpeakerBean = beanManager.getBean(Speaker.class, helloSpeakerQualifiers);
helloSpeaker = (HelloSpeaker) beanManager.getReference(helloSpeakerBean);
assertNotNull(helloSpeaker);
configurator.validate();
final Set<Annotation> morningSpeakerQualifiers = new HashSet<Annotation>();
morningSpeakerQualifiers.add(new MorningLiteral());
morningSpeakerQualifiers.add(new NamedLiteral("morningSpeaker"));
final LatkeBean<?> morningSpeakerBean = beanManager.getBean(Speaker.class, morningSpeakerQualifiers);
morningSpeaker = (MorningSpeaker) beanManager.getReference(morningSpeakerBean);
assertNotNull(morningSpeaker);
final Set<Annotation> speakerQualifiers = new HashSet<Annotation>();
speakerQualifiers.add(new NamedLiteral("speakerService"));
final LatkeBean<?> speakerProviderBean = beanManager.getBean(SpeakerService.class, speakerQualifiers);
speakerProvider = (SpeakerService) beanManager.getReference(speakerProviderBean);
assertNotNull(speakerProvider);
}
use of org.b3log.latke.ioc.config.Configurator in project latke by b3log.
the class BottleUnitTest method beforeTest.
@BeforeTest
@SuppressWarnings("unchecked")
public void beforeTest() throws Exception {
System.out.println("before BottleUnitTest");
Latkes.initRuntimeEnv();
Lifecycle.startApplication(drinkPackageClasses);
beanManager = LatkeBeanManagerImpl.getInstance();
// Creates bean by APIs
final Configurator configurator = beanManager.getConfigurator();
configurator.createBean(Mix.class).named("spiritMix").scoped(Singleton.class).qualified(new OddLiteral());
// Validate after bean configuration
configurator.validate();
final LatkeBean<?> wineBottleBean = beanManager.getBean(WineBottle.class);
assertNotNull(wineBottleBean);
wineBottle = (WineBottle) beanManager.getReference(wineBottleBean);
assertNotNull(wineBottle);
final LatkeBean<?> juiceBottleBean = beanManager.getBean(JuiceBottle.class);
assertNotNull(juiceBottleBean);
juiceBottle = (JuiceBottle) beanManager.getReference(juiceBottleBean);
assertNotNull(juiceBottle);
final LatkeBean<?> mixBottleBean = beanManager.getBean(MixBottle.class, new HashSet<Annotation>());
mixBottle = (MixBottle) beanManager.getReference(mixBottleBean);
assertNotNull(mixBottle);
}
Aggregations