public void ConfigureServices(IServiceCollection services) { services.AddCors((options) => { options.AddPolicy(CorsProfile, (builder) => { builder.WithOrigins(Origins).WithMethods(Methods).AllowAnyHeader(); }); }); services.AddMvc((options) => { FilterCollection filters = options.Filters; filters.Add(new ProducesAttribute(ContentType)); filters.Add(new ConsumesAttribute(ContentType)); }); services.AddControllersWithViews().AddJsonOptions((options) => { JsonSerializerOptions serializerOptions = options.JsonSerializerOptions; serializerOptions.AllowTrailingCommas = false; serializerOptions.WriteIndented = false; serializerOptions.IgnoreNullValues = true; // Add ImageCaster converters that we need in general. serializerOptions.AddImageCasterConverters(); // Add converters that we need on the API specifically. IList <JsonConverter> converters = serializerOptions.Converters; converters.Add(new FrontendFileConverter()); }); services.AddControllers(); }
/// <summary>Load the configuration from the provided <see cref="TextReader"/>.</summary> /// <param name="reader">The text reader to read the string from for the configuration.</param> /// <returns>A data object that represents the configuration passed.</returns> public static ImageCasterConfig Load(TextReader reader) { reader.RequireNonNull(); IDeserializer deserializer = new DeserializerBuilder().Build(); object yamlObject = deserializer.Deserialize(reader); ISerializer serializer = new SerializerBuilder().JsonCompatible().Build(); string json = serializer.Serialize(yamlObject); JsonSerializerOptions options = new JsonSerializerOptions(); options.AddImageCasterConverters(); ImageCasterConfig config = JsonSerializer.Deserialize <ImageCasterConfig>(json, options); return(config); }