Last active
September 24, 2022 19:08
-
-
Save ritasker/fc5cfbfb82bcf28534d3ac1c3bd46ea7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class NodaTimeModelBinder : ModelBinderBase | |
{ | |
private readonly JsonSerializerOptions serializerOptions; | |
public NodaTimeModelBinder(ILoggerFactory loggerFactory) : base(loggerFactory) | |
{ | |
serializerOptions = new JsonSerializerOptions {PropertyNameCaseInsensitive = true}; | |
serializerOptions.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb); | |
} | |
protected override async Task<T> BindCore<T>(HttpRequest request) | |
{ | |
return await JsonSerializer.DeserializeAsync<T>(request.Body, serializerOptions); | |
} | |
} | |
public class Startup | |
{ | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddCarter(configurator: c => | |
{ | |
c.WithModelBinder<NodaTimeModelBinder>(); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment