SoCreate / service-fabric-distributed-cache

MIT License
36 stars 19 forks source link

Support for custom serialization providers #32

Closed dvera-phs closed 1 year ago

dvera-phs commented 2 years ago

This change adds support for using custom serialization providers in the communication between ServiceFabric services. I've tested this change using Microsoft's sample JSON SerializationProvider, but any provider should be able to be passed in when the service is created at startup. Identical custom serializers will need to be passed into both the client facing service and the internal service.

For example, when using the JSON Serializer in ClientApp and DistributedCacheStore, we'd do the following to register the SerializationProvider:

ClientApp/Startup.cs

services.Configure<ServiceFabricCacheOptions>(o => {
    o.RetryTimeout = TimeSpan.FromSeconds(5);
    o.SerializationProvider = new ServiceRemotingJsonSerializationProvider();
  });

DistributedCacheStore/DistributedCacheStore.cs

public DistributedCacheStore(StatefulServiceContext context)
   : base(context, (message) => ServiceEventSource.Current.ServiceMessage(context, message), serializationProvider: new ServiceRemotingJsonSerializationProvider())
 { }