예제 #1
0
        public static Service Create(string serviceName, string serviceEndpointPrefix, string serviceEndpointTemplate)
        {
            if (string.IsNullOrEmpty(serviceName))
            {
                throw new ArgumentNullException("serviceName");
            }
            var service = new Service {
                ServiceName = serviceName, ServiceEndpointPrefix = serviceEndpointPrefix, ServiceEndpointTemplate = serviceEndpointTemplate
            };

            if (!SERVICE_CACHE.ContainsKey(serviceName))
            {
                logger.Info($"Registering new service: {service.ToString()}");
                SERVICE_CACHE.Add(serviceName, service);
                return(service);
            }
            else
            {
                Service existingService = null;
                SERVICE_CACHE.TryGetValue(serviceName, out existingService);
                if (existingService.Equals(service))
                {
                    return(existingService);
                }
                else
                {
                    throw new ArgumentException($"Cannot redefine service '{serviceName}'. Existing: '{existingService}', New: '{service}'");
                }
            }
        }
예제 #2
0
        /// <summary>Get Service instance based on service name.</summary>
        /// <param name="serviceName">service name.</param>
        /// <returns>A service instance.</returns>
        public static Service GetServiceByName(string serviceName)
        {
            Service service = null;

            if (!SERVICE_CACHE.TryGetValue(serviceName, out service))
            {
                logger.Info($"Service {serviceName} not found.");
            }
            return(service);
        }