Skip to content

How to use with top-lavel statements #15

Answered by maxkoshevoi
ibiza240 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, does this work? After that DateOnly/TimeOnly conversions should work for everything (not only controllers)

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddRazorPages();
builder.Services 
    .AddControllers(options => options.UseDateOnlyTimeOnlyStringConverters())
    .AddJsonOptions(options => options.UseDateOnlyTimeOnlyStringConverters());

var app = builder.Build();
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Error");
    app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
    endpoints.MapControllers(); // Map attribute-routed API controllers

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@ibiza240
Comment options

@maxkoshevoi
Comment options

Answer selected by maxkoshevoi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #14 on October 25, 2022 12:16.