autofac / Autofac.ServiceFabric

Autofac integration for Azure Service Fabric. Provides service factory implementations for Actors, Stateful Services and Stateless Services.
MIT License
26 stars 27 forks source link

How to communicate to stateful service use remoting? #35

Closed jbarber2016 closed 6 years ago

jbarber2016 commented 6 years ago

I have a stateless service (web api) that talks to stateful service over remoting. On the stateful service I register with autofac, and same goes for the stateless. However one of the ways to communicate to the stateful service is remoting, is there some way using autofac to locate services instead of me having to write the following code?

IMyService helloWorldClient = ServiceProxy.Create(new Uri("fabric:/MyApplication/MyHelloWorldService"));

string message = await helloWorldClient.HelloWorldAsync();

J-McElroy commented 6 years ago

You can do the following:

builder.RegisterType<ServiceProxyFactory>().As<IServiceProxyFactory>();  
builder.Register<IMyService>(c =>
            {
                var factory = c.Resolve<IServiceProxyFactory>();
                return factory.CreateServiceProxy<IMyService>(new Uri("fabric:/MyApplication/MyHelloWorldService"), new ServicePartitionKey(0));
            });
alexmg commented 6 years ago

Thanks for jumping in @J-McElroy 👍