private ResolveDelegate <BuilderContext> SettingResolutionFactory(Attribute attribute, object info, object value)
        {
            Type type = null;

            if (info is ParameterInfo parameterInfo)
            {
                type = parameterInfo.ParameterType;
            }
            else if (info is PropertyInfo propertyInfo)
            {
                type = propertyInfo.PropertyType;
            }

            return((ref BuilderContext context) =>
            {
                if (!(attribute is SettingValueAttribute settingValueAttribute) || type == null)
                {
                    return value;
                }

                IReadOnlySettingsService readOnlySettingsService = (IReadOnlySettingsService)
                                                                   context.Resolve(
                    typeof(IReadOnlySettingsService),
                    ((SettingValueAttribute)attribute).ServiceInstance);
                return AsyncContext.Run(
                    () => readOnlySettingsService.GetSettingAsync(settingValueAttribute.SettingKey, settingValueAttribute.SettingType ?? type));
            });
        }
        private static IReadOnlySettingsService CreateReadOnlySettingsService()
        {
            IReadOnlySettingsService settingsServiceMock = Substitute.For <IReadOnlySettingsService>();

            settingsServiceMock.IsRegisteredAsync(Arg.Is(Key1)).Returns(true);
            settingsServiceMock.GetSettingAsync(Arg.Is(Key1), Arg.Is(typeof(string))).Returns("value1");
            return(settingsServiceMock);
        }
        public static IReadOnlySettingsService AsReadOnly([NotNull] this IReadOnlySettingsService service)
        {
            if (service == null)
            {
                throw new ArgumentNullException(nameof(service));
            }

            return(!(service is ISettingsService) ? service : new ReadOnlySettingsService(service));
        }
        public static async Task <T> GetSettingAsync <T>(
            [NotNull] this IReadOnlySettingsService service,
            [NotNull] string key)
        {
            if (service == null)
            {
                throw new ArgumentNullException(nameof(service));
            }

            if (key == null)
            {
                throw new ArgumentNullException(nameof(key));
            }

            return((T)await service.GetSettingAsync(key, typeof(T)));
        }
 /// <summary>
 ///     Initializes a new instance of the <see cref="ReadOnlySettingsService"/> class.
 /// </summary>
 /// <param name="service">The service to wrap.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="service"/> is <see langword="null"/>.</exception>
 public ReadOnlySettingsService([NotNull] IReadOnlySettingsService service)
 {
     _service = service ?? throw new ArgumentNullException(nameof(service));
 }