void EnforceStatefulActorEndpointBehaviorPolicy(ServiceDescription serviceDescription) { IEnumerable <ServiceRemotingDispatcher> remotingDispatchers = GetDispatchers(serviceDescription.ServiceType); ActorInstanceContextProvider contextProvider = new ActorInstanceContextProvider(); foreach (ServiceEndpoint endpoint in serviceDescription.Endpoints) { //All endpoints for a given Actor must share the same ActorInstanceContextProvider. endpoint.EndpointBehaviors.Add(contextProvider); endpoint.EndpointBehaviors.Add(new FabricThreadPoolBehavior()); endpoint.EndpointBehaviors.Add(new StatefulActorInstanceProvider()); endpoint.EndpointBehaviors.Add(new ServiceHeaderInterceptor(remotingDispatchers)); foreach (OperationDescription operation in endpoint.Contract.Operations) { if (operation.TaskMethod == null) { throw new InvalidOperationException("Validation failed. Actor operation '" + endpoint.Contract.ContractType.FullName + "." + operation.Name + "' does not return Task or Task<>. Actor interface methods must be async and must return either Task or Task<>."); } OperationBehaviorAttribute operationBehavior = operation.OperationBehaviors.FirstOrDefault(behavior => behavior is OperationBehaviorAttribute) as OperationBehaviorAttribute; operationBehavior.TransactionScopeRequired = true; operation.OperationBehaviors.Add(new ActorOperationBehavior(remotingDispatchers)); } } }
void EnforceStatefulActorEndpointBehaviorPolicy(ServiceDescription serviceDescription) { if (serviceDescription.Endpoints.Count(endpoint => !endpoint.Contract.ContractType.Namespace.Contains("ServiceModelEx")) > 1) { throw new InvalidOperationException("Validation failed. Multiple application interfaces found. An Actor may only possess a single application interface."); } ActorInstanceContextProvider contextProvider = new ActorInstanceContextProvider(); foreach (ServiceEndpoint endpoint in serviceDescription.Endpoints) { //All endpoints for a given Actor must share the same ActorInstanceContextProvider. endpoint.EndpointBehaviors.Add(contextProvider); endpoint.EndpointBehaviors.Add(new FabricThreadPoolBehavior()); endpoint.EndpointBehaviors.Add(new StatefulActorInstanceProvider()); foreach (OperationDescription operation in endpoint.Contract.Operations) { if (operation.TaskMethod == null) { throw new InvalidOperationException("Validation failed. Actor operation '" + endpoint.Contract.ContractType.FullName + "." + operation.Name + "' does not return Task or Task<>. Actor interface methods must be async and must return either Task or Task<>."); } OperationBehaviorAttribute operationBehavior = operation.OperationBehaviors.FirstOrDefault(behavior => behavior is OperationBehaviorAttribute) as OperationBehaviorAttribute; operationBehavior.TransactionScopeRequired = true; operation.OperationBehaviors.Add(new ActorOperationBehavior()); } } }