ASP.NET Core is a modern Web framework for .NET that gives you everything you need to build powerful backend services.
With .NET 6 things are simpler than ever before and there are many new features that will make your development fun and fast.
In this session we'll explore all the cool and new things that were added and all that changes that make ASP.NET Core 6 the best web framework
3. System Architect @ @tamir_dresher
Tamir Dresher
My Books:
Software Engineering Lecturer
Ruppin Academic Center https://www.israelclouds.com/iasaisrael
https://tinyurl.com/Telescopim-YouTube
4. What’s new
Simplicity & Productivity
• New hosting model
• Minimal APIs
• Hot reload
• Async Streaming
Performance
• .NET 6
• Network processing
• Hosting overhead
Better JS FXs Integration
• Frameworks versions
• Webpack dev server proxy
support
Blazor
• Middleware request throughput is ~5% faster in .NET 6.
• MVC on Linux is ~12%, thanks to faster logging.
• Minimal APIs = MVC*2
• HTTPS connections use ~40% less memory, thanks to zero
byte reads.
• Protobuf serialization is ~20% faster with .NET 6.
5. Simplicity & Productivity
• New hosting model
• Minimal APIs
• Hot reload
• Async Streaming
Performance
• .NET 6
• Network processing
• Hosting overhead
Better JS FXs Integration
• Frameworks versions
• Webpack dev sever proxy support
Blazor
Blazor
• .NET Hot reload
• State persistence during prerendering
• Error boundaries
• WebAssembly AOT
• Runtime relinking
• Native dependencies
• Smaller download size
• Render components from JS
• Custom event args
• JavaScript initializers
• JavaScript modules per component
• Infer generic types from parent
• Generic type constraints
• Handle large binary data
• Remove SignalR message size limitations
• Required parameters
• Handle query string parameters
• Influence the HTML head
• SVG support
8. WebApplication vs IHost
• Introducing a lower ceremony replacement for the WebHost to remove
some of the ceremony in hosting ASP.NET Core applications
IHost? host = CreateHostBuilder(args).Build();
static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
...
}); var builder = WebApplication.CreateBuilder(args);
...
WebApplication? app = builder.Build();
9. WebApplication
• Reduce the number of callbacks used to configure top level things
• Expose top level properties for things people commonly resolve in Startup.Configure.
• This allows them to avoid using the service locator pattern for IConfiguration, ILogger, IHostApplicationLifetime.
• Merge the IApplicationBuilder, the IEndpointRouteBuilder and the IHost into a single object.
• This makes it easy to register middleware and routes without needed an additional level of lambda nesting
• Merge the IConfigurationBuilder, IConfiguration, and IConfigurationRoot into a single
Configuration type so that we can access configuration while it's being built.
• This is important since you often need configuration data as part of configuring services.
• UseRouting and UseEndpoints are called automatically (if they haven't already been called) at
the beginning and end of the pipeline.
"Minimal hosting" for ASP.NET Core applications · Issue #30354 · dotnet/aspnetcore (github.c
11. From 5 to 6
• Migrate from ASP.NET Core 5.0 to 6.0 | Microsoft Docs
• .NET 6 ASP.NET Core Migration (github.com)
https://gist.github.com/davidfowl/0e0372c3c1d895c3ce195ba983b1e03d
15. 984
820
425
0
200
400
600
800
1000
1200
Middleware Min API Controller
API performance (1k RPS)
Performance
• HTTP APIs – pay for play
• ~5% RPS gain for middleware in .NET 6
• New min API twice as fast as API controllers
• Faster JWT authentication
• ~40% faster gain in JWT middleware
• MVC on Linux
• ~12% faster thanks to faster logging
• More efficient MemoryCache
• ~10% RPS gain on cache TechEmpower benchmark
• Reduced memory usage per https connection
• ~70% working set reduction for idle WebSocket connections
• HTTP/2 & gRPC
• Improvements to HttpClient connection management
• ~20% faster Protobuf serialization
dotNETConf/Roth_ASP.NET_Core_MVC_Razor_Pages_in_.NET6.pptx at master · dotnet-presentations/dotNETConf (github.com)
17. IEnumerable
namespace System.Collections.Generic
{
public interface IEnumerable<out T> : IEnumerable
{
IEnumerator<T> GetEnumerator();
}
public interface IEnumerator<out T> : IDisposable,
IEnumerator
{
bool MoveNext ();
T Current { get; }
}
}
var fibNums = new List<int> { 0, 1, 1, 2, 3, 5, 8, 13 };
foreach (int element in fibNums)
{
Console.Write($"{element} ");
}
private IEnumerable<int> Fibonacci(int n)
{
int a = 0; int b = 1; int sum = 0;
for (int i = 0; i < n; i++)
{
yield return a;
sum = a + b;
a = b;
b = sum;
}
}
18. Iterators and Async
namespace System.Collections.Generic
{
public interface IEnumerable<out T> : IEnumerable
{
IEnumerator<T> GetEnumerator();
}
public interface IEnumerator<out T> : IDisposable,
IEnumerator
{
bool MoveNext ();
T Current { get; }
}
}
var fibNums = new List<int> { 0, 1, 1, 2, 3, 5, 8, 13 };
foreach (int element in fibNums)
{
Console.Write($"{element} ");
}
private async IEnumerable<int> Fibonacci(int n)
{
int a = 0; int b = 1; int sum = 0;
for (int i = 0; i < n; i++)
{
await SomeAsyncMethod();
yield return a;
sum = a + b;
a = b;
b = sum;
}
}
19. IAsyncEnumerable
namespace System.Collections.Generic
{
public interface IAsyncEnumerable<out T>
{
IAsyncEnumerator<T> GetAsyncEnumerator(
CancellationToken cancellationToken = default);
}
public interface IAsyncEnumerator<out T> : IAsyncDisposable
{
ValueTask<bool> MoveNextAsync();
T Current { get; }
}
}
namespace System
{
public interface IAsyncDisposable
{
ValueTask DisposeAsync();
}
}
namespace System.Collections.Generic
{
public interface IEnumerable<out T> : IEnumerable
{
IEnumerator<T> GetEnumerator();
}
public interface IEnumerator<out T> : IDisposable,
IEnumerator
{
bool MoveNext ();
T Current { get; }
}
}
20. Iterators and Async - IAsyncEnumerable
var fibNums = Fibonacci(20)
await foreach (int element in fibNums)
{
Console.Write($"{element} ");
}
private async IAsyncEnumerable<int> Fibonacci(int n)
{
int a = 0; int b = 1; int sum = 0;
for (int i = 0; i < n; i++)
{
await SomeAsyncMethod();
yield return a;
sum = a + b;
a = b;
b = sum;
}
}
namespace System.Collections.Generic
{
public interface IAsyncEnumerable<out T>
{
IAsyncEnumerator<T> GetAsyncEnumerator(
CancellationToken cancellationToken = default);
}
public interface IAsyncEnumerator<out T> :
IAsyncDisposable
{
ValueTask<bool> MoveNextAsync();
T Current { get; }
}
}
21. New SPA templates
SPA Dev Server ASP.NET Core Backend
Browser requests goes to
Dev Server URL
Requests forwarded backend
via the Dev Server proxy
22. Summary
Simplicity & Productivity
• New hosting model
• Minimal APIs
• Hot reload
• Async Streaming
Performance
• .NET 6
• Network processing
• Hosting overhead
Better JS FXs Integration
• Frameworks versions
• Webpack dev server proxy
support