/// <inheritdoc />
        public override bool TryGet(string key, out string value)
        {
            if (key.StartsWith("ConnectionStrings:", StringComparison.InvariantCultureIgnoreCase))
            {
                var searchKey = key.Split(':')[1];

                try
                {
                    // look for a service info of that type
                    value = ConnectionStringManager.Value.GetByTypeName(searchKey).ConnectionString;
                    return(true);
                }
                catch (ConnectorException)
                {
                    // look for a service info with that id
                    ServiceInfoCreator = ServiceInfoCreatorFactory.GetServiceInfoCreator(Configuration.Value);
                    var serviceInfo = ServiceInfoCreator.ServiceInfos.FirstOrDefault(si => si.Id.Equals(searchKey));
                    if (serviceInfo is object)
                    {
                        value = ConnectionStringManager.Value.GetFromServiceInfo(serviceInfo).ConnectionString;
                        return(true);
                    }
                }
            }

            value = null;
            return(false);
        }
        /// <summary>
        /// Build or return the relevant <see cref="ServiceInfoCreator"/>
        /// </summary>
        /// <param name="configuration">Application <see cref="IConfiguration"/></param>
        /// <returns>Singleton <see cref="ServiceInfoCreator"/></returns>
        internal static ServiceInfoCreator GetServiceInfoCreator(IConfiguration configuration)
        {
            if (configuration is null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            lock (_lock)
            {
                if (serviceInfoCreator is object && configuration == serviceInfoCreator.Configuration && (bool)serviceInfoCreator.GetType().GetProperty("IsRelevant").GetValue(null))
                {
                    return(serviceInfoCreator);
                }

                var alternateInfoCreators = ReflectionHelpers.FindTypeFromAssemblyAttribute <ServiceInfoCreatorAssemblyAttribute>();
                foreach (var alternateInfoCreator in alternateInfoCreators)
                {
                    if ((bool)alternateInfoCreator.GetProperty("IsRelevant").GetValue(null))
                    {
                        serviceInfoCreator = (ServiceInfoCreator)alternateInfoCreator.GetMethod("Instance").Invoke(null, new[] { configuration });
                        return(serviceInfoCreator);
                    }
                }

                serviceInfoCreator = ServiceInfoCreator.Instance(configuration);
            }

            return(serviceInfoCreator);
        }
Exemple #3
0
 private static ServiceInfoCreator GetServiceInfoCreator(IConfiguration config)
 {
     if (Platform.IsCloudFoundry)
     {
         return(CloudFoundryServiceInfoCreator.Instance(config));
     }
     else
     {
         return(ServiceInfoCreator.Instance(config));
     }
 }
Exemple #4
0
        public static ServiceInfoCreator Instance(IConfiguration config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            if (config == _config)
            {
                return(_me);
            }

            lock (_lock)
            {
                if (config == _config)
                {
                    return(_me);
                }

                _me = new ServiceInfoCreator(config);
            }

            return(_me);
        }