![]() |
|
ASP.NET Core and Blazor updates in .NET Core 3.0 Preview 8 - Printable Version +- Sick Gaming (https://sickgaming.net) +-- Forum: Programming (https://sickgaming.net/forum-76.html) +--- Forum: C#, Visual Basic & .NET (https://sickgaming.net/forum-79.html) +--- Thread: ASP.NET Core and Blazor updates in .NET Core 3.0 Preview 8 (/thread-91933.html) |
ASP.NET Core and Blazor updates in .NET Core 3.0 Preview 8 - xSicKxBot - 09-10-2019 ASP.NET Core and Blazor updates in .NET Core 3.0 Preview 8 Sourabh August 13th, 2019 .NET Core 3.0 Preview 8 is now available and it includes a bunch of new updates to ASP.NET Core and Blazor. Here’s the list of what’s new in this preview:
Please see the release notes for additional details and known issues. Get started To get started with ASP.NET Core in .NET Core 3.0 Preview 8 install the .NET Core 3.0 Preview 8 SDK If you’re on Windows using Visual Studio, install the latest preview of Visual Studio 2019. .NET Core 3.0 Preview 8 requires Visual Studio 2019 16.3 Preview 2 or later To install the latest Blazor WebAssembly template also run the following command: Code: dotnet new -i Microsoft.AspNetCore.Blazor.Templates::3.0.0-preview8.19405.7To upgrade an existing an ASP.NET Core app to .NET Core 3.0 Preview 8, follow the migrations steps in the ASP.NET Core docs. Please also see the full list of breaking changes in ASP.NET Core 3.0. To upgrade an existing ASP.NET Core 3.0 Preview 7 project to Preview 8:
You should hopefully now be all set to use .NET Core 3.0 Preview 8. Project template updates Cleaned up top-level templates in Visual Studio Top level ASP.NET Core project templates in the “Create a new project” dialog in Visual Studio no longer appear duplicated in the “Create a new ASP.NET Core web application” dialog. The following ASP.NET Core templates now only appear in the “Create a new project” dialog:
Angular template updated to Angular 8 The Angular template for ASP.NET Core 3.0 has now been updated to use Angular 8. Blazor templates renamed and simplified We’ve updated the Blazor templates to use a consistent naming style and to simplify the number of templates:
Code: dotnet new blazorwasm --hostedThe Razor Class Library template is now setup for Razor component development by default and the Blazor Class Library template has been removed. New Razor Class Library projects target .NET Standard so they can be used from both Blazor Server and Blazor WebAssembly apps. To create a new Razor Class Library template that targets .NET Core and supports Pages and Views instead, select the “Support pages and views” option in Visual Studio, or pass the Code: --support-pages-and-viewsCode: dotnet new razorclasslib --support-pages-and-viewsComponents in .razor files are now case-sensitive. This enables some useful new scenarios and improves diagnostics from the Razor compiler. For example, the Code: CounterCode: ButtonCode: ButtonCode: buttonCode: ButtonCode: CounterButton.razor Code: <button class="btn btn-primary" @attributes="AdditionalAttributes" @onclick="OnClick">@ChildContent</button> @code { [Parameter] public EventCallback<UIMouseEventArgs> OnClick { get; set; } [Parameter] public RenderFragment ChildContent { get; set; } [Parameter(CaptureUnmatchedValues = true)] public IDictionary<string, object> AdditionalAttributes { get; set; }
}Counter.razor Code: @page "/counter" <h1>Counter</h1> <p>Current count: @currentCount</p> <Button OnClick="IncrementCount">Click me</Button> @code { int currentCount = 0; void IncrementCount() { currentCount++; }
}Notice that the Code: ButtonCode: buttonWe can move the Code: ButtonCode: ButtonCode: ButtonCode: NavLinkThe built-in Code: NavLinkCode: NavLinkCode: hrefCode: classCode: <NavLink href="my-page" target="_blank">My page</NavLink>which would render: Code: <a href="my-page" target="_blank" rel="noopener noreferrer">My page</a>Blazor Server apps require a live connection to the server in order to function. If the connection or the server-side state associated with it is lost, then the the client will be unable to function. Blazor Server apps will attempt to reconnect to the server in the event of an intermittent connection loss and this logic has been made more robust in this release. If the reconnection attempts fail before the network connection can be reestablished, then the user can still attempt to retry the connection manually by clicking the provided “Retry” button. However, if the server-side state associated with the connect was also lost (e.g. the server was restarted) then clients will still be unable to connect. A common situation where this occurs is during development in Visual Studio. Visual Studio will watch the project for file changes and then rebuild and restart the app as changes occur. When this happens the server-side state associated with any connected clients is lost, so any attempt to reconnect with that state will fail. The only option is to reload the app and establish a new connection. New in this release, the app will now also suggest that the user reload the browser when the connection is lost and reconnection fails. Culture aware data binding Data-binding support ( Code: @bindCode: <input>Code: System.Globalization.CultureInfo.CurrentCultureCode: @bindYou can also manually specify the culture to use for data binding using the new Code: @bind:cultureCode: CultureInfoCode: <input @bind="amount" @bind:culture="CultureInfo.InvariantCulture" />The Code: <input type="number" />Code: <input type="date" />Code: CultureInfo.InvariantCultureOther field types with specific formatting requirements include Code: datetime-localCode: monthCode: weekData binding now also includes support for binding to Code: DateTime?Code: DateTimeOffsetCode: DateTimeOffset?Automatic generation of backing fields for Code: @refThe Razor compiler will now automatically generate a backing field for both element and component references when using Code: @refCode: <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}");
}In some cases you may still want to manually create the backing field. For example, declaring the backing field manually is required when referencing generic components. To suppress backing field generation specify the Code: @ref:suppressFieldRazor Pages support for Code: @attributeRazor Pages now support the new Code: @attributeFor example, you can now specify that a page requires authorization like this: Code: @page
@attribute [Microsoft.AspNetCore.Authorization.Authorize] <h1>Authorized users only!<h1> <p>Hello @User.Identity.Name. You are authorized!</p>As part of the effort to decouple the components of Kestrel, we are introducing new networking primitives allowing you to add support for non-HTTP protocols. You can bind to an endpoint ( Code: System.Net.EndPointCode: BindCode: IConnectionListenerFactoryCode: IConnectionListenerCode: AcceptAsyncCode: ConnectionContextCode: ConnectionContextCode: HttpContextThe example below show a simple TCP Echo server hosted in a BackgroundService built using these new primitives. Code: public class TcpEchoServer : BackgroundService
{ private readonly ILogger<TcpEchoServer> _logger; private readonly IConnectionListenerFactory _factory; private IConnectionListener _listener; public TcpEchoServer(ILogger<TcpEchoServer> logger, IConnectionListenerFactory factory) { _logger = logger; _factory = factory; } protected override async Task ExecuteAsync(CancellationToken stoppingToken) { _listener = await _factory.BindAsync(new IPEndPoint(IPAddress.Loopback, 6000), stoppingToken); while (true) { var connection = await _listener.AcceptAsync(stoppingToken); // AcceptAsync will return null upon disposing the listener if (connection == null) { break; } // In an actual server, ensure all accepted connections are disposed prior to completing _ = Echo(connection, stoppingToken); } } public override async Task StopAsync(CancellationToken cancellationToken) { await _listener.DisposeAsync(); } private async Task Echo(ConnectionContext connection, CancellationToken stoppingToken) { try { var input = connection.Transport.Input; var output = connection.Transport.Output; await input.CopyToAsync(output, stoppingToken); } catch (OperationCanceledException) { _logger.LogInformation("Connection {ConnectionId} cancelled due to server shutdown", connection.ConnectionId); } catch (Exception e) { _logger.LogError(e, "Connection {ConnectionId} threw an exception", connection.ConnectionId); } finally { await connection.DisposeAsync(); _logger.LogInformation("Connection {ConnectionId} disconnected", connection.ConnectionId); } }
}We’ve updated the default sockets transport in Kestrel to add support Unix domain sockets (on Linux, macOS, and Windows 10, version 1803 and newer). To bind to a Unix socket, you can call the Code: ListenUnixSocket()Code: KestrelServerOptionsCode: public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureWebHostDefaults(webBuilder => { webBuilder .ConfigureKestrel(o => { o.ListenUnixSocket("/var/listen.sock"); }) .UseStartup<Startup>(); });In preview8, we’ve added support for Code: CallCredentialsCode: Grpc.AuthCode: CallCredentialsDiagnostics improvements for gRPC Support for Code: ActivityThe gRPC client and server use Activities to annotate inbound/outbound requests with baggage containing information about the current RPC operation. This information can be accessed by telemetry frameworks for distributed tracing and by logging frameworks. EventCounters The newly introduced Code: Grpc.AspNetCore.ServerCode: Grpc.Net.Client
You can use the Code: dotnet countersCode: dotnet counters monitor -p <PID> Grpc.AspNetCore.ServerWe’ve added support in Visual Studio that makes it easier to manage references to other Protocol Buffers documents and Open API documents. When pointed at OpenAPI documents, the ServiceReference experience in Visual Studio can generated typed C#/TypeScript clients using Code: NSwagWhen pointed at Protocol Buffer ( Code: .protoCode: Grpc.ToolsSignalR User Survey We’re interested in how you use SignalR and the Azure SignalR Service, and your opinions on SignalR features. To that end, we’ve created a survey we’d like to invite any SignalR customer to complete. If you’re interested in talking to one of the engineers from the SignalR team about your ideas or feedback, we’ve provided an opportunity to enter your contact information in the survey, but that information is not required. Help us plan the next wave of SignalR features by providing your feedback in the survey. Give feedback We hope you enjoy the new features in this preview release of ASP.NET Core and Blazor! Please let us know what you think by filing issues on GitHub. Thanks for trying out ASP.NET Core and Blazor! |