In 2022, Optimizely will upgrade its platform to the recently-released .NET 6. Niteco’s Optimizely MVP Scott Reed details what benefits this change will bring. 

Released on November 8th, 2021, .NET 6 marks the latest update in the .NET Core product line. It gives us several great framework benefits and includes the release of C# 10, providing developers with more updates to our favorite programming language. 

Along with this release by Microsoft, we recently had the release of Optimizely CMS 12 and Commerce 14 on the .NET 5 version, which is a major milestone for the platform. Within this blog, I’ll talk about the .NET 6 and C# 10 features as well as the impact it will have for Optimizely customers and partners once Optimizely upgrades from .NET 5 to .NET 6. 

For a full breakdown of the benefits of .NET 6, you can navigate to https://devblogs.microsoft.com/dotnet/announcing-net-6/  

1. .NET 5 & 6 Support 

As you can see in the image below, .NET 5, which recently saw the first major release of Optimizely CMS and Commerce, is not long-term supported. .NET 6 has long-term support, which means it will be supported for 3 years, allowing for stability within anything built with it. 

2. Performance 

There have been several improvements in .NET 6, making this the best version ever. From the speed of building (which is excellent for developers) to framework improvements – such as in I/O in particular , they have resulted in decreased execution time, latency, and memory use. An as shown in a Microsoft blog, build times have been improved significantly. 

dotnet6-build-improvements.png

For framework performance, there are many improvements across the board. You can read an in-depth write-up of the improvements with many of the core underlying framework code here. But as a simple example, the standard string format method has been made faster with a smaller code size.

Method Runtime Mean Ratio Code Size
Format .NET 5.0 13.21 ns 1.00 1,649 B
Format .NET 6.0 10.37 ns 0.78 590 B

3. Unified Platform

There is a continued effort to bring .NET libraries to more platforms and for more usages, continuing on from the work on .NET 5 to create a unified platform for all development, with common approaches to development, deployment, and infrastructure.

dotnet-unified-platform.png

4. Minimal APIs

Minimal APIs are designed to allow us to create API endpoints without all of the standard scaffolding of routing and controllers that standard WEB API required. With improvements to C# 10 for expression return types, we can now simply create API mappings in the program.cs file instead, such as shown below.

app.MapGet("/weatherforecast", () =>
{
   var forecast =  Enumerable.Range(1, 5).Select(index => 
       new WeatherForecast 
       ( 
               DateTime.Now.AddDays(index), 
               Random.Shared.Next(-20, 55), 
               summaries[Random.Shared.Next(summaries.Length)] 
        )) 
        .ToArray();
      return forecast; 
})
.WithName("GetWeatherForecast"); 

We can also add in an endpoint explorer and swagger document generation very easily with the following code.

var builder = WebApplication.CreateBuilder(args); 

//Add service to the container.
//Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle

builder.Services.AddEndpointsApiExplorer(); 
builder.Services.AddSwaggerGen(); 

var app = builder.Build(); 

//Configure the HTTP request pipeline
if (app.Environment.IsDevelopment()) 
{
    app.useSwagger();
    app.UseSwaggerUI(); 
}

You can find more information in the Microsoft documentation.

5. Blazor Improvements

Blazor has seen several improvements within .NET 6, including the ability to share your Blazor components across .NET MAUI applications as well as web applications, which can save on the experience of creating native apps as well as web applications.

There has also been the introduction of dynamic components, ahead of time compilation for WebAssembly, improved pre-rendering and performance improvements. This makes Blazor an even more compelling reason for the front-end stack.

There are also some improvements in the Hot Reload functionality for Blazor WebAssembly, which we’ll mention below.

6. Hot Reload

Hot reload allows us to see our application changes almost instantly, allowing for a far faster loop when working and editing code and solutions. For example, in Blazor we can now edit our Blazor markup and components, and with hot reload on save see those changes in the browser almost instantly.

However, be aware that any complex changes that can’t be easily updated will reload the page, but for developers, this is a massive win, as it reduces time for development and makes that loop of editing and seeing changes a lot faster.

7. Top Level Statements

A top level statement reduces the clutter and default code that is needed for applications to get started and allows the focus to be more on the developer’s code. For example, the following examples taken from the Microsoft tutorial on top level statements show us the benefit.

.NET 5

using System; 
namespace Application 
{
    class Program 
    { 
          static void Main(string[] args)
         {
               Console.WriteLine("Hello World!");
          } 
    } 

} 

.NET 6

// See https://aka.ms/new-console-template for more information 
Console.WriteLine("Hello, World!"); 

8. Global and Implicit Usings

In another move to reduce the amount of file clutter, we now have two new types of project-scoped namespaces which will allow us to no longer require having namespaces on every single file in our applications.

Global

With global namespaces, we can simply add a set of namespaces to a C# file and mark them as global, and they will then apply to all classes in our project.

global using System;

Implicit Usings

Since we can infer a lot of the common namespace for project types with .NET 6 and C# 10, we will need these to be automatically added for you. As a standard for projects, the following will be added to the csproj file:

<PropertyGroup>
 <!-- Other properties like OutputType and TargetFramework -->
 <ImplicitUsings>enable</ImplicitUsings> 
</PropertyGroup> 

With this enabled, namespaces like System won’t need to be on a file or even in a global namespace file, they will just always be there, and Visual Studio 2022 will be clever enough to know in the design editor – so no squiggly lines.

9. File Scoped Namespaces

Instead of having to have namespaces wrapped around all our code by default, increasing the amount of indenting, with C# 10 we can now have them just as statements at the top of the C# file.

namespace MyCompany.MyNamespace; 
class MyClass // Note: no indentation 
{ ... } 

10. Much more!!!!

There are so many great features in this update of .NET 6 and C# 10, including:

  • Lambda Improvements
  • Struct Support for Records
  • Interpolated String Improvements
  • Extended Property Patterns

For a detailed overview of all these features, take a look at https://devblogs.microsoft.com/dotnet/welcome-to-csharp-10/!

Optimizely Upgrade Timeline

As mentioned previously, Optimizely CMS 12 and Commerce 14 are currently on .NET 5. This was a major upgrade from the previous .NET Framework version of the platform.

As the support for .NET 5 is ending May 8th, 2022 (as seen at https://dotnet.microsoft.com/platform/support/policy/dotnet-core), there will be a need for the .NET 6 version of Optimizely to be ready by the middle of next year. Therefore, Optimizely will be hard at work delivering that update in early 2022.

The good news is that the .NET 6 upgrade will be substantially smaller in scope than the .NET 5 update, so a lot less development and testing will be required. And of course, Niteco can help you on the journey of upgrading to .NET 5 today, and then .NET 6 when Optimizely releases it. 

Conclusion

With .NET 6 and C# 10, we see many great features, from performance and platform upgrade to great C# features, that will make everything a lot faster and easier. It’s a great time to get your Optimizely solution upgraded to .NET 5 to get all the amazing performance and stability benefits, as show below (from Optimizely’s testing).

4x

Better in Response Time

5 - 10x

Faster in Site and Commerce Operation

3x

More Server Request Handling

We're looking at numbers in the double digits! Which means, customer websites will load even faster!

 

The numbers have dropped significantly, allowing for an even faster user experiences for actions such as Register/Login, Search, and Add To Cart!

 

The number of requests have tripled and we're still seeing better performances! Supporting more traffic, more visitors, more users!

 

When .NET 6 is ready for the platform, we will get even more performance, more features and more of the great updates that we’ve been gifted by Microsoft and Optimizely.

Contact Niteco at https://niteco.com to have our specialists help you on this journey!

Find out more about the latest .NET Core upgrade and why it is important for your business