BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News ASP.NET Core OData 9 Improves Performance, Drops .NET Framework

ASP.NET Core OData 9 Improves Performance, Drops .NET Framework

Microsoft announced the availability of the ASP.NET Core OData 9 package on August 30th 2024. The new package brings ASP.NET Core in line with .NET 8 OData libraries, changing the internal details of how the data is encoded in the OData format. According to Microsoft, it brings it more in line with the OData specification.

Earlier in August 2024, Microsoft updated OData .NET libraries to version 8.0.0. The most important changes in it is the dropping of support for legacy .NET Framework. From this version on, only .NET 8 and higher will be supported. The developers using the legacy .NET Framework can still use the version 7.x of OData libraries, which are still actively supported until March 2025, when they will be in maintenance mode.

The OData 8 libraries use a new JSON writer, System.Text.Utf8JsonWriter, to serialise and deserialise the JSON payload. The new writer is significantly faster and needs less memory than the old one, JsonWriter, created by the Microsoft.OData.Json.DefaultJsonWriterFactory since it isn't based on the TextWriter but on a Stream. While the new writer has been available since OData version 7.12.2, now it’s the default implementation in OData 8.

Developers can still use the old writer, if needed, by calling AddOData method in the service builder and providing an ODataJsonWriterFactory instance, which corresponds to the older DefaultJsonWriterFactory and was renamed for clarity.

builder.Services.AddControllers().AddOData(options => options.EnableQueryFeatures().AddRouteComponents(routePrefix: string.Empty, model: modelBuilder.GetEdmModel(), configureServices: (services) =>
{
    services.AddScoped < Microsoft.OData.Json.IJsonWriterFactory > (sp => new Microsoft.OData.Json.ODataJsonWriterFactory());
}));

The new writer doesn’t serialise JSON the same way as the old one. It doesn’t encode all the higher-ASCII Unicode characters as the older writer did. For example, it won’t encode non-Latin symbols such as Greek letters as Unicode sequence of numbers. Instead, it will output the Unicode character itself. The old writer would encode virtually all non-ASCII characters as numbers, making the size of the payload bigger and the encoding process slower. The new JSON writer outputs uppercase Unicode characters instead of lowercase used by previous versions.

Another major change in ASP.NET Core OData 9 is how the dependency injection works. While the earlier versions of OData libraries would use non-standard IContainerBuilder to configure OData services, the updated library uses the same abstractions as .NET does, namely IServiceProvider.

builder.Services.AddControllers().AddOData(options => options.EnableQueryFeatures().AddRouteComponents(routePrefix: string.Empty, model: modelBuilder.GetEdmModel(), configureServices: (services) =>
{
    services.AddDefaultODataServices(odataVersion: Microsoft.OData.ODataVersion.V4, configureReaderAction: (messageReaderSettings) =>
    {
        // Relevant changes to the ODataMessageReaderSettings instance here
    }, configureWriterAction: (messageWriterSettings) =>
    {
        // Relevant changes to the ODataMessageWriterSettings instance here
    }, configureUriParserAction: (uriParserSettings) =>
    {
        // // Relevant changes to the ODataUriParserSettings instance here
    });
}));

There are some minor changes in the new OData libraries, like the removal of legacy implementations and old standards such as JSONP format. For a full list, developers can check the release notes of OData 8 .NET libraries.

The new ASP.NET Core OData 9 libraries are distributed as NuGet packages. The new release has been downloaded 150.000 times in the last 6 weeks. The source code of ASP.NET Core OData is available on GitHub and the repository currently has 458 open issues.

About the Author

Rate this Article

Adoption
Style

BT