Пример #1
0
        private List <object> CreateHandlers(Message message, out object messageBody)
        {
            IHandleTypeResolver resolver = null;

            if (_serviceBus.Configuration.HandleTypeResolverType != null)
            {
                resolver = (IHandleTypeResolver)ActivatorUtilities.CreateInstance(
                    _serviceProvider,
                    _serviceBus.Configuration.HandleTypeResolverType);
            }

            messageBody = DeserializeMessage(message, resolver);

            var handlerType = CreateHandlerType(messageBody.GetType());
            var handlers    = _serviceProvider.GetServices(handlerType)?.ToList() ?? new List <object>();

            return(handlers);
        }
Пример #2
0
        private static object DeserializeMessage(Message message, IHandleTypeResolver resolver)
        {
            // use two deserialization strategies. If resolver exists, attempt to use it
            // if no type is found, fallback to JsonConvert. If that can't find a valid
            // type, it will return JObject

            object messageBody = null;

            var enclosedType = message.UserProperties[HeaderTypes.EnclosedType] as string;

            if (resolver != null)
            {
                var alternativeType = resolver.UseTypeFor(enclosedType);
                if (alternativeType != null)
                {
                    messageBody = SerializationHelper.GetObject(message.Body, alternativeType);
                }
            }

            return(messageBody ?? SerializationHelper.GetObject(message.Body));
        }