You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Introduce an ASP.NET project to the Sample projects #1487
Motivation:
I've been looking at the different serialization options available on the documentation page and was wondering if you would be interested in a sample project that demonstrates their usages in ASP.NET.
As there is currently no support for the System.Text converter, that is the default for the minimal-api style project, I was thinking of starting with a basic Controllers API, which we would hopefully extend in the future.
In terms of methods, I was thinking of an API similar to the UnitConverter or maybe a "calculator-type" thing that uses one of the standard operations.
In addition, at work, we've been using some extensions that provide the necessary OpenAPI metadata, such that the API is nicely formatted in Swagger, that can also be added later.
@angularsen Full disclosure, I work with @mindball and pitched him the idea as a good-starting-issue.
Do you think we want this in v5 or directly in v6? I kinda lean towards the latter, as we haven't ported #1479 - the introduction of a new package in the SDK-style project is going to propagate to the main Directory.packages..
I'm living in the v6 world, it's 2025, what is this v5 you guys keep
talking about? 😂
Seriously though, as soon as your base units and possibly the fractions PR
has landed, we should be nearing a release or at least beta/stabilization,
and should merge into master and make a maintenance release/v5 branch.
I noticed this issue was closed due to inactivity, but I’ve been working on this topic in my public repository: ASP.Net.UnitsNetSerializationExamples. I’ve been progressing on this in my spare time over weekends, which is why it took longer. However, I’m close to finishing and will have it ready as soon as possible.
Hello Angularsen, I want to inform you that I have finished the example of serialization for both converters and have provided a detailed description ASP.Net.UnitsNetSerializationExamples. I remain available if you have any questions.
@mindball Hey that's great! We can add a link to it in the README.
A couple of first impressions:
Very thorough and well explained 👏
I'm missing some examples early in the README, a few screenshots of the swagger UI and/or some example JSON responses for the different serializers would help understand early what this all does. An image explains more than thousand words, or so they say 😊
I could not get dotnet run going, I tried it in a github codespace, but got this error:
Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter 'typeName')
at System.ArgumentNullException.Throw(String paramName)
at System.Reflection.TypeNameParser.GetType(String typeName, Func`2 assemblyResolver, Func`4 typeResolver, Assembly requestingAssembly, Boolean throwOnError, Boolean ignoreCase, Boolean extensibleParser)
at System.Type.GetType(String typeName)
at Program.<Main>$(String[] args) in /workspaces/ASP.Net.UnitsNetSerializationExamples/Program.cs:line 8
Not sure if this is a codespace thing, I didn't try checking it out locally on my machine.
These refactorings @mindball come thanks to @lipchev (who is currently working hard on SerializerType.SystemTextJson ). I just want to explain how the project should be launched and if I find free time I will add screenshots with explanation:
appsettings.AbbreviatedUnitsConverter.json and appsettings.IQuantityJSONConverter.json: This configuration specifies that the application should use the NewtonsoftJson serializer with the Abbreviated or UnitTypeAndName schema for JSON serialization.
var serializationOptions = builder.Configuration.GetSection("JsonConverter").Get<SerializationOptions>(); switch (serializationOptions.Serializer) { case SerializerType.NewtonsoftJson: { builder.Services.AddControllersWithNewtonsoftConverter(serializationOptions.Schema); break; } //case SerializerType.SystemTextJson: not yet implemented default: throw new ArgumentOutOfRangeException(); }: This reads the JsonConverter section from the configuration and sets up the JSON serialization based on the specified Serializer and Schema. It uses the AddControllersWithNewtonsoftConverter method to configure the NewtonsoftJson serializer with the appropriate schema.
AddControllersWithNewtonsoftConverter: This method configures the NewtonsoftJson serializer with the specified schema. It adds the appropriate JsonConverter (AbbreviatedUnitsConverter or UnitsNetIQuantityJsonConverter) to the JSON serializer settings based on the provided SerializationSchema. We haven't made a default scheme yet, so it's important to choose one of the two configurations we've defined.
Regarding your comment on missing examples early in the README—I appreciate your feedback! I'm not entirely sure what specific examples you would find most useful. I'd be happy to refine the documentation further if you could clarify your expectations 😊.
Show some short examples of how the API responses may look like with the different serializers; AbbreviatedUnitsConverter, UnitsNetIQuantityJsonConverter. Just add a few JSON snippets to the readme.
The sample should be runnable with dotnet run without having to configure anything, just pick some defaults and maybe explain the default settings in the README.
A table of contents could help, there is a lot of information on that page.
Activity
angularsen commentedon Jan 1, 2025
Hi, sure!
If you wanna build one, we can absolutely add it to the samples folder.
lipchev commentedon Jan 1, 2025
@angularsen Full disclosure, I work with @mindball and pitched him the idea as a
good-starting-issue.Do you think we want this in
v5or directly inv6? I kinda lean towards the latter, as we haven't ported #1479 - the introduction of a new package in the SDK-style project is going to propagate to the mainDirectory.packages..angularsen commentedon Jan 1, 2025
lipchev commentedon Jan 1, 2025
It usually takes me at least 3-4 months to adjust...
mindball commentedon Jan 2, 2025
Great, I'm on it
github-actions commentedon Feb 2, 2025
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.
github-actions commentedon Feb 9, 2025
This issue was automatically closed due to inactivity.
mindball commentedon Feb 9, 2025
I noticed this issue was closed due to inactivity, but I’ve been working on this topic in my public repository: ASP.Net.UnitsNetSerializationExamples. I’ve been progressing on this in my spare time over weekends, which is why it took longer. However, I’m close to finishing and will have it ready as soon as possible.
angularsen commentedon Feb 10, 2025
No problem, no rush on our end, so just take your time 😃
mindball commentedon Mar 23, 2025
Hello Angularsen, I want to inform you that I have finished the example of serialization for both converters and have provided a detailed description ASP.Net.UnitsNetSerializationExamples. I remain available if you have any questions.
angularsen commentedon Apr 12, 2025
@mindball Hey that's great! We can add a link to it in the README.
A couple of first impressions:
dotnet rungoing, I tried it in a github codespace, but got this error:Not sure if this is a codespace thing, I didn't try checking it out locally on my machine.
minchobalaliev commentedon Apr 13, 2025
These refactorings @mindball come thanks to @lipchev (who is currently working hard on SerializerType.SystemTextJson ). I just want to explain how the project should be launched and if I find free time I will add screenshots with explanation:
var serializationOptions = builder.Configuration.GetSection("JsonConverter").Get<SerializationOptions>(); switch (serializationOptions.Serializer) { case SerializerType.NewtonsoftJson: { builder.Services.AddControllersWithNewtonsoftConverter(serializationOptions.Schema); break; } //case SerializerType.SystemTextJson: not yet implemented default: throw new ArgumentOutOfRangeException(); }: This reads the JsonConverter section from the configuration and sets up the JSON serialization based on the specified Serializer and Schema. It uses the AddControllersWithNewtonsoftConverter method to configure the NewtonsoftJson serializer with the appropriate schema.Regarding your comment on missing examples early in the README—I appreciate your feedback! I'm not entirely sure what specific examples you would find most useful. I'd be happy to refine the documentation further if you could clarify your expectations 😊.
angularsen commentedon Apr 13, 2025
Great! My suggestions:
AbbreviatedUnitsConverter,UnitsNetIQuantityJsonConverter. Just add a few JSON snippets to the readme.dotnet runwithout having to configure anything, just pick some defaults and maybe explain the default settings in the README.