Upgrade procedure - 4.0
This document describes the procedure for upgrading project running on Slice 3.2.0 to the latest version - Slice 4.0.
Update Slice version in
pom.xml and set to 4.0.0
, e.g.... <dependency> <groupId>com.cognifide.slice</groupId> <artifactId>slice-core-api</artifactId> <version>4.0.0</version> </dependency> ...
- Update
Activator
. There's no need to setup context any more - the only object you need to create isInjectorRunner
. More details here: Writing activator - 4.0.- Remove
ContextScope
object. BASE_PACKAGE
andBUNDLE_NAME_FILTER
are now arguments ofInjectorRunner
's constructor - move them there.
- Remove
Context improvements.
the
ContextProviderFactory
does not longer exist. A snippet of code needed to get an injector in servlets or OSGi services should be rewritten as follows://old one - Slice 3.2 public void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) { InjectorWithContext injector = injectorsRepo.getInjector("appName"); ContextProviderFactory contextProviderFactory = injector.getInstance(ContextProviderFactory.class); SimpleContextProvider simpleContextProvider = contextProviderFactory.getSimpleContextProvider(); ContextFactory contextFactory = injector.getInstance(ContextFactory.class); simpleContextProvider.setContext(contextFactory.getServletRequestContext(request, response)); injector.pushContextProvider(simpleContextProvider); try { ModelProvider modelProvider = injector.getInjector().getInstance(ModelProvider.class); //do your stuff } finally { injector.popContextProvider(); } } //new one - Slice 4.0 public void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) { try (InjectorWithContext injector = InjectorUtil.getInjector("myApp", request)) { ModelProvider modelProvider = injector.getInstance(ModelProvider.class); // do your stuff } } //new one in Java6 - Slice 4.0 public void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) { InjectorWithContext injector = InjectorUtil.getInjector("myApp", request); try { ModelProvider modelProvider = injector.getInstance(ModelProvider.class); // do something clever with the model } finally { injector.close(); } }
If you don't use custom contexts - skip this step. If use are using a custom contexts and
ContextProviderFactory
(which has been removed) you may want to use a newConstantContextProvider
which has a similar purpose.//Slice 3.2 Context myContext = createContext(); ContextProviderFactory providerFactory = injector.getInstance(ContextProviderFactory.class); SimpleContextProvider contextProvider = providerFactory.getSimpleContextProvider(); contextProvider.setContext(myContext); injector.pushContextProvider(contextProvider); //Slice 4.0 Context myContext = createContext(); ContextProvider contextProvider = new ConstantContextProvider(myContext ); injector.pushContextProvider(contextProvider);
- Link API has been removed. If you want it back, fell free to take it out of Slice 3.2.0 source code: https://github.com/Cognifide/Slice/tree/3.2.0. You will need to register a link module (see example) in the list of your modules in activator.
- Validation API has been removed. If you want it back, fell free to take it out of Slice 3.2.0 source code: https://github.com/Cognifide/Slice/tree/3.2.0. You will need to register a link module (see example) in the list of your modules in activator.