aspnet / Configuration

[Archived] Interfaces and providers for accessing configuration files. Project moved to https://github.com/aspnet/Extensions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support Newtonsoft Attributes

fromm1990 opened this issue · comments

It could be helpful if this library could support attributes from Newtonsoft such as

[JsonProperty(Required = Required.Always)]
[JsonConverter(typeof(TopicNameConverter))]

Furthermore it could be nice if converters could be added while adding the JSON file.

public static IWebHost BuildWebHost(string[] args) =>
    WebHost.CreateDefaultBuilder(args)
        .UseKestrel()
        .UseContentRoot(Directory.GetCurrentDirectory())
        .ConfigureAppConfiguration((hostingContext, config) =>
        {
            var env = hostingContext.HostingEnvironment;
            config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                .AddJsonConverter(new JsonConverter());
            config.AddEnvironmentVariables();
        })
        .UseStartup<Startup>()
        .Build();

This would help people to map complex types with a parameterized constructor. Furthermore it is possible to make fields required such an error would be thrown while binding, should the settings file not contain the required field.

comment in this pull request will answer to this question #789

I don't see them discuss the option of adding JsonConverters, or am I missing something?

i mean about json property. For converter i guess it should be implemented the same way