ASP.NET Core and Blazor update

.NET Core 3.0 preview 8  is now available, which includes a series of new updates to the ASP.NET Core and Blazor of. Updates are as follows:

Project template update

  • Cleanup template in Visual Studio top

Visual Studio in the "Create a new project" Top ASP.NET Core Project Templates dialog box no longer appears in the "Create a new ASP.NET Core web application" dialog box. The following ASP.NET Core template now appear only in the "Create a new project" dialog box: Razor Class Library, Blazor App, Worker Service and gRPC Service

  • Angular template updated Angular 8
  • BLazor renaming template and simplify

Updated Blazor template to use consistent naming style, and simplifies the number of templates:

"Blazor (server-side)" template is now called "Blazor Server App", using blaszorserver create a Blazor Server application from the command line. "Blazor" template is now called "Blazor WebAssembly App", using blaszorwasm create a Blazor WebAssembly application from the command line. To create Blazor WebAssembly application ASP.NET Core bearer, select "ASP.NET Core hosted" option in Visual Studio.

Create a new Blazor app

dotnet new blazorwasm --hosted

  • Razor Class Library template replace Blazor Class Library template

新的 Razor 类库项目以 .NET 标准为目标,因此可以同时从 Blazor Server 和 Blazor WebAssembly 应用程序中使用它们。若要创建新的 Razor 类库模板,该模板针对 .NET Core 并支持页面和视图,请在 Visual Studio 中选择 Support pages and views 选项,或在命令行上传递 --support-pages-and-views 选项。

Razor Class Library for Pages and Views

dotnet new razorclasslib --support-pages-and-views

区分大小写的组件绑定

 .razor 文件中的组件现在是区分大小写的。

改进 BLazor 服务器应用程序的重连接逻辑

Blazor Server 应用程序需要一个与服务器的实时连接才能正常工作。如果连接或与其关联的服务器端状态丢失,则客户端将无法工作。Blazor Server 应用程序将尝试在出现断续连接丢失时重新连接到服务器,此逻辑在此版本中变得更加健壮。如果在重新建立网络连接之前重新连接尝试失败,那么用户仍然可以通过单击提供的“重试”按钮尝试手动重试连接。

Reload prompt

更新 NavLink 组件以处理其他属性

以前,NavLink 对 href 和 class 属性有特定的支持,但现在可以指定任何其他属性。例如:

<NavLink href="my-page" target="_blank">My page</NavLink>
为
<a href="my-page" target="_blank" rel="noopener noreferrer">My page</a>

@ref 支持字段的自动生成

当使用 @ref 时,Razor 编译器将自动为元素和组件引用生成一个后备字段。

<button @ref="myButton" @onclick="OnClicked">Click me</button>

<Counter @ref="myCounter" IncrementAmount="10" />

@code {
    void OnClicked() => Console.WriteLine($"I have a {myButton} and myCounter.IncrementAmount={myCounter.IncrementAmount}");
}

对 @attribute 的 Razor Pages 支持

@page
@attribute [Microsoft.AspNetCore.Authorization.Authorize]

<h1>Authorized users only!<h1>

<p>Hello @User.Identity.Name. You are authorized!</p>

非 HTTP 服务器的新网络原语

作为分离 Kestrel 组件的工作的一部分,该版引入了新的网络原语,允许添加对非 HTTP 协议的支持。

可以通过调用 IConnectionListenerFactory 上的 Bind 来绑定到端点(System.Net.EndPoint)。这将返回一个 IConnectionListener,它可以用于接受新的连接。调用 AcceptAsync 将返回一个 ConnectionContext,其中包含连接的详细信息。ConnectionContext 类似于 HttpContext,只不过它代表一个连接,而不是 HTTP 请求和响应。

支持 Kestrel 套接字传输的 Unix 域套接字

此版本更新了 Kestrel 中的默认套接字传输,以添加对 Unix 域套接字的支持(在 Linux、MacOS 和 Windows 10、1803 及更高版本上)。要绑定到 Unix 套接字,可以在 KestrelServerOptions 上调用 ListenUnixSocket( ) 方法。

public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
        .ConfigureWebHostDefaults(webBuilder =>
        {
            webBuilder
                .ConfigureKestrel(o =>
                {
                    o.ListenUnixSocket("/var/listen.sock");
                })
                .UseStartup<Startup>();
        });

GRPC 支持 CallCredentials

此版增加了对 CallCredware 的支持,允许与现有的库(如 Grpc.Auth)之间的互操作性,这些库依赖 CallCredware。

Visual Studio 中的 Service Reference 工具

在 Visual Studio 中添加了支持,使管理对其他协议缓冲区文档和 OpenAPI 文档的引用变得更容易。

ServiceReference

GRPC 的诊断改进

GRPC 客户端和服务器使用 Activities 对入站/出站请求进行注释,其中包含有关当前 RPC 操作的信息。

新引入的 Grpc.AspNetCore.Server 和 Grpc.Net.Client 提供程序现在发出以下事件计数器:

total-calls

current-calls

calls-failed

calls-deadline-exceeded

messages-sent

messages-received

calls-unimplemented

详情请见发布说明:

https://devblogs.microsoft.com/aspnet/asp-net-core-and-blazor-updates-in-net-core-3-0-preview-8/

Guess you like

Origin www.oschina.net/news/109098/asp-net- core-and-blazor-update