1 Reply Latest reply on Jan 16, 2013 10:35 AM by Harvey Raja-Oracle

    Plugging in custom serializer with dependencies

      I'm attempting to use Google Guice with Coherence. I've managed to successfully delegate to Guice for dependency injection when creating a cachestore, using a custom ConfigurableCacheFactory and overriding instantiateAny in the same way as with the Spring examples.

      I would also like to get access to the Guice injector to pass some dependencies to a custom serializer (so it can pass them on to objects it deserializes). I can't find any hooks to wire this up - instantiateAny isn't called for serializers. There's a class called ConfigurableSerializerFactory that looks promising but I can't see any docs on how this can be used. Any suggestions?

      Edited by: 937651 on 09-Jan-2013 03:42
        • 1. Re: Plugging in custom serializer with dependencies
          Harvey Raja-Oracle

          I assume you are using POF and is a PofSerializer that you want to pass dependencies to. One option is to provide a custom PofContext implementation, more than likely an extension of ConfigurablePofContext. There would be two strategies; to inject dependencies upon serializer creation or upon access to the serializer for de/serialzing an object. Generally I would have thought the former as a more efficient mechanism however the latter can be carried out with an easier hook.

          To achieve dependency injection of serializer creation in 3.7.1 you will have to provide your own implementation of createPofConfig. You could delegate to the parent (CPC) and walk through the serializers performing your injection to avoid having to re-write the logic in createPofConfig. In the next major release of Coherence we have teased these two things apart a little such that there is an overridable method for creating custom serializers. The alternative is to inject upon access which you could achieve by overriding CPC.getPofSerializer. You may want to put some effort in ensuring this has a small cost.