Пример #1
0
        /// <summary>
        /// Gets the IFunctionalService with the given name, checking to make sure that the name makes sense first.
        /// </summary>
        /// <param name="serviceName">The name of the service to find.</param>
        /// <returns>An IFunctionalService instance if found, otherwise an exception is thrown.</returns>
        protected virtual IFunctionalService GetService(string serviceName)
        {
            if (!serviceName.ToLower().EndsWith("s"))
            {
                throw new InvalidOperationException(
                          $"Found a functional service to support messages to {serviceName}, but its name isn't a plural (doesn't end in 's'). This will not work in the current framework.");
            }

            IService service = FunctionalServiceProviderFactory.GetInstance(ProviderSettings).GetProvider(serviceName);

            if (service == null)
            {
                throw new InvalidOperationException(
                          $"No functional service found to support messages to {serviceName}.");
            }

            if (!ProviderUtils.IsFunctionalService(service.GetType()))
            {
                throw new InvalidOperationException(
                          $"Service ({service.GetType().Name}) found for {serviceName} is not a functional service implementation");
            }

            return(service as IFunctionalService);
        }