/// <summary> /// Instantiates the ServiceRemotingDispatcher that uses the given service context and /// dispatches messages to the given service implementation. /// </summary> /// <param name="serviceContext">Service context</param> /// <param name="service">Service implementation that implements interfaces of type <see cref="IService"/></param> public ServiceRemotingDispatcher(ServiceContext serviceContext, IService service) { Requires.ThrowIfNull(serviceContext, "serviceContext"); this.cancellationHelper = new ServiceRemotingCancellationHelper(serviceContext.TraceId); this.methodDispatcherMap = new Dictionary <int, ServiceMethodDispatcherBase>(); this.service = service; if (service != null) { var serviceTypeInformation = ServiceTypeInformation.Get(service.GetType()); List <ServiceInterfaceDescription> interfaceDescriptions = new List <ServiceInterfaceDescription>(); foreach (var interfaceType in serviceTypeInformation.InterfaceTypes) { var methodDispatcher = ServiceCodeBuilder.GetOrCreateMethodDispatcher(interfaceType); this.methodDispatcherMap.Add(methodDispatcher.InterfaceId, methodDispatcher); interfaceDescriptions.Add(ServiceInterfaceDescription.Create(interfaceType)); } this.servicePerformanceCounterProvider = new ServicePerformanceCounterProvider(serviceContext.PartitionId, serviceContext.ReplicaOrInstanceId, interfaceDescriptions); } }
public static IEnumerable <ServiceRequestHeader> GetServiceRequestHeader(ServiceContext serviceContext, IService service) { var types = ServiceTypeInformation.Get(service.GetType()).InterfaceTypes; if (types != null) { foreach (var type in types) { var customAttributes = type.Assembly.GetCustomAttributes <ServiceRequestHeaderAttribute>(); if (customAttributes != null) { foreach (var customAttribute in customAttributes) { yield return((ServiceRequestHeader)Activator.CreateInstance(customAttribute.HeaderType)); } } } } var entryAssembly = Assembly.GetEntryAssembly(); if (entryAssembly != (Assembly)null) { var customAttributes = entryAssembly.GetCustomAttributes <ServiceRequestHeaderAttribute>(); if (customAttributes != null) { foreach (var customAttribute in customAttributes) { yield return((ServiceRequestHeader)Activator.CreateInstance(customAttribute.HeaderType)); } } } }
/// <summary> /// Instantiates the ServiceRemotingDispatcher that uses the given service context and /// dispatches messages to the given service implementation. /// </summary> /// <param name="serviceContext">Service context</param> /// <param name="serviceImplementation">Service implementation that implements interfaces of type <see cref="IService"/></param> /// <param name="serviceRemotingMessageBodyFactory">This is the factory used by Dispatcher to create Remoting Response object</param> public ServiceRemotingMessageDispatcher(ServiceContext serviceContext, IService serviceImplementation, IServiceRemotingMessageBodyFactory serviceRemotingMessageBodyFactory = null) { var serviceTypeInformation = ServiceTypeInformation.Get(serviceImplementation.GetType()); this.Initialize(serviceContext, serviceImplementation, serviceTypeInformation.InterfaceTypes, false, serviceRemotingMessageBodyFactory); }
public static IServiceRemotingMessageHandler GetServiceRemotingDispatcher(ServiceContext serviceContext, IService service) { try { var types = ServiceTypeInformation.Get(service.GetType()).InterfaceTypes; if (types != null) { foreach (var type in types) { var customAttribute = type.Assembly.GetCustomAttribute <ServiceRemotingDispatcherAttribute>(); if (customAttribute != null) { return ((IServiceRemotingMessageHandler) Activator.CreateInstance(customAttribute.ServiceRemotingDispatcherType, new object[] { serviceContext, service })); } } } var entryAssembly = Assembly.GetEntryAssembly(); if (entryAssembly != (Assembly)null) { var customAttribute = entryAssembly.GetCustomAttribute <ServiceRemotingDispatcherAttribute>(); if (customAttribute != null) { return ((IServiceRemotingMessageHandler) Activator.CreateInstance(customAttribute.ServiceRemotingDispatcherType, new object[] { serviceContext, service })); } } } catch (Exception) { // Ignore // TODO: Should probably log this. } return(new ServiceRemotingDispatcher(service, new Microsoft.ServiceFabric.Services.Remoting.Runtime.ServiceRemotingDispatcher(serviceContext, service), null)); }