.NET Core 3.0 and ASP.NET Core 3.0 Preview

A few days ago Microsoft released .NET Core 3.0 Preview 9, which is a preview of .NET Core 3.0 final version.

.NET Core 3.0 official release will be posted on .NET Conf, .NET Conf time is 23 to 25 September.

Visual Studio 2019 16.3 Preview 3 and Visual Studio for Mac 8.3 supports .NET Core 3.0, these versions also released.

From .NET Core 3.0 Preview 7 can be used for production, the official website is to use dotnet https://dotnet.microsoft.com/ Powered by .NET Core 3.0.0-preview9-19423-09.

Park also blog the other day to upgrade to .NET Core 3.0 Preview 8, currently running regarded as good.

Here the actual experience of .NET Core 3.0 new features.

.NET Core 3.0

System.Text.Json

Example:

    public class Person
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public DateTime? BirthDay { get; set; }
    }
    //转成对象
    string json = ...
    Person person = JsonSerializer.Parse<Person>(json);
    
    //转成json字符串
    Person person = ...
    string json = JsonSerializer.ToString(person);

.NET Standard 2.1

To .NET Standard 2.1 as the goal, you must edit the project file and TargetFramework property to netstandard2.1: .NET Framework does not support .NET Standard 2.1.

<Project Sdk="Microsoft.NET.Sdk">
 
  <PropertyGroup>
    <TargetFramework>netstandard2.1</TargetFramework>
  </PropertyGroup>
 
</Project>

 

Microsoft.Data.SqlClient

Microsoft.Data.SqlClient is Microsoft Sql Server data provider.

It is the union of the two components System.Data.SqlClient independently present in the .NET Framework and .NET Core.

Install the latest version

Install-Package Microsoft.Data.SqlClient 

https://github.com/dotnet/SqlClient 

Released as a single program

dotnet publish -r win10-x64 /p:PublishSingleFile=true

Alpine Docker images

.NET Core and ASP.NET Core on ARM64

docker pull mcr.microsoft.com/dotnet/core/runtime:3.0-alpine-arm64v8 

docker pull mcr.microsoft.com/dotnet/core/aspnet:3.0-alpine-arm64v8

dotnet-counters

安装 : dotnet tool install --global dotnet-counters --version 3.0.0-preview8.19412.1

Example of use:

Show all information

dotnet-counters monitor --process-id 1902 System.Runtime

Show CPU usage and the number of abnormal GC

dotnet-counters monitor --process-id 1902 System.Runtime[cpu-usage,gc-heap-size,exception-count]

The official document: https: //github.com/dotnet/diagnostics/blob/master/documentation/dotnet-counters-instructions.md

ReadyToRun

You can set the application by compiling as ReadyToRun (R2R) format to shorten the startup time .NET Core applications. R2R is a compiled form ahead of time (AOT).

Example lifting:

IL application only:

Start time: 1.9 seconds
Memory usage: 69.1 MB
Application Size: 150 MB
Use ReadyToRun image:

Start time: 1.3 seconds.
Memory usage: 55.7 MB
Application Size: 156 MB

To enable ReadyToRun need to compile the following:

The PublishReadyToRun property is set to true. Use explicit release RuntimeIdentifier.

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <PublishReadyToRun>true</PublishReadyToRun>
  </PropertyGroup>
</Project>

 

dotnet publish -r win-x64 -c Release

ReadyToRun compiler does not currently support cross location. We need to be compiled on a given target. For example, if you want the Windows x64 R2R program, you need to run the publish command in that environment.

THE linker

IL linker using the program size can be reduced from about of about 68MB to 28MB

dotnet publish -r win10-x64 -c Release /p:PublishTrimmed=true /p:PublishSingleFile=true

HttpClient supports HTTP / 2

Example of use:

var client = new HttpClient() { BaseAddress = new Uri("https://localhost:5001") };
// HTTP/1.1 request
using (var response = await client.GetAsync("/"))
{
    Console.WriteLine(response.Content);
}
// HTTP/2 request
using (var request = new HttpRequestMessage(HttpMethod.Get, "/") { Version = new Version(2, 0) })
using (var response = await client.SendAsync(request))
{
    Console.WriteLine(response.Content);
}

 

ASP.NET Core 3.0

The previous also introduced ASP.NET Core 3.0 preview experience .

ASP.NET Core 3.0 major update or Blazor and gRPC

BLAZE

Blazor is using a .NET framework to generate an interactive Web UI of the client:

  • To create rich interactive UI using C # instead of JavaScript.
  • Shared use .NET to write server-side and client-side application logic.
  • UI will be rendered as HTML and CSS, with support for many browsers, including mobile browsers.

Using .NET client-side Web development offers the following benefits:

  • C # instead of using JavaScript to write code.
  • Use of existing .NET library ecosystem.
  • Application logic shared between the server and the client.
  • Benefit from the performance, reliability and security of .NET.
  • Always efficient support Visual Studio on Windows, Linux and macOS.
  • A set of stable, feature-rich and easy to use common language, framework and tools to generate basis.

Blazor based application components. The components Blazor UI elements refers to, e.g., a page, dialog box, or a data entry form.

Razor component classes typically written to mark pages (file extension .razor) form. Blazor the assembly is sometimes referred Razor assembly.

Razor markup shows components:

<div>
    <h1>@Title</h1>

    @ChildContent

    <button @onclick="OnYes">Yes!</button>
</div>

@code {
    [Parameter]
    public string Title { get; set; }

    [Parameter]
    public RenderFragment ChildContent { get; set; }

    private void OnYes()
    {
        Console.WriteLine("Write to the console in C#! 'Yes' button was selected.From LineZero");
    }

Dialog text content ( ChildContent) and header ( Title) by using this component in which the UI component. OnYes By button  onclick C # method of triggering events.

Blazor HTML tags using the natural configuration of the UI. HTML elements specified component, and the characteristic mark to pass values to the properties of the component.

In the following examples Index the components used in the above  Dialog components.

@page "/"

<h1>Hello, world!</h1>

Welcome to your new app.

<Dialog Title="Blazor">
    Do you want to <i>learn more</i> about Blazor?
   From LineZero
</Dialog>

More official description: https:? //Docs.microsoft.com/zh-cn/aspnet/core/blazor/get-started view = aspnetcore-3.0 & tabs = visual-studio

gRPC

The main advantage of gRPC are:

  • Modern high-performance lightweight RPC framework.
  • Priority API development agreement, default protocol buffer, allows nothing to do with language.
  • Multilingual tool can be used to generate a strong type server and the client.
  • Support clients, servers, and two-way streaming call.
  • Protobuf using binary serialization reduce the use of the network.

These advantages make gRPC apply to:

  • Efficiency is crucial lightweight micro-services.
  • Polyglot need for multilingual system development.
  • Streaming point to deal with a request or response processing real-time services.

Although there are currently implemented in C # introduced in the official gRPC, but current implementations rely on native library written in C (gRPC C-core). 

Currently being achieved gRPC Kestrel HTTP server-based and fully managed ASP.NET Core.

Guess you like

Origin www.cnblogs.com/linezero/p/netcore3andaspnetcore3.html