Skip to content

Introduce an ASP.NET project to the Sample projects #1487

Closed

Description

@mindball

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.

Activity

  1. angularsen commented on Jan 1, 2025

    @angularsen
    Owner

    Hi, sure!
    If you wanna build one, we can absolutely add it to the samples folder.

  2. lipchev commented on Jan 1, 2025

    @lipchev
    Collaborator

    @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..

  3. angularsen commented on Jan 1, 2025

    @angularsen
    Owner
  4. lipchev commented on Jan 1, 2025

    @lipchev
    Collaborator

    I'm living in the v6 world, it's 2025, what is this v5 you guys keep talking about? 😂

    It usually takes me at least 3-4 months to adjust...

  5. mindball commented on Jan 2, 2025

    @mindball
    Author

    Hi, sure! If you wanna build one, we can absolutely add it to the samples folder.

    Great, I'm on it

  6. github-actions commented on Feb 2, 2025

    @github-actions
    Contributor

    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.

  7. github-actions commented on Feb 9, 2025

    @github-actions
    Contributor

    This issue was automatically closed due to inactivity.

  8. mindball commented on Feb 9, 2025

    @mindball
    Author

    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.

  9. angularsen commented on Feb 10, 2025

    @angularsen
    Owner

    No problem, no rush on our end, so just take your time 😃

  10. mindball commented on Mar 23, 2025

    @mindball
    Author

    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.

  11. angularsen commented on Apr 12, 2025

    @angularsen
    Owner

    @mindball Hey that's great! We can add a link to it in the README.

    A couple of first impressions:

    1. Very thorough and well explained 👏
    2. 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 😊
    3. 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.

  12. minchobalaliev commented on Apr 13, 2025

    @minchobalaliev

    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:

    1. 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.
    2. 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.
    3. 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 😊.

  13. angularsen commented on Apr 13, 2025

    @angularsen
    Owner

    Great! My suggestions:

    1. 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.
    2. 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.
    3. A table of contents could help, there is a lot of information on that page.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions