azure - Is it normal to return actor's proxy from service -
i have service accepts data , then, think, should return actor initialized values.
public class myservice : statefulservice, imyservice { public imyactor dothings(data data) { var actor = actorproxy.create<imyactor>(new actorid(guid.newguid())); actor.init(data); //some other things return actor; } }
another service this:
var service = serviceproxy.create<icommandbrokerservice>(new uri("fabric:/app"), servicepartitionkey.singleton); var actor = service.dothings(data); var state = actor.getstate(); //...
so, okay return actor in such way, or should return actor's id , request proxy on call sight?
upd: according @loekd 's answer did wrapper little type-safety.
[datacontract(name = "actorreferenceof{0}wrapper")] public class actorreferencewrapper<t> { [datamember] public actorreference actorreference { get; private set; } public actorreferencewrapper(actorreference actorref) { actorreference = actorref ?? throw new argumentnullexception(); } public t bind() { return (t)actorreference.bind(typeof(t)); } public iactorservice getactorservice(iactorproxyfactory serviceproxy=null) { return actorreference.getactorservice(serviceproxy); } public tservice getactorservice<tservice>(iactorproxyfactory serviceproxyfactory) tservice : iactorservice { return serviceproxyfactory.createactorserviceproxy<tservice>(actorreference.serviceuri, actorreference.actorid); } public static implicit operator actorreference(actorreferencewrapper<t> actorref) { return actorref.actorreference; } public static explicit operator actorreferencewrapper<t>(actorreference actorreference) { return new actorreferencewrapper<t>(actorreference); } }
no, types used in sf remoting must datacontractserializable
. contracts use can have fields , properties, no methods.
so, instead of returning proxy, return actor reference.
next, use bind create proxy it.
Comments
Post a Comment