/// <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);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Get service info of a given type when you know the Id
 /// </summary>
 /// <typeparam name="TServiceInfo">Service info type you're looking for</typeparam>
 /// <param name="configuration">Configuration to search</param>
 /// <param name="id">Id of service</param>
 /// <returns>Requested implementation of <see cref="IServiceInfo"/></returns>
 public static TServiceInfo GetServiceInfo <TServiceInfo>(this IConfiguration configuration, string id)
     where TServiceInfo : class
 => ServiceInfoCreatorFactory.GetServiceInfoCreator(configuration).GetServiceInfo <TServiceInfo>(id);
Ejemplo n.º 3
0
 /// <summary>
 /// Get configuration info for all services of a given service type
 /// </summary>
 /// <param name="configuration">Configuration to search</param>
 /// <param name="infoType">Type to search for</param>
 /// <returns>A list of relevant <see cref="IServiceInfo"/></returns>
 public static IEnumerable <IServiceInfo> GetServiceInfos(this IConfiguration configuration, Type infoType)
 => ServiceInfoCreatorFactory.GetServiceInfoCreator(configuration).GetServiceInfos(infoType);
Ejemplo n.º 4
0
 /// <summary>
 /// Get service info when you know the Id
 /// </summary>
 /// <param name="configuration">Configuration to search</param>
 /// <param name="id">Id of service</param>
 /// <returns>Requested implementation of <see cref="IServiceInfo"/></returns>
 public static IServiceInfo GetServiceInfo(this IConfiguration configuration, string id)
 => ServiceInfoCreatorFactory.GetServiceInfoCreator(configuration).GetServiceInfo(id);
Ejemplo n.º 5
0
 /// <summary>
 /// Get configuration info for all services of a given service type
 /// </summary>
 /// <typeparam name="TServiceInfo">Service info type you're looking for</typeparam>
 /// <param name="configuration">Configuration to search</param>
 /// <returns>List of service infos</returns>
 public static IEnumerable <TServiceInfo> GetServiceInfos <TServiceInfo>(this IConfiguration configuration)
     where TServiceInfo : class
 => ServiceInfoCreatorFactory.GetServiceInfoCreator(configuration).GetServiceInfos <TServiceInfo>();