In order Slice to work, you have to write and set up activator of your application. The activator will be responsible for creating and storing injector of your application.
Example activator
Below The code presents below shows how an activator of your application should look like:
Code Block | ||||
---|---|---|---|---|
| ||||
package com.cognifide.app.core; import java.util.ArrayList; import java.util.List; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import com.cognifide.slice.api.context.ContextScope; import com.cognifide.slice.api.injector.InjectorRunner; import com.cognifide.slice.commons.SliceModulesFactory; import com.cognifide.slice.core.internal.context.SliceContextScope; import com.cognifide.slice.cq.module.CQModulesFactory; import com.cognifide.slice.validation.ValidationModulesFactory; import com.google.inject.Module; public class Activator implements BundleActivator { private static final String BUNDLE_NAME_FILTER = "com\\.cognifide\\.app\\..*"; private static final String BASE_PACKAGE = "com.cognifide.app"; private static final String INJECTOR_NAME = "myapp"; @Override public void start(BundleContext bundleContext) throws Exception { final ContextScope scope = new SliceContextScope(); final InjectorRunner injectorRunner = new InjectorRunner(bundleContext, INJECTOR_NAME, scope); List<Module> sliceModules = SliceModulesFactory.createModules(bundleContext, INJECTOR_NAME, BUNDLE_NAME_FILTER, BASE_PACKAGE); List<Module> cqModules = CQModulesFactory.createModules(); List<Module> validationModules = ValidationModulesFactory.createModules(); List<Module> customModules = createCustomModules(); injectorRunner.installModules(sliceModules); injectorRunner.installModules(cqModules); injectorRunner.installModules(validationModules); injectorRunner.installModules(customModules); injectorRunner.start(); } private List<Module> createCustomModules() { List<Module> applicationModules = new ArrayList<Module>(); //populate the list with your modules return applicationModules; } } |
...