Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This document describes the procedure for upgrading project running on Slice 3.2.0 to the latest version - Slice 4.0.

  1. Update Slice version in pom.xml and set to 4.0.0, e.g.

    Code Block
    ...
    <dependency>
        <groupId>com.cognifide.slice</groupId>
        <artifactId>slice-core-api</artifactId>
        <version>4.0.0</version>
    </dependency>
    ...
  2. Update Activator. There's no need to setup context any more - the only object you need to create is InjectorRunner. More details here: Writing activator - 4.0.
    1. Remove ContextScope object.
    2. BASE_PACKAGE and BUNDLE_NAME_FILTER are now arguments of InjectorRunner's constructor - move them there.
  3. Context has been simplified  - 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:

    Code Block
    //old one
    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
    public void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) {
        try (InjectorWithContext injector = InjectorUtil.getInjector("myApp", request)) {      
            ModelProvider modelProvider = injector.getInstance(ModelProvider.class);      
            // do something clever with the model
        }
    }
    
    //new one in Java6
    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();
        }
    }
  4. 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.
  5. 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.