コード例 #1
0
        public async Task Initialise(CancellationToken cancellationToken)
        {
            var handledMessageTypeNames = new List <string>();

            foreach (var serviceDescriptor in registeredServices)
            {
                AddMessageTypesHandledBy(
                    serviceDescriptor.ServiceType,
                    handledMessageTypeNames);
            }

            // TODO unit test case
            if (!handledMessageTypeNames.Any())
            {
                throw new InvalidOperationException(
                          "Cannot initialise the incoming message pipeline because no message handlers were configured - there is nothing to listen for.");
            }

            await messageSource
            .EnsureSubscribed(
                new SubscriptionDescription(
                    endpointName,
                    handledMessageTypeNames.Distinct()),
                cancellationToken)
            .ConfigureAwait(false);
        }