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.

  1. 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>
    ...
  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 improvements.

    1.  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();
          }
      }
    2. 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 new ConstantContextProvider 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);
  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.