protected virtual AbstractEndpoint CreateEndpoint(IMessageHandler handler, MethodInfo method, List <Attribute> annotations) { AbstractEndpoint endpoint = null; var inputChannelName = MessagingAttributeUtils.ResolveAttribute <string>(annotations, InputChannelProperty); if (!string.IsNullOrEmpty(inputChannelName)) { IMessageChannel inputChannel; try { inputChannel = ChannelResolver.ResolveDestination(inputChannelName); if (inputChannel == null) { inputChannel = new DirectChannel(ApplicationContext, inputChannelName); ApplicationContext.Register(inputChannelName, inputChannel); } } catch (DestinationResolutionException) { inputChannel = new DirectChannel(ApplicationContext, inputChannelName); ApplicationContext.Register(inputChannelName, inputChannel); } endpoint = DoCreateEndpoint(handler, inputChannel, annotations); } return(endpoint); }
private AbstractEndpoint GetEndpoint(List <Attribute> attributes, object result) { var endpoint = result as AbstractEndpoint; if (endpoint != null) { var autoStartup = MessagingAttributeUtils.ResolveAttribute <string>(attributes, "AutoStartup"); if (!string.IsNullOrEmpty(autoStartup)) { autoStartup = ApplicationContext?.ResolveEmbeddedValue(autoStartup); if (!string.IsNullOrEmpty(autoStartup)) { endpoint.IsAutoStartup = bool.Parse(autoStartup); } } var phase = MessagingAttributeUtils.ResolveAttribute <string>(attributes, "Phase"); if (!string.IsNullOrEmpty(phase)) { phase = ApplicationContext?.ResolveEmbeddedValue(phase); if (!string.IsNullOrEmpty(phase)) { endpoint.Phase = int.Parse(phase); } } } return(endpoint); }
protected virtual void SetOutputChannelIfPresent(List <Attribute> annotations, AbstractReplyProducingMessageHandler handler) { var outputChannelName = MessagingAttributeUtils.ResolveAttribute <string>(annotations, "OutputChannel"); if (!string.IsNullOrEmpty(outputChannelName)) { handler.OutputChannelName = outputChannelName; } }
protected virtual string GenerateServiceName(string originalServiceName, MethodInfo method, Type attributeType) { var name = MessagingAttributeUtils.EndpointIdValue(method); if (string.IsNullOrEmpty(name)) { name = originalServiceName + "." + method.Name + "." + attributeType.Name + "." + Guid.NewGuid().ToString(); } return(name); }
public virtual bool ShouldCreateEndpoint(MethodInfo method, List <Attribute> attributes) { var inputChannel = MessagingAttributeUtils.ResolveAttribute <string>(attributes, InputChannelProperty); var createEndpoint = !string.IsNullOrEmpty(inputChannel); if (!createEndpoint && ServiceAnnotationAware()) { var isService = method.GetCustomAttribute <ServiceAttribute>() != null; if (isService) { throw new InvalidOperationException("A channel name in '" + InputChannelProperty + "' is required when " + AnnotationType + " is used on '[Service]' methods."); } } return(createEndpoint); }
protected override IMessageHandler CreateHandler(object service, MethodInfo method, List <Attribute> attributes) { AbstractReplyProducingMessageHandler serviceActivator; if (method.GetCustomAttribute <ServiceAttribute>() != null) { // Service Attribute usage var target = ResolveTargetServiceFromMethodWithServiceAnnotation(method); serviceActivator = ExtractTypeIfPossible <AbstractReplyProducingMessageHandler>(target); if (serviceActivator == null) { if (target is IMessageHandler handler) { /* * Return a reply-producing message handler so that we still get 'produced no reply' messages * and the super class will inject the advice chain to advise the handler method if needed. */ return(new ReplyProducingMessageHandlerWrapper(ApplicationContext, handler)); } else { serviceActivator = new ServiceActivatingHandler(ApplicationContext, target, method); } } else { CheckMessageHandlerAttributes(ResolveTargetServiceName(method), attributes); return((IMessageHandler)target); } } else { serviceActivator = new ServiceActivatingHandler(ApplicationContext, service, method); } var requiresReply = MessagingAttributeUtils.ResolveAttribute <string>(attributes, "RequiresReply"); if (!string.IsNullOrEmpty(requiresReply)) { serviceActivator.RequiresReply = bool.Parse(ApplicationContext.ResolveEmbeddedValue(requiresReply)); } SetOutputChannelIfPresent(attributes, serviceActivator); return(serviceActivator); }
protected virtual string GenerateHandlerServiceName(string originalServiceName, MethodInfo method) { var name = MessagingAttributeUtils.EndpointIdValue(method); if (string.IsNullOrEmpty(name)) { if (originalServiceName == null) { originalServiceName = method.DeclaringType.Name; } var baseName = originalServiceName + "." + method.Name + "." + AnnotationType.Name; name = baseName; var count = 1; while (ApplicationContext.ContainsService(name)) { name = baseName + "#" + (++count); } } return(name + ".handler"); }
public object PostProcess(object service, string serviceName, MethodInfo method, List <Attribute> attributes) { GetSourceHandlerFromContext(method, out var sourceHandler, out var skipEndpointCreation); if (skipEndpointCreation) { return(null); } var handler = GetHandler(service, method, attributes); if (handler != sourceHandler) { var handlerServiceName = GenerateHandlerServiceName(serviceName, method); if (handler is ReplyProducingMessageHandlerWrapper && !string.IsNullOrEmpty(MessagingAttributeUtils.EndpointIdValue(method))) { handlerServiceName += ".wrapper"; } ApplicationContext.Register(handlerServiceName, handler); handler = (IMessageHandler)ApplicationContext.GetService(handlerServiceName); } var endpoint = CreateEndpoint(handler, method, attributes); if (endpoint != null) { return(endpoint); } else { return(handler); } }