Fruity Mike
Fruity Mike
Explore posts from servers
CC#
Created by Fruity Mike on 10/19/2024 in #help
lib for asp.net core dependency issues
Hey I want to move out and generalize certain api configurations, middlewares, etc. One of these would be json options:
builder.Services.AddControllers()
.AddJsonOptions(options =>
{
options.AllowInputFormatterExceptionMessages = true; options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; options.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; options.JsonSerializerOptions.DictionaryKeyPolicy = JsonNamingPolicy.CamelCase;
})
builder.Services.AddControllers()
.AddJsonOptions(options =>
{
options.AllowInputFormatterExceptionMessages = true; options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; options.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; options.JsonSerializerOptions.DictionaryKeyPolicy = JsonNamingPolicy.CamelCase;
})
I have written extension method for it:
public static IMvcBuilder AddDefaultJsonOptions(this IMvcBuilder builder, Action<JsonOptions> configure)
{
builder.AddJsonOptions(options =>
{ options.AllowInputFormatterExceptionMessages = true; options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; options.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; options.JsonSerializerOptions.DictionaryKeyPolicy = JsonNamingPolicy.CamelCase;
configure.Invoke(options);
});
return builder;
}
public static IMvcBuilder AddDefaultJsonOptions(this IMvcBuilder builder, Action<JsonOptions> configure)
{
builder.AddJsonOptions(options =>
{ options.AllowInputFormatterExceptionMessages = true; options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; options.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; options.JsonSerializerOptions.DictionaryKeyPolicy = JsonNamingPolicy.CamelCase;
configure.Invoke(options);
});
return builder;
}
Should be working, but 'JsonOptions' definition is missing and I'm unable to figure out/find necessary nuget. So far I'm using these packages:
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.2" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.2" />
</ItemGroup>
Any tips would be appreciated. P.S. using .net 8
27 replies
CC#
Created by Fruity Mike on 10/25/2022 in #help
Buffered download [Answered]
Hello, For example I can download a file
var client = new HttpClient();
var result = await client.GetByteArrayAsync(url);
var client = new HttpClient();
var result = await client.GetByteArrayAsync(url);
By doing that I write it all to memory. But what if the file is quite big (4gb+), how could I download in chunks while writing those to persistence?
40 replies
CC#
Created by Fruity Mike on 9/12/2022 in #help
File logs and docker
Hey, I have a web api which uses serilog to log into files. Whenever it runs in a container those logs are also contained in the container. As far as I understand after container stops running logs are lost. I'm aware of log driver but haven't read enough yet. So I basically want to retrieve those files/logs. Maybe anyone could point me to a "good practice" or a solution for this kind of problem?
4 replies
CC#
Created by Fruity Mike on 9/5/2022 in #help
Migrations with dapper [Answered]
Hey, I want to use dapper but don't want to deal with migrations/schema changes manually what could you recommend me?
22 replies
CC#
Created by Fruity Mike on 9/1/2022 in #help
Default mapping logic from jwt payload to claims
Hey, I have asp.net core web api with jwt authentication. It's fairly "default", something you would find on most tutorials. If I would generate token it would have payload:
{"sub":"user","exp":1662070302}
{"sub":"user","exp":1662070302}
So whenever token is successfully validated I'm expecting to have two claims with same keys as types and values. But for some reason I'm getting the following:
Type: $http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier Value: user
Type: $exp Value: 1662070302
Type: $http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier Value: user
Type: $exp Value: 1662070302
Because of this I have a question. Is there a flag of some sort to disable this key to type override or I have to override this override?
2 replies