Beispiel #1
0
        public async Task OnAccessAsync <TResult>(ProxyValueContext <TResult> context, Func <Task> next)
            where TResult : notnull
        {
            var hasCachedValues = _cachedSets.TryGetValue(context.PropertyKeyPrefix, out var cachedValues);

            if (!hasCachedValues)
            {
                await next();

                if (context.ResultSet.Any())
                {
                    _cachedSets.Add(
                        context.PropertyKeyPrefix,
                        context.ResultSet.ToDictionary(
                            x => x.Key,
                            x => (object)x.Value));
                }

                return;
            }

            foreach (var cachedValue in cachedValues !)
            {
                if (cachedValue.Value is TResult resultValue)
                {
                    context.ResultSet[cachedValue.Key] = resultValue;
                    continue;
                }

                throw new ProxyObjectsException($"The type of a cached value does not match the property type");
            }
        }
        public async Task OnAccessAsync <TResult>(ProxyValueContext <TResult> context, Func <Task> next)
            where TResult : notnull
        {
            await next();

            var stackValues = _scopeValueStack
                              .GetAll()
                              .Where(x => x.PropertyKey.StartsWith(context.PropertyKeyPrefix));

            foreach (var stackValue in stackValues)
            {
                if (stackValue.PropertyValue is TResult resultValue)
                {
                    context.ResultSet[stackValue.PropertyKey] = resultValue;
                    continue;
                }

                throw new ProxyObjectsException($"The type of a scoped value does not match the property type");
            }
        }
Beispiel #3
0
        public async Task OnAccessAsync <TResult>(ProxyValueContext <TResult> context, Func <Task> next)
            where TResult : notnull
        {
            await next();

            var configurationKeyPrefix = context.PropertyKeyPrefix.Replace(".", ":");

            var configurationSection = _configuration.GetSection(configurationKeyPrefix);
            var configurationValues  = configurationSection.Exists()
                ? configurationSection.AsEnumerable()
                : Array.Empty <KeyValuePair <string, string> >();

            foreach (var(configurationKey, _) in configurationValues)
            {
                var configurationType = typeof(TResult);

                var propertyKey   = configurationKey.Replace(":", ".");
                var propertyValue = (TResult)_configuration.GetValue(
                    configurationType, configurationKey);

                context.ResultSet[propertyKey] = propertyValue;
            }
        }