站长工具外链查询,个人网站制作 教程,国家企业信用公示系统官网(全国),wordpress导出图片不显示点击上方蓝字 关注我们#xff08;本文阅读时间#xff1a;6分钟).NET 7 预览版2 现已推出#xff0c;其中包括对 ASP.NET Core 的许多重大改进。以下是此预览版中新增内容的摘要#xff1a;• 推断来自服务的 API 控制器操作参数#xff1b;• SignalR 集线器方法的依赖注… 点击上方蓝字 关注我们本文阅读时间6分钟).NET 7 预览版2 现已推出其中包括对 ASP.NET Core 的许多重大改进。以下是此预览版中新增内容的摘要• 推断来自服务的 API 控制器操作参数• SignalR 集线器方法的依赖注入• 为minimal API 提供端点描述和摘要• 在最小的 API 中绑定来自标头和查询字符串的数组和 StringValue• 自定义 cookie 同意值。有关为 .NET 7 计划的 ASP.NET Core 工作的更多详细信息请参阅 GitHub 上的 .NET 7 的完整 ASP.NET Core 路线图。.NET 7 预览版2https://devblogs.microsoft.com/dotnet/announcing-dotnet-7-preview-2?ocidAID3042760完整 ASP.NET Core 路线图https://aka.ms/aspnet/roadmap?ocidAID3042760开始使用 要开始使用 .NET 7 Preview 2 中的 ASP.NET Core请安装 .NET 7 SDK。如果您在 Windows 上使用 Visual Studio我们建议安装最新的 Visual Studio 2022 预览版。Visual Studio for Mac 对 .NET 7 预览的支持尚不可用但即将推出。要安装最新的 .NET WebAssembly 构建工具请从提升的命令提示符处运行以下命令dotnet workload install wasm-tools。 .NET 7 SDKhttps://dotnet.microsoft.com/download/dotnet/7.0?ocidAID3042760Visual Studio 2022 预览版https://visualstudio.com/preview?ocidAID3042760升级现有项目要将现有的 ASP.NET Core 应用从 .NET 7 Preview 1 升级到 .NET 7 Preview 2将所有 Microsoft.AspNetCore.* 包引用更新到 7.0.0-preview.2.*。将所有 Microsoft.Extensions.* 包引用更新到 7.0.0-preview.2.*。另请参阅 .NET 7 的 ASP.NET Core 中的重大更改的完整列表。重大更改完整列表https://docs.microsoft.com/dotnet/core/compatibility/7.0#aspnet-core?ocidAID3042760推断来自服务的 API 控制器操作参数当类型配置为服务时API 控制器操作的参数绑定现在通过依赖注入绑定参数。这意味着不再需要将 [FromServices] 属性显式应用于参数。Services.AddScopedSomeCustomType();[Route([controller])]
[ApiController]
public class MyController : ControllerBase
{// Both actions will bound the SomeCustomType from the DI containerpublic ActionResult GetWithAttribute([FromServices]SomeCustomType service) Ok();public ActionResult Get(SomeCustomType service) Ok();
}您可以通过设置 DisableImplicitFromServicesParameters 来禁用该功能Services.ConfigureApiBehaviorOptions(options
{options.DisableImplicitFromServicesParameters true;
})SignalR 集线器方法的依赖注入SignalR 集线器方法现在支持通过依赖注入 (DI) 注入服务。Services.AddScopedSomeCustomType();public class MyHub : Hub
{// SomeCustomType comes from DI by default nowpublic Task Method(string text, SomeCustomType type) Task.CompletedTask;
}您可以通过设置 DisableImplicitFromServicesParameters 来禁用该功能services.AddSignalR(options
{options.DisableImplicitFromServicesParameters true;
});要显式标记要从配置的服务绑定的参数请使用 [FromServices] 属性public class MyHub : Hub
{public Task Method(string arguments, [FromServices] SomeCustomType type);
}为Minimal API 提供端点描述和摘要Minimal API 现在支持使用用于 OpenAPI 规范生成的描述和摘要来注释操作。您可以使用扩展方法在Minimal API 应用程序中为路由处理程序设置这些描述和摘要app.MapGet(/hello, () ...).WithDescription(Sends a request to the backend HelloService to process a greeting request.);或者通过路由处理程序委托上的属性设置描述或摘要app.MapGet(/hello, [EndpointSummary(Sends a Hello request to the backend)]() ...)在Minimal API 中绑定来自标头和查询字符串的数组和 StringValue在此版本中您现在可以将 HTTPS 标头和查询字符串中的值绑定到原始类型数组、字符串数组或 StringValues// Bind query string values to a primitive type array
// GET /tags?q1q2q3
app.MapGet(/tags, (int[] q) $tag1: {q[0]} , tag2: {q[1]}, tag3: {q[2]})// Bind to a string array
// GET /tags?namesjohnnamesjacknamesjane
app.MapGet(/tags, (string[] names) $tag1: {names[0]} , tag2: {names[1]}, tag3: {names[2]})// Bind to StringValues
// GET /tags?namesjohnnamesjacknamesjane
app.MapGet(/tags, (StringValues names) $tag1: {names[0]} , tag2: {names[1]}, tag3: {names[2]})您还可以将查询字符串或标头值绑定到复杂类型的数组只要该类型具有 TryParse 实现如下例所示。// Bind query string values to a primitive type array
// GET /tags?q1q2q3
app.MapGet(/tags, (int[] q) $tag1: {q[0]} , tag2: {q[1]}, tag3: {q[2]})// Bind to a string array
// GET /tags?namesjohnnamesjacknamesjane
app.MapGet(/tags, (string[] names) $tag1: {names[0]} , tag2: {names[1]}, tag3: {names[2]})// Bind to StringValues
// GET /tags?namesjohnnamesjacknamesjane
app.MapGet(/tags, (StringValues names) $tag1: {names[0]} , tag2: {names[1]}, tag3: {names[2]})自定义 cookie 同意值您现在可以使用新的 CookiePolicyOptions.ConsentCookieValue 属性指定用于跟踪用户是否同意 cookie 使用策略的值。感谢daviddesmet 贡献了这项改进daviddesmethttps://github.com/daviddesmet请求有关 IIS 卷影复制的反馈在 .NET 6 中我们为 IIS 的 ASP.NET Core 模块 (ANCM) 添加了对影子复制应用程序程序集的实验性支持。当 ASP.NET Core 应用程序在 Windows 上运行时二进制文件被锁定因此无法修改或替换它们。您可以通过部署应用程序离线文件来停止应用程序但有时这样做不方便或不可能。卷影复制允许在应用程序运行时通过复制程序集来更新应用程序程序集。 您可以通过在 web.config 中自定义 ANCM 处理程序设置来启用卷影复制?xml version1.0 encodingutf-8?
configurationsystem.webServerhandlersremove nameaspNetCore/add nameaspNetCore path* verb* modulesAspNetCoreModuleV2 resourceTypeUnspecified//handlersaspNetCore processPath%LAUNCHER_PATH% arguments%LAUNCHER_ARGS% stdoutLogEnabledfalse stdoutLogFile.logsstdouthandlerSettingshandlerSetting nameexperimentalEnableShadowCopy valuetrue /handlerSetting nameshadowCopyDirectory value../ShadowCopyDirectory/ //handlerSettings/aspNetCore/system.webServer
/configuration我们正在研究使 IIS 中的卷影复制成为 .NET 7 中 ASP.NET Core 的一项功能并且我们正在寻求有关该功能是否满足用户要求的更多反馈。如果您将 ASP.NET Core 部署到 IIS请尝试使用卷影复制并在 GitHub 上与我们分享您的反馈。应用程序离线文件https://docs.microsoft.com/aspnet/core/host-and-deploy/app-offline?ocidAID3042760分享反馈https://github.com/dotnet/AspNetCore.Docs/issues/23733总结我们希望您喜欢 .NET 7 中的 ASP.NET Core 预览版。通过在 GitHub 上提交问题让我们知道您对这些新改进的看法。感谢您试用 ASP.NET Core提交问题https://github.com/dotnet/aspnetcore/issues/new 获取ASP.NET Core文档新增内容