I am looking to have a generic type service ie -
public interface IFooService<T>
{
Task<T> Get(int id);
}
However, service fabric does not allow generic classes or generic methods. I have also tried something like
public interface INinjaService : IService, IFooService<SuperNinja>
{
}
but it does not pick up inherited interfaces stating
The service type 'Omni.Fabric.Services.NinjaService' does not implement any service interfaces. A service interface is the one that derives from 'Microsoft.ServiceFabric.Services.Remoting.IService' type.
I can't seem to find any reference to generics on Service Fabric Documentation or stackoverflow. Either it is still too new or possibly I am headed down the wrong path. Has anyone had any luck implementing this sort of pattern? Can it be done? Should it be done?
NinjaService as requested
public class NinjaService : StatelessService, INinjaService
{
public NinjaService(StatelessServiceContext serviceContext) : base(serviceContext)
{
}
protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
{
return new[] { new ServiceInstanceListener(context => this.CreateServiceRemotingListener(context)) };
}
public Task<SuperNinja> Get(int id)
{
return Task.FromResult(new SuperNinja());
}
}
Consuming Code (called from an Owin WebApi Service
public async Task<SuperNinja> Get(int key)
{
try
{
INinjaService service = ServiceProxy.Create<INinjaService>(new Uri("fabric:/Omni.Fabric/Services"));
var t = await service.Get(key).ConfigureAwait(false);
return t;
}
catch (Exception ex)
{
throw;
}
}