/// <summary> /// Creates new instance of <see cref="JsonFileConfigurationLoader"/>. /// </summary> /// <param name="file">Enables file system access.</param> /// <param name="tokenConverter">Json token converter.</param> /// <param name="filePaths">Json file paths. The first file is considered the main file, the others act as overrides.</param> /// <param name="encoding">Encoding to be used for reading json file.</param> /// <param name="jsonSerializerSettingsProvider">Provides <see cref="JsonSerializerSettings"/> for deserialization of file content to <see cref="JToken"/>.</param> /// <param name="jsonConfigurationProviderFactory">A factory for creation of <see cref="IConfigurationProvider{TRawDataIn,TRawDataOut}"/>.</param> public JsonFileConfigurationLoader(IFile file, IJsonTokenConverter tokenConverter, string[] filePaths, IEncoding encoding = null, Func <JsonSerializerSettings> jsonSerializerSettingsProvider = null, Func <JToken[], IJsonTokenConverter, IConfigurationProvider <JToken, JToken> > jsonConfigurationProviderFactory = null) { if (file == null) { throw new ArgumentNullException(nameof(file)); } if (filePaths == null) { throw new ArgumentNullException(nameof(filePaths)); } if (tokenConverter == null) { throw new ArgumentNullException(nameof(tokenConverter)); } if (filePaths.Any(path => String.IsNullOrWhiteSpace(path))) { throw new ArgumentException("At least one of the configuration file path is empty.", nameof(filePaths)); } _file = file; _filePaths = filePaths; _tokenConverter = tokenConverter; _jsonSerializerSettingsProvider = jsonSerializerSettingsProvider; _encoding = encoding ?? new UTF8Encoding(false, true).ToInterface(); _jsonConfigurationProviderFactory = jsonConfigurationProviderFactory ?? ((tokens, converter) => new JsonFileConfigurationProvider(tokens, converter)); }
/// <summary> /// Creates new instance of <see cref="JsonFileConfigurationProvider"/>. /// </summary> /// <param name="tokens">Tokens the configurations are deserialized from. The first token is considered to be the main file, the others act as overrides.</param> /// <param name="tokenConverter">Json deserializer.</param> /// <exception cref="ArgumentNullException">Thrown when the <paramref name="tokens"/> or <paramref name="tokenConverter"/> is <c>null</c>.</exception> public JsonFileConfigurationProvider([NotNull] JToken[] tokens, [NotNull] IJsonTokenConverter tokenConverter) { if (tokens == null) { throw new ArgumentNullException(nameof(tokens)); } if (tokens.Length == 0) { throw new ArgumentException("Token collection can not be empty.", nameof(tokens)); } _tokens = tokens; _tokenConverter = tokenConverter ?? throw new ArgumentNullException(nameof(tokenConverter)); }