![]() |
|
ASP.NET Core and Blazor updates in .NET Core 3.0 Preview 7 - 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 7 (/thread-91591.html) |
ASP.NET Core and Blazor updates in .NET Core 3.0 Preview 7 - xSicKxBot - 07-26-2019 ASP.NET Core and Blazor updates in .NET Core 3.0 Preview 7 Daniel July 23rd, 2019 .NET Core 3.0 Preview 7 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 7 install the .NET Core 3.0 Preview 7 SDK If you’re on Windows using Visual Studio, install the latest preview of Visual Studio 2019. Note: .NET Core 3.0 Preview 7 requires Visual Studio 2019 16.3 Preview 1, which is being released later this week. To install the latest client-side Blazor templates also run the following command: Code: dotnet new -i Microsoft.AspNetCore.Blazor.Templates::3.0.0-preview7.19365.7Installing the Blazor Visual Studio extension is no longer required and it can be uninstalled if you’ve installed a previous version. Installing the Blazor WebAssembly templates from the command-line is now all you need to do to get them to show up in Visual Studio. Upgrade an existing project To upgrade an existing an ASP.NET Core app to .NET Core 3.0 Preview 7, 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 6 project to Preview 7:
That’s it! You should be ready to go. Latest Visual Studio preview includes .NET Core 3.0 as the default runtime The latest preview update for Visual Studio (16.3) includes .NET Core 3.0 as the default .NET Core runtime version. This means that if you install the latest preview of Visual Studio then you already have .NET Core 3.0. New project by default will target .NET Core 3.0 Top level ASP.NET Core templates in Visual Studio The ASP.NET Core templates now show up as top level templates in Visual Studio in the “Create a new project” dialog. This means you can now search for the various ASP.NET Core templates and filter by project type (web, service, library, etc.) to find the one you want to use. Simplified web templates We’ve taken some steps to further simplify the web app templates to reduce the amount of code that is frequently just removed. Specifically:
We will provide samples and documentation for adding these features to new apps as needed. Attribute splatting for components Components can now capture and render additional attributes in addition to the component’s declared parameters. Additional attributes can be captured in a dictionary and then “splatted” onto an element as part of the component’s rendering using the new Code: @attributesCode: <input>Code: <input>Code: maxlengthCode: placeholderAccepting arbitrary parameters To define a component that accepts arbitrary attributes define a component parameter using the Code: [Parameter]Code: CaptureUnmatchedAttributesCode: Dictionary<string, object>Code: IEnumerable<KeyValuePair<string, object>>Code: IReadOnlyDictionary<string, object>Code: @code { [Parameter(CaptureUnmatchedAttributes = true)] Dictionary<string, object> Attributes { get; set; }
}The Code: CaptureUnmatchedAttributesCode: [Parameter]Code: CaptureUnmatchedAttributesUsing @attributes to render arbitrary attributes A component can pass arbitrary attributes to another component or markup element using the Code: @attributesCode: @attributesCode: <input class="form-field" @attributes="Attributes" type="text" /> @code { [Parameter(CaptureUnmatchedAttributes = true)] Dictionary<string, object> Attributes { get; set; }
}Using the Code: @attributesCode: AttributeCode: AttributesCode: classCode: class="form-field"Code: AttributesCode: typeCode: type="text"Data binding support for TypeConverters and generics Blazor now supports data binding to types that have a string Code: TypeConverterCode: GuidCode: TimeSpanCode: TypeConverterCode: TypeConverterCode: <input @bind="guid" /> <p>@guid</p> @code { Guid guid;
}Data binding also now works great with generics. In generic components you can now bind to types specified using generic type parameters. Code: @typeparam T <input @bind="value" /> <p>@value</p> @code { T value;
}In Preview 6 we introduced directive attributes as a common syntax for Razor compiler related features like specifying event handlers ( Code: @onclickCode: @bindCode: @Code: @* Before *@
<button @onclick="@OnClick">Click me</button> @* After *@
<button @onclick="OnClick">Click me</button>In place of Windows perf counters, .NET Core introduced a new way of emitting metrics via EventCounters. In preview7, we now emit EventCounters ASP.NET Core. You can use the Code: dotnet countersInstall the latest preview of Code: dotnet countersCode: dotnet tool install --global dotnet-counters --version 3.0.0-preview7.19365.2The Hosting EventSourceProvider ( Code: Microsoft.AspNetCore.Hosting
SignalR In addition to hosting, SignalR ( Code: Microsoft.AspNetCore.Http.Connections
To view all the counters emitted by ASP.NET Core, you can start dotnet counters and specify the desired provider. The example below shows the output when subscribing to events emitted by the Code: Microsoft.AspNetCore.HostingCode: System.RuntimeCode: dotnet counters monitor -p <PID> Microsoft.AspNetCore.Hosting System.RuntimeNew Package ID for SignalR’s JavaScript Client in NPM The Azure SignalR Service made it easier for non-.NET developers to make use of SignalR’s real-time capabilities. A frequent question we would get from potential customers who wanted to enable their applications with SignalR via the Azure SignalR Service was “does it only work with ASP.NET?” The former identity of the ASP.NET Core SignalR – which included the Code: @aspnetTo mitigate this confusion, beginning with 3.0.0-preview7, the SignalR JavaScript client will change from being Code: @aspnet/signalrCode: @microsoft/signalrNew Customizable SignalR Hub Method Authorization With Preview 7, SignalR now provides a custom resource to authorization handlers when a hub method requires authorization. The resource is an instance of Code: HubInvocationContextCode: HubInvocationContextCode: HubCallerContextConsider the example of a chat room allowing multiple organization sign-in via Azure Active Directory. Anyone with a Microsoft account can sign in to chat, but only members of the owning organization should be able to ban users or view users’ chat histories. Furthermore, we might want to restrict certain functionality from certain users. Using the updated features in Preview 7, this is entirely possible. Note how the Code: DomainRestrictedRequirementCode: IAuthorizationRequirementCode: HubInvocationContextCode: public class DomainRestrictedRequirement : AuthorizationHandler<DomainRestrictedRequirement, HubInvocationContext>, IAuthorizationRequirement
{ protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, DomainRestrictedRequirement requirement, HubInvocationContext resource) { if (IsUserAllowedToDoThis(resource.HubMethodName, context.User.Identity.Name) && context.User != null && context.User.Identity != null && context.User.Identity.Name.EndsWith("@jabbr.net", StringComparison.OrdinalIgnoreCase)) { context.Succeed(requirement); } return Task.CompletedTask; } private bool IsUserAllowedToDoThis(string hubMethodName, string currentUsername) { return !(currentUsername.Equals("bob42@jabbr.net", StringComparison.OrdinalIgnoreCase) && hubMethodName.Equals("banUser", StringComparison.OrdinalIgnoreCase)); }
}Now, individual Hub methods can be decorated with the name of the policy the code will need to check at run-time. As clients attempt to call individual Hub methods, the Code: DomainRestrictedRequirementCode: DomainRestrictedRequirementCode: SendMessageCode: @jabbr.netCode: bob42@jabbr.netCode: [Authorize]
public class ChatHub : Hub
{ public void SendMessage(string message) { } [Authorize("DomainRestricted")] public void BanUser(string username) { } [Authorize("DomainRestricted")] public void ViewUserHistory(string username) { }
}Creating the Code: DomainRestrictedCode: Startup.csCode: DomainRestrictedRequirementCode: services .AddAuthorization(options => { options.AddPolicy("DomainRestricted", policy => { policy.Requirements.Add(new DomainRestrictedRequirement()); }); });It must be noted that in this example, the Code: DomainRestrictedRequirementCode: IAuthorizationRequirementCode: AuthorizationHandlerCode: AuthorizationHandlerCode: StartupHTTPS in gRPC templates The gRPC templates have been now been updated to use HTTPS by default. At development time, we continue the same certificate generated by the Code: dotnet dev-certsgRPC Client Improvements The managed gRPC client ( Code: Grpc.Net.ClientgRPC Metapackage In 3.0.0-preview7, we’ve introduced a new package Code: Grpc.AspNetCoreCLI tool for managing gRPC code generation The new Code: dotnet-grpcInstall the latest preview of Code: dotnet-grpcCode: dotnet tool install --global dotnet-grpc --version 0.1.22-pre2As an example, you can run following commands to generate a protobuf file and add it to your project for code generation. If you attempt this on a non-web project, we will default to generating a client and add the required package dependencies. Code: dotnet new proto -o .\Protos\mailbox.proto
dotnet grpc add-file .\Protos\mailbox.protoWe 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! Daniel Roth Principal Program Manager, ASP.NET Follow Daniel https://devblogs.microsoft.com/aspnet/author/danroth27/feed/ |