Beispiel #1
0
        /// <summary>
        /// Applies JSON configuration from the file. By default reads "Atata.json" file.
        /// </summary>
        /// <typeparam name="TConfig">The type of the configuration class.</typeparam>
        /// <param name="builder">The builder.</param>
        /// <param name="filePath">The file path.</param>
        /// <param name="environmentAlias">The environment alias.</param>
        /// <returns>The <see cref="AtataContextBuilder"/> instance.</returns>
        public static AtataContextBuilder ApplyJsonConfig <TConfig>(this AtataContextBuilder builder, string filePath = null, string environmentAlias = null)
            where TConfig : JsonConfig <TConfig>, new()
        {
            string jsonContent = JsonConfigFile.ReadText(filePath, environmentAlias);

            TConfig config = JsonConvert.DeserializeObject <TConfig>(jsonContent);

            AtataContextBuilder resultBuilder = JsonConfigMapper.Map(config, builder);

            if (builder.BuildingContext == AtataContext.GlobalConfiguration.BuildingContext)
            {
                JsonConfigManager <TConfig> .UpdateGlobalValue(jsonContent, config);

                EnsureInitConfigEventHandlerIsSubscribed <TConfig>(resultBuilder);
            }
            else
            {
                JsonConfigManager <TConfig> .InitCurrentValue();

                JsonConfigManager <TConfig> .UpdateCurrentValue(jsonContent, config);
            }

            EnsureResetConfigEventHandlerIsSubscribed <TConfig>(resultBuilder);

            resultBuilder.EventSubscriptions.Add(
                new LogJsonConfigPathEventHandler(JsonConfigFile.GetRelativePath(filePath, environmentAlias)));

            return(resultBuilder);
        }
        // GET api/values
        public IEnumerable <KeyValue> Get()
        {
            JsonConfigFile jsonConfigFile = new JsonConfigFile("test");
            KeyValue       result         = jsonConfigFile.Get("name");

            JsonConfigFile hellConfig = new JsonConfigFile("hello");
            KeyValue       result1    = hellConfig.Get("title");

            return(new KeyValue[] { result, result1 });
        }