diff --git a/Directory.Packages.props b/Directory.Packages.props index 814acc8965..01f0ec3435 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -37,9 +37,9 @@ - - - + + + @@ -125,7 +125,7 @@ - + @@ -140,8 +140,6 @@ - - diff --git a/abp_io/AbpIoLocalization/AbpIoLocalization/Account/Localization/Resources/pt.json b/abp_io/AbpIoLocalization/AbpIoLocalization/Account/Localization/Resources/pt.json new file mode 100644 index 0000000000..dc343133aa --- /dev/null +++ b/abp_io/AbpIoLocalization/AbpIoLocalization/Account/Localization/Resources/pt.json @@ -0,0 +1,22 @@ +{ + "culture": "pt", + "texts": { + "Account": "Conta ABP - Iniciar sessão e registar | ABP.IO", + "Welcome": "Bem-vindo", + "UseOneOfTheFollowingLinksToContinue": "Utilize uma das seguintes ligações para continuar", + "FrameworkHomePage": "Página inicial da framework", + "FrameworkDocumentation": "Documentação da framework", + "OfficialBlog": "Blogue oficial", + "CommercialHomePage": "Página inicial comercial", + "CommercialSupportWebSite": "Site de apoio comercial", + "CommunityWebSite": "Site da comunidade ABP", + "ManageAccount": "A minha conta | ABP.IO", + "ManageYourProfile": "Gerir o seu perfil", + "ReturnToApplication": "Voltar à aplicação", + "IdentityUserNotAvailable:Deleted": "Este endereço de email não está disponível. Motivo: já foi eliminado.", + "SelectYourOrganization": "Selecione a sua organização", + "PleaseSelectOrganization": "Selecione uma organização para continuar", + "Continue": "Continuar", + "CaptchaExplanation": "Calcule a expressão matemática abaixo e introduza a resposta." + } +} \ No newline at end of file diff --git a/common.props b/common.props index 60ae3048a8..39be4f5c66 100644 --- a/common.props +++ b/common.props @@ -1,8 +1,8 @@ latest - 10.7.0 - 5.7.0 + 10.8.0-preview + 5.8.0-preview $(NoWarn);CS1591;CS0436 https://abp.io/assets/abp_nupkg.png https://abp.io/ diff --git a/docs/en/Blog-Posts/2024-07-31 v8_3_Preview/post.md b/docs/en/Blog-Posts/2024-07-31 v8_3_Preview/post.md index fc3590b0d5..dff0e1fdae 100644 --- a/docs/en/Blog-Posts/2024-07-31 v8_3_Preview/post.md +++ b/docs/en/Blog-Posts/2024-07-31 v8_3_Preview/post.md @@ -165,7 +165,7 @@ There are exciting articles contributed by the ABP community as always. I will h * [Create a Generic HTTP Service to Consume a Web API](https://abp.io/community/articles/create-a-generic-http-service-to-consume-a-web-api-yidme2kq) by [Bart Van Hoey](https://github.com/bartvanhoey) * [Use User-Defined Function Mapping for Global Filter](https://abp.io/community/articles/use-userdefined-function-mapping-for-global-filter-pht26l07) by [Liming Ma](https://github.com/maliming) -* [How to use .NET Aspire with ABP framework](https://abp.io/community/articles/how-to-use-.net-aspire-with-abp-framework-h29km4kk) by [Berkan Şaşmaz](https://twitter.com/berkansasmazz) +* [How to use Aspire with ABP framework](https://abp.io/community/articles/how-to-use-.net-aspire-with-abp-framework-h29km4kk) by [Berkan Şaşmaz](https://twitter.com/berkansasmazz) * [Exciting New Feature in ABP.IO CMS Kit: Marked Item System](https://abp.io/community/articles/exciting-new-feature-in-abp.io-cms-kit-marked-item-system.-2hvpq0me) by [Suhaib Mousa](https://abp.io/community/members/suhaibmousa032@gmail.com) Thanks to the ABP Community for all the content they have published. You can also [post your ABP-related (text or video) content](https://abp.io/community/posts/create) to the ABP Community. diff --git a/docs/en/Blog-Posts/2024-09-17-My-Impressions-at-DotNext-2024-Conference/post.md b/docs/en/Blog-Posts/2024-09-17-My-Impressions-at-DotNext-2024-Conference/post.md index c6ac51d273..c426dad0c6 100644 --- a/docs/en/Blog-Posts/2024-09-17-My-Impressions-at-DotNext-2024-Conference/post.md +++ b/docs/en/Blog-Posts/2024-09-17-My-Impressions-at-DotNext-2024-Conference/post.md @@ -14,7 +14,7 @@ Last week, I had the chance of being a speaker at **DotNext 2024** in Moscow. [J One of the standout aspects of the conference was its strong technical focus, particularly on deep-dive .NET topics. Talks covered subjects like **low-level optimizations**, architecture, performance, and platform internals. -The conference started with Sergei Benzenko's talk "What's New in .NET 9". There are important topics like ".NET Aspire in Action", "AI-Driven Software Development", "DDD and Strategic Design" and "OAuth 2.0 User-Managed Access in ASP.NET Core with Keycloak". +The conference started with Sergei Benzenko's talk "What's New in .NET 9". There are important topics like "Aspire in Action", "AI-Driven Software Development", "DDD and Strategic Design" and "OAuth 2.0 User-Managed Access in ASP.NET Core with Keycloak". ![DotNext 2024 Speakers](speakers.png) diff --git a/docs/en/Blog-Posts/2024-10-23 v9_0_Preview/POST.md b/docs/en/Blog-Posts/2024-10-23 v9_0_Preview/POST.md index db52eed7d5..79b50c3d6b 100644 --- a/docs/en/Blog-Posts/2024-10-23 v9_0_Preview/POST.md +++ b/docs/en/Blog-Posts/2024-10-23 v9_0_Preview/POST.md @@ -209,7 +209,7 @@ There are exciting articles contributed by the ABP community as always. I will h * [Mohammad AlMohammad AlMahmoud](https://abp.io/community/members/Mohammad97Dev) has created **two** new community articles: * [Implementing Multi-Language Functionality With ABP Framework](https://abp.io/community/articles/implementing-multilanguage-functionality-with-abp-framework-loq7kfx4) * [Configure Quartz.Net in Abp FrameWork](https://abp.io/community/articles/configure-quartz.net-in-abp-framework-3bveq4y1) -* [.NET Aspire vs ABP Studio: Side by Side](https://abp.io/community/articles/.net-aspire-vs-abp-studio-side-by-side-t1c73d1l) by [Halil İbrahim Kalkan](https://twitter.com/hibrahimkalkan) +* [Aspire vs ABP Studio: Side by Side](https://abp.io/community/articles/.net-aspire-vs-abp-studio-side-by-side-t1c73d1l) by [Halil İbrahim Kalkan](https://twitter.com/hibrahimkalkan) * [PoC of using GrapesJS for ABPs CMS Kit](https://abp.io/community/articles/poc-of-using-grapesjs-for-abps-cms-kit-1rmv4q41) by [Jack Fistelmann](https://abp.io/community/members/jfistelmann) * [ABP-Powered Web App with Inertia.js, React, and Vite](https://abp.io/community/articles/abppowered-web-app-with-inertia.js-react-and-vite-j7cccvad) by [Anto Subash](https://antosubash.com/) * [Multi-Tenancy Support in Angular Apps with ABP.IO](https://abp.io/community/articles/multitenancy-support-in-angular-apps-with-abp.io-lw9l36c5) by [HeadChannel Team](https://headchannel.co.uk/) diff --git a/docs/en/Blog-Posts/2025-06-10-Announcing-ABP-Studio-1.0-Stable-Release/POST.md b/docs/en/Blog-Posts/2025-06-10-Announcing-ABP-Studio-1.0-Stable-Release/POST.md index 8b37325e7e..38ccce7748 100644 --- a/docs/en/Blog-Posts/2025-06-10-Announcing-ABP-Studio-1.0-Stable-Release/POST.md +++ b/docs/en/Blog-Posts/2025-06-10-Announcing-ABP-Studio-1.0-Stable-Release/POST.md @@ -87,7 +87,7 @@ We will keep releasing new versions with exciting features based on our roadmap - **OpenTelemetry Integration:** We'll be integrating OpenTelemetry support directly into the startup templates, making distributed tracing and observability a seamless part of your application from day one. - **LeptonX Theme Builder**: Allowing users to determine styling, colour palette and easily override their project's theme styles. - **Monitor dashboards of the tools used in the solution (e.g. Kubernetes, Redis, Grafana, etc...)** -- **Pre-configured .NET Aspire for the Microservice Startup Template** +- **Pre-configured Aspire for the Microservice Startup Template** - **and more...** We are incredibly excited about the future of ABP Studio and can't wait to share the next set of features with you. Your comments and suggestions are invaluable to us. If you have any feedback, please drop a comment below. diff --git a/docs/en/Blog-Posts/2025-12-24-Announcing-Aspire-For-Microservice-Template/POST.md b/docs/en/Blog-Posts/2025-12-24-Announcing-Aspire-For-Microservice-Template/POST.md index a56dd5a464..7ef2be8c6b 100644 --- a/docs/en/Blog-Posts/2025-12-24-Announcing-Aspire-For-Microservice-Template/POST.md +++ b/docs/en/Blog-Posts/2025-12-24-Announcing-Aspire-For-Microservice-Template/POST.md @@ -1,8 +1,8 @@ -# Announcing .NET Aspire Integration for ABP Microservice Template +# Announcing Aspire Integration for ABP Microservice Template -We are excited to announce the integration of **.NET Aspire** into the ABP microservice solution, available starting with **ABP Studio v2.0.0**. This integration brings a unified development experience for building, running, debugging, and deploying distributed applications. With Aspire, you can now orchestrate your entire microservice ecosystem with a single command, eliminating complex configurations and making local development effortless. +We are excited to announce the integration of **Aspire** into the ABP microservice solution, available starting with **ABP Studio v2.0.0**. This integration brings a unified development experience for building, running, debugging, and deploying distributed applications. With Aspire, you can now orchestrate your entire microservice ecosystem with a single command, eliminating complex configurations and making local development effortless. -## What is .NET Aspire? +## What is Aspire? [Aspire](https://aspire.dev/get-started/what-is-aspire/) is a cloud-ready stack designed to streamline the development of distributed applications. It provides: @@ -14,7 +14,7 @@ We are excited to announce the integration of **.NET Aspire** into the ABP micro ## How Does It Work with ABP? -When you enable .NET Aspire in an ABP microservice solution, you get a fully integrated development experience where: +When you enable Aspire in an ABP microservice solution, you get a fully integrated development experience where: - All microservices, gateways, and applications are orchestrated through a single entry point (AppHost). - Infrastructure containers (databases, Redis, RabbitMQ, Elasticsearch, etc.) are managed as code. @@ -24,8 +24,8 @@ When you enable .NET Aspire in an ABP microservice solution, you get a fully int When creating a new microservice solution via ABP Studio: -1. In the solution creation wizard, look for the **".NET Aspire Integration"** step. -2. Toggle the option to **enable .NET Aspire**. +1. In the solution creation wizard, look for the **"Aspire Integration"** step. +2. Toggle the option to **enable Aspire**. 3. Complete the wizard—Aspire projects will be generated along with your solution. ![Enable Aspire in ABP Studio](aspire-configuration.png) @@ -38,7 +38,7 @@ When Aspire is enabled, two additional projects are added to your solution: ### AppHost (Orchestrator) -[`AppHost`](https://aspire.dev/get-started/app-host/) is the .NET Aspire orchestrator project that declares all resources (services, databases, containers, applications) and their dependencies in C# code. It provides: +[`AppHost`](https://aspire.dev/get-started/app-host/) is the Aspire orchestrator project that declares all resources (services, databases, containers, applications) and their dependencies in C# code. It provides: - **Centralized orchestration**: Start your entire microservice ecosystem with a single command. - **Code-first infrastructure**: Databases, Redis, RabbitMQ, Elasticsearch, and observability tools are defined programmatically. @@ -162,9 +162,9 @@ The database management admin tool varies by database type: ## Get Started Today -Ready to experience the power of .NET Aspire with ABP? Create a new microservice solution in ABP Studio and enable the .NET Aspire integration option. For detailed documentation, visit our [.NET Aspire Integration documentation](https://abp.io/docs/latest/solution-templates/microservice/aspire-integration). +Ready to experience the power of Aspire with ABP? Create a new microservice solution in ABP Studio and enable the Aspire integration option. For detailed documentation, visit our [Aspire Integration documentation](https://abp.io/docs/latest/solution-templates/microservice/aspire-integration). -To learn more about .NET Aspire, visit: [https://aspire.dev](https://aspire.dev/get-started/what-is-aspire/) +To learn more about Aspire, visit: [https://aspire.dev](https://aspire.dev/get-started/what-is-aspire/) We are excited to bring this integration to you and can't wait to hear your feedback. If you have any questions or suggestions, please drop a comment below. diff --git a/docs/en/Blog-Posts/2026-08-05 v10_7_Preview/POST.md b/docs/en/Blog-Posts/2026-08-05 v10_7_Preview/POST.md index b8a4d5bf65..f065aacbf5 100644 --- a/docs/en/Blog-Posts/2026-08-05 v10_7_Preview/POST.md +++ b/docs/en/Blog-Posts/2026-08-05 v10_7_Preview/POST.md @@ -10,7 +10,7 @@ You can check the [Get Started page](https://abp.io/get-started) to see how to g By default, ABP Studio uses stable versions to create solutions. Therefore, if you want to create a solution with a preview version, first you need to create a solution and then switch your solution to the preview version from the ABP Studio UI: -![studio-switch-to-preview](studio-switch-to-preview.png) +![studio-switch-to-preview](https://raw.githubusercontent.com/abpframework/abp/refs/heads/dev/docs/en/Blog-Posts/2026-08-05%20v10_7_Preview/studio-switch-to-preview.png) ## Migration Guide @@ -82,7 +82,7 @@ Generated React pages include list, search, sorting, paging, filtering, export, The generator respects the entity and field configuration you define in ABP Suite, including `ShowOn*`, `IsFilterable`, and `ReadonlyOnEditModal` options. Navigation lookups use server-side search. -![React CRUD page generation demo](react-crud-page.mp4) +![](https://raw.githubusercontent.com/abpframework/abp/refs/heads/dev/docs/en/Blog-Posts/2026-08-05%20v10_7_Preview/react-crud-page.gif) ### ABP Suite Decimal Precision diff --git a/docs/en/Blog-Posts/2026-08-05 v10_7_Preview/react-crud-page.gif b/docs/en/Blog-Posts/2026-08-05 v10_7_Preview/react-crud-page.gif new file mode 100644 index 0000000000..12779ac98b Binary files /dev/null and b/docs/en/Blog-Posts/2026-08-05 v10_7_Preview/react-crud-page.gif differ diff --git a/docs/en/Community-Articles/2024-01-15-Abp-Supports-NET8/Post.md b/docs/en/Community-Articles/2024-01-15-Abp-Supports-NET8/Post.md index c6a37d85cd..f9aa44aa2e 100644 --- a/docs/en/Community-Articles/2024-01-15-Abp-Supports-NET8/Post.md +++ b/docs/en/Community-Articles/2024-01-15-Abp-Supports-NET8/Post.md @@ -7,9 +7,9 @@ Here's the summary of .NET 8 features and enhancements: ## What's new in .NET 8 -### .NET Aspire +### Aspire -[.NET Aspire](https://learn.microsoft.com/en-us/dotnet/aspire/) is a tool to observe and manage distributed web applications. It's still preview version. You can manage your containers, executables, logs, traces and metrics of your running web application. For more information see this article https://devblogs.microsoft.com/dotnet/introducing-dotnet-aspire-simplifying-cloud-native-development-with-dotnet-8/ +[Aspire](https://aspire.dev/) is a tool to observe and manage distributed web applications. It's still preview version. You can manage your containers, executables, logs, traces and metrics of your running web application. For more information see this article https://devblogs.microsoft.com/dotnet/introducing-dotnet-aspire-simplifying-cloud-native-development-with-dotnet-8/ ### Serialization diff --git a/docs/en/Community-Articles/2024-03-19-join-abpio-at-modern-net-web-day/post.md b/docs/en/Community-Articles/2024-03-19-join-abpio-at-modern-net-web-day/post.md index df8844f18a..d8a7dc0a9e 100644 --- a/docs/en/Community-Articles/2024-03-19-join-abpio-at-modern-net-web-day/post.md +++ b/docs/en/Community-Articles/2024-03-19-join-abpio-at-modern-net-web-day/post.md @@ -11,7 +11,7 @@ Join us dive into the magic of .NET 8 at the community live stream event, "Moder Topics that will be covered include: * *ASP.NET Core*: Crafting Maintainable Microservices -* *Cloud Native development with .NET Aspire* +* *Cloud Native development with Aspire* * *Developer Productivity with Visual Studio and .NET* * *GitHub Copilot configuration, extension, tips and tricks* * *User Experience and Front-End Development*: Delve into responsive design, accessibility, and performance optimization. Discuss modern front-end frameworks (Blazor, React, Angular, etc.) in the .NET ecosystem. Share strategies for creating delightful user interfaces. diff --git a/docs/en/Community-Articles/2024-04-16-welcome-to-abp-dotnet-conf24-a-decade-of-net-innovation/post.md b/docs/en/Community-Articles/2024-04-16-welcome-to-abp-dotnet-conf24-a-decade-of-net-innovation/post.md index 92635c6f7e..f878d9ce2d 100644 --- a/docs/en/Community-Articles/2024-04-16-welcome-to-abp-dotnet-conf24-a-decade-of-net-innovation/post.md +++ b/docs/en/Community-Articles/2024-04-16-welcome-to-abp-dotnet-conf24-a-decade-of-net-innovation/post.md @@ -50,7 +50,7 @@ As we always be careful with topics we choose on our regular **[ABP Community Ta * 🎙️[Adora Nwodo](https://abp.io/conference/2024/speakers/adora-nwodo), Designing Secure Cloud Native Apps with .NET and Azure * 🎙️[Nicola Iarocci](https://abp.io/conference/2024/speakers/nicola-iarocci), C# 12 What's new and interesting * 🎙️[Jimmy Engström](https://abp.io/conference/2024/speakers/jimmy-engstrom), Connecting gadgets to Blazor -* 🎙️[Juergen Gutsch](https://abp.io/conference/2024/speakers/juergen-gutsch), Building cloud native applications with .NET Aspire +* 🎙️[Juergen Gutsch](https://abp.io/conference/2024/speakers/juergen-gutsch), Building cloud native applications with Aspire * 🎙️[Halil Ibrahim Kalkan](https://abp.io/conference/2024/speakers/halil-ibrahim-kalkan), Designing Modular Monolith for Microservice Architecture * 🎙️[Shaun Lawrence](https://abp.io/conference/2024/speakers/shaun-lawrance), Building games in .NET MAUI * 🎙️[Jamie Taylor](https://abp.io/conference/2024/speakers/jamie-taylor), Empathy, Sympathy and Compassion diff --git a/docs/en/Community-Articles/2024-05-16-abp-dotnet-conference-2024-wrap-up/post.md b/docs/en/Community-Articles/2024-05-16-abp-dotnet-conference-2024-wrap-up/post.md index 426b01639c..1d509fadd4 100644 --- a/docs/en/Community-Articles/2024-05-16-abp-dotnet-conference-2024-wrap-up/post.md +++ b/docs/en/Community-Articles/2024-05-16-abp-dotnet-conference-2024-wrap-up/post.md @@ -33,7 +33,7 @@ The success of ABP Dotnet Conference 2024 would not have been possible without t * 🎙️[Adora Nwodo](https://abp.io/conference/2024/speakers/adora-nwodo), Designing Secure Cloud Native Apps with .NET and Azure * 🎙️[Nicola Iarocci](https://abp.io/conference/2024/speakers/nicola-iarocci), C# 12 What's new and interesting * 🎙️[Jimmy Engström](https://abp.io/conference/2024/speakers/jimmy-engstrom), Connecting gadgets to Blazor -* 🎙️[Juergen Gutsch](https://abp.io/conference/2024/speakers/juergen-gutsch), Building cloud native applications with .NET Aspire +* 🎙️[Juergen Gutsch](https://abp.io/conference/2024/speakers/juergen-gutsch), Building cloud native applications with Aspire * 🎙️[Halil Ibrahim Kalkan](https://abp.io/conference/2024/speakers/halil-ibrahim-kalkan), Designing Modular Monolith for Microservice Architecture * 🎙️[Shaun Lawrence](https://abp.io/conference/2024/speakers/shaun-lawrance), Building games in .NET MAUI * 🎙️[Jamie Taylor](https://abp.io/conference/2024/speakers/jamie-taylor), Empathy, Sympathy and Compassion diff --git a/docs/en/Community-Articles/2024-06-27-how-to-use-Aspire-with-ABP-framework/How to use Aspire with ABP framework.md b/docs/en/Community-Articles/2024-06-27-how-to-use-Aspire-with-ABP-framework/How to use Aspire with ABP framework.md index 4afe83c7c9..c5529d2de2 100644 --- a/docs/en/Community-Articles/2024-06-27-how-to-use-Aspire-with-ABP-framework/How to use Aspire with ABP framework.md +++ b/docs/en/Community-Articles/2024-06-27-how-to-use-Aspire-with-ABP-framework/How to use Aspire with ABP framework.md @@ -1,17 +1,17 @@ -# How to use .NET Aspire with ABP framework +# How to use Aspire with ABP framework -[.NET Aspire](https://learn.microsoft.com/en-us/dotnet/aspire/get-started/aspire-overview) is an opinionated, cloud-ready stack designed for building observable, production-ready, and distributed applications. On the other hand, the [ABP framework](https://docs.abp.io/en/abp/latest) offers a complete, modular and layered software architecture based on Domain Driven Design principles and patterns. This guide explores how to combine .NET Aspire with ABP, enabling developers to create observable, and feature-rich applications. +[Aspire](https://aspire.dev/get-started/what-is-aspire/) is an opinionated, cloud-ready stack designed for building observable, production-ready, and distributed applications. On the other hand, the [ABP framework](https://docs.abp.io/en/abp/latest) offers a complete, modular and layered software architecture based on Domain Driven Design principles and patterns. This guide explores how to combine Aspire with ABP, enabling developers to create observable, and feature-rich applications. -## When to Use .NET Aspire? +## When to Use Aspire? -Using .NET Aspire with the ABP framework can be beneficial in various scenarios where you need to combine the strengths of both technologies. Here are some situations when using .NET Aspire with ABP can be advantageous: +Using Aspire with the ABP framework can be beneficial in various scenarios where you need to combine the strengths of both technologies. Here are some situations when using Aspire with ABP can be advantageous: -- **Enterprise Web Applications:** ABP is well-suited for building enterprise web applications with its opinionated architecture and best practices. When combined with .NET Aspire, you can leverage ABP's features for rapid development of user interfaces, backend services, and business logic while benefiting from .NET Aspire's cloud-native capabilities and observability features. -- **Observability and Monitoring:** .NET Aspire's emphasis on observability, including logging, monitoring, and tracing, can enhance ABP applications by providing deeper insights into system behavior, performance metrics, and diagnostics, which is key for maintaining and optimizing enterprise-grade applications. +- **Enterprise Web Applications:** ABP is well-suited for building enterprise web applications with its opinionated architecture and best practices. When combined with Aspire, you can leverage ABP's features for rapid development of user interfaces, backend services, and business logic while benefiting from Aspire's cloud-native capabilities and observability features. +- **Observability and Monitoring:** Aspire's emphasis on observability, including logging, monitoring, and tracing, can enhance ABP applications by providing deeper insights into system behavior, performance metrics, and diagnostics, which is key for maintaining and optimizing enterprise-grade applications. ## Creating a new ABP Solution -To demonstrate the usage of .NET Aspire with the ABP framework, I've created an ABP solution. If you want to create the same solution from scratch, follow the steps below: +To demonstrate the usage of Aspire with the ABP framework, I've created an ABP solution. If you want to create the same solution from scratch, follow the steps below: Install the ABP CLI if you haven't installed it before: @@ -27,12 +27,12 @@ abp new AspirationalAbp -u mvc --database-provider ef -dbms PostgreSQL --csf --t > The startup template selection matters for this article. I chose these options so that the demo solution can cover complex scenarios. -**Disclaimer-I:** This article is based on version `8.0.1` of .NET Aspire and version `8.2.0` of ABP Framework. +**Disclaimer-I:** This article is based on version `8.0.1` of Aspire and version `8.2.0` of ABP Framework. -**Disclaimer-II:** ABP and .NET Aspire may not be fully compatible in some respects. This article aims to explain how these two technologies can be used together in the simplest way possible, even if they are not fully compatible. -## Add .NET Aspire +**Disclaimer-II:** ABP and Aspire may not be fully compatible in some respects. This article aims to explain how these two technologies can be used together in the simplest way possible, even if they are not fully compatible. +## Add Aspire -After creating the solution, run the following commands in the `src` folder of your solution to add .NET Aspire: +After creating the solution, run the following commands in the `src` folder of your solution to add Aspire: ```bash // Adding AppHost @@ -46,11 +46,11 @@ dotnet sln ../AspirationalAbp.sln add ./AspirationalAbp.ServiceDefaults/Aspirati These commands add two new projects to the solution: - **AspirationalAbp.AppHost**: An orchestrator project designed to connect and configure the different projects and services of your app. -- **AspirationalAbp.ServiceDefaults**: A .NET Aspire shared project to manage configurations that are reused across the projects in your solution related to [resilience](https://learn.microsoft.com/en-us/dotnet/core/resilience/http-resilience), [service discovery](https://learn.microsoft.com/en-us/dotnet/aspire/service-discovery/overview), and [telemetry](https://learn.microsoft.com/en-us/dotnet/aspire/fundamentals/telemetry). +- **AspirationalAbp.ServiceDefaults**: An Aspire shared project to manage configurations that are reused across the projects in your solution related to [resilience](https://learn.microsoft.com/en-us/dotnet/core/resilience/http-resilience), [service discovery](https://aspire.dev/fundamentals/service-discovery/), and [telemetry](https://aspire.dev/fundamentals/telemetry/). -We have added .NET Aspire to our ABP based solution, but we have not registered our projects in the .NET Aspire orchestration. Now, let's enroll our projects, which implement the db migrator, web user interface, API, and auth, in .NET Aspire orchestration. +We have added Aspire to our ABP based solution, but we have not registered our projects in the Aspire orchestration. Now, let's enroll our projects, which implement the db migrator, web user interface, API, and auth, in Aspire orchestration. -## Registering projects to .NET Aspire orchestration +## Registering projects to Aspire orchestration First of all, we need to add the reference of related projects to the `AspirationalAbp.AppHost` project. For this, add the following `ItemGroups` to the `AspirationalAbp.AppHost/AspirationalAbp.AppHost.csproj` file: @@ -130,11 +130,11 @@ With the code above, the following operations were performed below: 7. Adds the `Web` project, referencing Redis. 8. Builds and runs the application. -Now let's make the projects we added to the app host compatible with .NET Aspire. +Now let's make the projects we added to the app host compatible with Aspire. ## Configuring Projects for Aspire -To make the `AspirationalAbp.DbMigrator`, `AspirationalAbp.AuthServer`, `AspirationalAbp.HttpApi.Host`, and `AspirationalAbp.Web` projects compatible with .NET Aspire, we need to add and configure several packages. For that, we need to add the `Aspire.StackExchange.Redis` package to all these projects and the `Aspire.Npgsql.EntityFrameworkCore.PostgreSQL` package to the `AspirationalAbp.EntityFrameworkCore` project. Additionally, we will add the `AspirationalAbp.ServiceDefaults` reference to host projects except `AspirationalAbp.DbMigrator`. Also, we need to convert [Serilog](https://serilog.net/) events into [OpenTelemetry](https://opentelemetry.io/) `LogRecord`s, for that we will add a `Serilog.Sinks.OpenTelemetry` reference to host projects. Let's begin with configuring `AspirationalAbp.DbMigrator`. +To make the `AspirationalAbp.DbMigrator`, `AspirationalAbp.AuthServer`, `AspirationalAbp.HttpApi.Host`, and `AspirationalAbp.Web` projects compatible with Aspire, we need to add and configure several packages. For that, we need to add the `Aspire.StackExchange.Redis` package to all these projects and the `Aspire.Npgsql.EntityFrameworkCore.PostgreSQL` package to the `AspirationalAbp.EntityFrameworkCore` project. Additionally, we will add the `AspirationalAbp.ServiceDefaults` reference to host projects except `AspirationalAbp.DbMigrator`. Also, we need to convert [Serilog](https://serilog.net/) events into [OpenTelemetry](https://opentelemetry.io/) `LogRecord`s, for that we will add a `Serilog.Sinks.OpenTelemetry` reference to host projects. Let's begin with configuring `AspirationalAbp.DbMigrator`. ### AspirationalAbp.DbMigrator @@ -211,7 +211,7 @@ To use the **OpenTelemetry** sink we have installed the `Serilog.Sinks.OpenTelem /// .CreateLogger(); ``` -So far we have made `AspirationalAbp.DbMigrator`, `AspirationalAbp.EntityFrameworkCore`, and `AspirationalAbp.AuthServer` compatible with .NET Aspire. Now let's continue with `AspirationalAbp.HttpApi.Host`. +So far we have made `AspirationalAbp.DbMigrator`, `AspirationalAbp.EntityFrameworkCore`, and `AspirationalAbp.AuthServer` compatible with Aspire. Now let's continue with `AspirationalAbp.HttpApi.Host`. ### AspirationalAbp.HttpApi.Host @@ -253,7 +253,7 @@ To use the **OpenTelemetry** sink we have installed the `Serilog.Sinks.OpenTelem /// .CreateLogger(); ``` -Finally, let's make `AspirationalAbp.Web` compatible with .NET Aspire. +Finally, let's make `AspirationalAbp.Web` compatible with Aspire. ### AspirationalAbp.Web @@ -299,8 +299,8 @@ After making all our changes, we can run the `AspirationalAbp.AppHost` project. ## Conclusion -Combining .NET Aspire with the ABP framework creates a powerful setup for building robust, observable, and feature-rich applications. By integrating Aspire's observability and cloud capabilities with ABP's approach of focusing on your business without repeating yourself, you can develop feature-rich, scalable applications with enhanced monitoring and seamless cloud integration. This guide provides a clear path to set up and configure these technologies, ensuring your applications are well-structured, maintainable, and ready for modern cloud environments. +Combining Aspire with the ABP framework creates a powerful setup for building robust, observable, and feature-rich applications. By integrating Aspire's observability and cloud capabilities with ABP's approach of focusing on your business without repeating yourself, you can develop feature-rich, scalable applications with enhanced monitoring and seamless cloud integration. This guide provides a clear path to set up and configure these technologies, ensuring your applications are well-structured, maintainable, and ready for modern cloud environments. ## See Also -* [.NET Aspire vs ABP Studio: Side by Side](https://abp.io/community/articles/.net-aspire-vs-abp-studio-side-by-side-t1c73d1l) +* [Aspire vs ABP Studio: Side by Side](https://abp.io/community/articles/.net-aspire-vs-abp-studio-side-by-side-t1c73d1l) diff --git a/docs/en/Community-Articles/2024-08-01-abpio-platform-83-rc-has-been-published/post.md b/docs/en/Community-Articles/2024-08-01-abpio-platform-83-rc-has-been-published/post.md index 4ddd247a63..9ddf93d189 100644 --- a/docs/en/Community-Articles/2024-08-01-abpio-platform-83-rc-has-been-published/post.md +++ b/docs/en/Community-Articles/2024-08-01-abpio-platform-83-rc-has-been-published/post.md @@ -162,7 +162,7 @@ There are exciting articles contributed by the ABP community as always. I will h * [Create a Generic HTTP Service to Consume a Web API](https://abp.io/community/articles/create-a-generic-http-service-to-consume-a-web-api-yidme2kq) by [Bart Van Hoey](https://github.com/bartvanhoey) * [Use User-Defined Function Mapping for Global Filter](https://abp.io/community/articles/use-userdefined-function-mapping-for-global-filter-pht26l07) by [Liming Ma](https://github.com/maliming) -* [How to use .NET Aspire with ABP framework](https://abp.io/community/articles/how-to-use-.net-aspire-with-abp-framework-h29km4kk) by [Berkan Şaşmaz](https://twitter.com/berkansasmazz) +* [How to use Aspire with ABP framework](https://abp.io/community/articles/how-to-use-.net-aspire-with-abp-framework-h29km4kk) by [Berkan Şaşmaz](https://twitter.com/berkansasmazz) * [Exciting New Feature in ABP.IO CMS Kit: Marked Item System](https://abp.io/community/articles/exciting-new-feature-in-abp.io-cms-kit-marked-item-system.-2hvpq0me) by [Suhaib Mousa](https://abp.io/community/members/suhaibmousa032@gmail.com) Thanks to the ABP Community for all the content they have published. You can also [post your ABP-related (text or video) content](https://abp.io/community/posts/create) to the ABP Community. diff --git a/docs/en/Community-Articles/2024-08-12-join-abp-at-net-conf-focus-on-ai/post.md b/docs/en/Community-Articles/2024-08-12-join-abp-at-net-conf-focus-on-ai/post.md index 432ece093c..f1a4f979fa 100644 --- a/docs/en/Community-Articles/2024-08-12-join-abp-at-net-conf-focus-on-ai/post.md +++ b/docs/en/Community-Articles/2024-08-12-join-abp-at-net-conf-focus-on-ai/post.md @@ -17,7 +17,7 @@ Get ready for deep dives into AI integration, practical examples, and insights f ### Session Highlights * **Getting Started with AI in .NET** by *Stephen Toub* -* **NET Aspire and Semantic Kernel** by *Steve Sanderson* and *Matthew Bolanos* +* **Aspire and Semantic Kernel** by *Steve Sanderson* and *Matthew Bolanos* * **Interactive AI with Blazor and .NET** by *Dan Roth* * **AI Models in .NET: From Local to Cloud** by *Bruno Capuano* * **RAG with .NET and Azure SQL** by *Davide Mauri* diff --git a/docs/en/Community-Articles/2024-10-01-SignalR-9-New-Features/Post.md b/docs/en/Community-Articles/2024-10-01-SignalR-9-New-Features/Post.md index c92e38f764..e662dd5231 100644 --- a/docs/en/Community-Articles/2024-10-01-SignalR-9-New-Features/Post.md +++ b/docs/en/Community-Articles/2024-10-01-SignalR-9-New-Features/Post.md @@ -44,7 +44,7 @@ public class MyHub : Hub ### Better Diagnostics and Telemetry -Microsoft focuses mainly on .NET Aspire nowadays. That’s why SignalR now integrates more deeply with the .NET Activity API, which is commonly used for distributed tracing. The enhancement is implemented for better monitoring in [.NET Aspire Dashboard](https://learn.microsoft.com/en-us/dotnet/aspire/fundamentals/dashboard/overview?tabs=bash#using-the-dashboard-with-net-aspire-projects). To support this feature: +Microsoft focuses mainly on Aspire nowadays. That’s why SignalR now integrates more deeply with the .NET Activity API, which is commonly used for distributed tracing. The enhancement is implemented for better monitoring in [Aspire Dashboard](https://aspire.dev/dashboard/overview/). To support this feature: 1- Add these packages to your`csproj`: @@ -76,9 +76,9 @@ builder builder.Services.ConfigureOpenTelemetryTracerProvider(tracing => tracing.AddOtlpExporter()); ``` -Finally, you’ll see the **SignalR Hub** events on the [Aspire Dashboard](https://learn.microsoft.com/en-us/dotnet/aspire/fundamentals/dashboard/overview): +Finally, you’ll see the **SignalR Hub** events on the [Aspire Dashboard](https://aspire.dev/dashboard/overview/): -![.NET Aspire Activity Dashboard](signalr-activity-dashboard.png) +![Aspire Activity Dashboard](signalr-activity-dashboard.png) diff --git a/docs/en/Community-Articles/2024-10-11-NET-Aspire-vs-ABP-Studio/POST.md b/docs/en/Community-Articles/2024-10-11-NET-Aspire-vs-ABP-Studio/POST.md index fe7b706b5a..db3eacbd9c 100644 --- a/docs/en/Community-Articles/2024-10-11-NET-Aspire-vs-ABP-Studio/POST.md +++ b/docs/en/Community-Articles/2024-10-11-NET-Aspire-vs-ABP-Studio/POST.md @@ -1,18 +1,18 @@ -# .NET Aspire vs ABP Studio: Side by Side +# Aspire vs ABP Studio: Side by Side -In this article, I will compare [.NET Aspire](https://learn.microsoft.com/en-us/dotnet/aspire/) by [ABP Studio](https://abp.io/docs/latest/studio) by explaining their similarities and differences. +In this article, I will compare [Aspire](https://aspire.dev/) by [ABP Studio](https://abp.io/docs/latest/studio) by explaining their similarities and differences. ## Introduction -While .NET Aspire and ABP Studio are tools for different purpose with different scope and they have different approaches to solve the problems, many developers still may confuse since they also have some similar functionalities and solves some common problems. +While Aspire and ABP Studio are tools for different purpose with different scope and they have different approaches to solve the problems, many developers still may confuse since they also have some similar functionalities and solves some common problems. -In this article, I will clarify all, and you will have a clear understanding of what are the similarities and differences of them. Let's start by briefly define what are .NET Aspire and ABP Studio. +In this article, I will clarify all, and you will have a clear understanding of what are the similarities and differences of them. Let's start by briefly define what are Aspire and ABP Studio. -### What is .NET Aspire? +### What is Aspire? -**[.NET Aspire](https://learn.microsoft.com/en-us/dotnet/aspire/)** is a **cloud-ready framework** designed to simplify building distributed, observable, and production-ready applications. It provides a set of opinionated tools and NuGet packages tailored for cloud-native concerns like **orchestration**, **service integration** (e.g., Redis, PostgreSQL), and **telemetry**. Aspire focuses on the **local development experience**, making it easier to manage complex, multi-service apps by **abstracting away configuration details**. +**[Aspire](https://aspire.dev/)** is a **cloud-ready framework** designed to simplify building distributed, observable, and production-ready applications. It provides a set of opinionated tools and NuGet packages tailored for cloud-native concerns like **orchestration**, **service integration** (e.g., Redis, PostgreSQL), and **telemetry**. Aspire focuses on the **local development experience**, making it easier to manage complex, multi-service apps by **abstracting away configuration details**. -Here, a screenshot from [.NET Aspire dashboard](https://learn.microsoft.com/en-us/dotnet/aspire/fundamentals/dashboard/overview) that is used for application monitoring and inspection: +Here, a screenshot from [Aspire dashboard](https://aspire.dev/dashboard/overview/) that is used for application monitoring and inspection: ![dotnet-aspire-dashboard](dotnet-aspire-dashboard.png) @@ -26,7 +26,7 @@ Here, a screenshot from the ABP Studio [Solution Runner panel](https://abp.io/do ## A Brief Comparison -Before deep diving details, I want to show a **table of features** to compare ABP Studio and .NET Aspire side by side: +Before deep diving details, I want to show a **table of features** to compare ABP Studio and Aspire side by side: ![abp-studio-vs-net-aspire-comparison-table](abp-studio-vs-dotnet-aspire-comparison-table.png) @@ -36,30 +36,30 @@ In the next sections, I will go through each feature and explain differences and ### Integration Packages -ABP Framework has tens of integration packages to 3rd-party libraries and services. .NET Aspire also has some library integrations. But these integrations have different purposes: +ABP Framework has tens of integration packages to 3rd-party libraries and services. Aspire also has some library integrations. But these integrations have different purposes: * **ABP Framework**'s integrations (like [MongoDB](https://abp.io/docs/latest/framework/data/mongodb), [RabbitMQ](https://abp.io/docs/latest/framework/infrastructure/background-jobs/rabbitmq), [Dapr](https://abp.io/docs/latest/framework/dapr), etc) are integrations for its abstractions and aimed to be **used directly by your application code**. They are complete and sophisticated integrations with the ABP Framework and your codebase. -* **.NET Aspire**'s integrations (like [MongoDB](https://learn.microsoft.com/en-us/dotnet/aspire/database/mongodb-integration), [RabbitMQ](https://learn.microsoft.com/en-us/dotnet/aspire/messaging/rabbitmq-integration), [Dapr](https://learn.microsoft.com/en-us/dotnet/aspire/frameworks/dapr), etc), on the other hand, for simplifying configuration, service discovery, orchestration and monitoring of these tools within .NET Aspire host. Basically, these are mostly for **integrating to .NET Aspire**, not for integrating to your application. +* **Aspire**'s integrations (like [MongoDB](https://aspire.dev/integrations/databases/mongodb/), [RabbitMQ](https://aspire.dev/integrations/messaging/rabbitmq/), [Dapr](https://aspire.dev/integrations/frameworks/dapr/), etc), on the other hand, for simplifying configuration, service discovery, orchestration and monitoring of these tools within Aspire host. Basically, these are mostly for **integrating to Aspire**, not for integrating to your application. For example, ABP's [MongoDB](https://abp.io/docs/latest/framework/data/mongodb) integration allows you to use MongoDB over [repository services](https://abp.io/docs/latest/framework/architecture/domain-driven-design/repositories), automatically handles database transactions, [audit logs](https://abp.io/docs/latest/framework/infrastructure/audit-logging), [event publishing](https://abp.io/docs/latest/framework/infrastructure/event-bus/distributed) on data saves, dynamic [connection string](https://abp.io/docs/latest/framework/fundamentals/connection-strings) management, [multi-tenancy](https://abp.io/docs/latest/framework/architecture/multi-tenancy) integration and so on. -On the other hand, .NET Aspire's [MongoDB](https://learn.microsoft.com/en-us/dotnet/aspire/database/mongodb-integration) integration basically adds [MongoDB driver library](https://www.nuget.org/packages/MongoDB.Driver/) to your .NET Aspire host application and configures it so you can discover MongoDB server on runtime, use a MongoDB Docker container and see its health status, logs and traces on .NET Aspire dashboard. +On the other hand, Aspire's [MongoDB](https://aspire.dev/integrations/databases/mongodb/) integration basically adds [MongoDB driver library](https://www.nuget.org/packages/MongoDB.Driver/) to your Aspire host application and configures it so you can discover MongoDB server on runtime, use a MongoDB Docker container and see its health status, logs and traces on Aspire dashboard. ### Starter Templates -Both of ABP Studio and .NET Aspire provide **startup solution templates for new applications**. However, there are huge differences between these startup solution templates and their purpose are completely different. +Both of ABP Studio and Aspire provide **startup solution templates for new applications**. However, there are huge differences between these startup solution templates and their purpose are completely different. * ABP Studio provides **production-ready** and [advanced solution templates](https://abp.io/docs/latest/solution-templates) for **layered**, **modular** or **microservice** solution development. They are well configured for **local development** and deploying to **Kubernetes** and other **production environments**. They provide different **UI and database options**, many optional modules and configuration. For example, you can check the [microservice solution template](https://abp.io/docs/latest/solution-templates/microservice/overview) to see how **sophisticated** it is. -* .NET Aspire's [project templates](https://learn.microsoft.com/en-us/dotnet/aspire/fundamentals/setup-tooling?tabs=windows&pivots=visual-studio#net-aspire-project-templates)' main purpose is to provide a minimal application structure that is **pre-integrated to .NET Aspire** libraries and configured for **local development** environment. +* Aspire's [project templates](https://aspire.dev/get-started/aspire-sdk-templates/)' main purpose is to provide a minimal application structure that is **pre-integrated to Aspire** libraries and configured for **local development** environment. -So, when you start with .NET Aspire project template, you will need to deal with a lot of work to make your solution production and enterprise ready. On the other hand, ABP Studio's solution templates are ready to launch your system from the first day and they provide you a perfect starting point for your new business idea. +So, when you start with Aspire project template, you will need to deal with a lot of work to make your solution production and enterprise ready. On the other hand, ABP Studio's solution templates are ready to launch your system from the first day and they provide you a perfect starting point for your new business idea. ### Monitoring & Application Running -Monitoring applications and services is an important requirement for building **complex distributed systems**. Both of ABP Studio and .NET Aspire provide **excellent tools** for that purpose. +Monitoring applications and services is an important requirement for building **complex distributed systems**. Both of ABP Studio and Aspire provide **excellent tools** for that purpose. * ABP Studio's [Solution Runner panel](https://abp.io/docs/latest/studio/running-applications) provides a powerful UI to run and monitor applications and services. You can see all HTTP requests, distributed events, exceptions and detailed application logs, trace and find problems in your system. You can use its fully functional built-in browser to navigate application UIs easily. You can also create multiple profiles to group and configure the applications for different teams. -* .NET Aspire's [dashboard](https://learn.microsoft.com/en-us/dotnet/aspire/fundamentals/dashboard/overview) can be used to see the states of the running applications and containers, explore their console output, logs, traces and metrics to understand what is happing in your distributed system. +* Aspire's [dashboard](https://aspire.dev/dashboard/overview/) can be used to see the states of the running applications and containers, explore their console output, logs, traces and metrics to understand what is happing in your distributed system. Both tools are pretty useful for monitoring. In addition to monitoring, **ABP Studio offers an advanced UI to control the running applications**, build, start and stop individually or by a group of applications. @@ -85,7 +85,7 @@ Here a screenshot that shows how to add new microservices, API gateways or web a ![abp-studio-add-new-microservice](abp-studio-add-new-microservice.png) -.NET Aspire has no such a feature and has no such a plan to provide that kind of architectural solution building experience. +Aspire has no such a feature and has no such a plan to provide that kind of architectural solution building experience. ### Kubernetes Integration @@ -99,11 +99,11 @@ Here, a few tasks you can accomplish using ABP Studio's Kubernetes integration: * **Monitor** services and applications that are running in your Kubernetes cluster * **Intercept traffic** of a service and redirect requests to your local machine. In that way, you can develop, test and run individual services or applications in your local computer that is **fully integrated** to other services and applications running in Kubernetes. -ABP Studio's Kubernetes Integration makes microservice development so easy and comfortable. On the other hand, .NET Aspire has no such a Kubernetes integrated development experience. +ABP Studio's Kubernetes Integration makes microservice development so easy and comfortable. On the other hand, Aspire has no such a Kubernetes integrated development experience. ## The ABP Platform -Until now, I directly compared ABP Studio and .NET Aspire features. .NET Aspire is directly built on .NET and ASP.NET Core. However, ABP Studio is not a standalone tool that is built on .NET and ASP.NET Core. It is built on the [ABP Platform](https://abp.io/) (which is built on .NET and ASP.NET Core). +Until now, I directly compared ABP Studio and Aspire features. Aspire is directly built on .NET and ASP.NET Core. However, ABP Studio is not a standalone tool that is built on .NET and ASP.NET Core. It is built on the [ABP Platform](https://abp.io/) (which is built on .NET and ASP.NET Core). The following diagram shows ABP Platform components at a glance: @@ -111,26 +111,26 @@ The following diagram shows ABP Platform components at a glance: So, when you use ABP Studio, you also take full power of the [open source ABP Framework](https://github.com/abpframework/abp) and other ABP Platform features. -## ABP and .NET Aspire Integration +## ABP and Aspire Integration -I have a good news to you. It is actually possible and pretty easy to make ABP Platform and .NET Aspire working together. +I have a good news to you. It is actually possible and pretty easy to make ABP Platform and Aspire working together. -You can check [@berkansasmaz](https://abp.io/community/members/berkansasmaz)'s great article: **[How to use .NET Aspire with ABP framework](https://abp.io/community/articles/how-to-use-.net-aspire-with-abp-framework-h29km4kk)**. +You can check [@berkansasmaz](https://abp.io/community/members/berkansasmaz)'s great article: **[How to use Aspire with ABP framework](https://abp.io/community/articles/how-to-use-.net-aspire-with-abp-framework-h29km4kk)**. ## Licensing ABP Studio has a Community Edition which is completely free and available to everyone. It includes many of the features I mentioned here. There is also a commercial edition that is included in [commercial ABP licenses](https://abp.io/pricing). You can [check that blog post](https://abp.io/blog/announcing-abp-studio-general-availability) which clearly explains the license differences and introduces the fundamental ABP Studio features. -On the other hand, .NET Aspire is a free tool developed and published by Microsoft. It has no commercial version. +On the other hand, Aspire is a free tool developed and published by Microsoft. It has no commercial version. ## Conclusion -Both .NET Aspire and ABP Studio serve distinct purposes, catering to different types of development environments. While .NET Aspire excels in simplifying cloud-native application setups and observability, ABP Studio provides a comprehensive framework for modular monoliths and microservice architectures with full-fledged enterprise level production-ready startup solution templates and integrated tools. +Both Aspire and ABP Studio serve distinct purposes, catering to different types of development environments. While Aspire excels in simplifying cloud-native application setups and observability, ABP Studio provides a comprehensive framework for modular monoliths and microservice architectures with full-fledged enterprise level production-ready startup solution templates and integrated tools. -In the previous section, it was mentioned that it is possible to [use them together](https://abp.io/community/articles/how-to-use-.net-aspire-with-abp-framework-h29km4kk). You don't have to select one of them. However, in my opinion, when you use ABP Studio, you won't need .NET Aspire since ABP Studio can do everything and much more. If you have budget, I suggest to purchase a commercial ABP Studio [license](https://abp.io/pricing) so you can fully unlock its power. +In the previous section, it was mentioned that it is possible to [use them together](https://abp.io/community/articles/how-to-use-.net-aspire-with-abp-framework-h29km4kk). You don't have to select one of them. However, in my opinion, when you use ABP Studio, you won't need Aspire since ABP Studio can do everything and much more. If you have budget, I suggest to purchase a commercial ABP Studio [license](https://abp.io/pricing) so you can fully unlock its power. ## Resources / Further Reading * [ABP Studio documentation](https://abp.io/docs/latest/studio) -* [.NET Aspire documentation](https://learn.microsoft.com/en-us/dotnet/aspire/) -* [How to use .NET Aspire with ABP framework](https://abp.io/community/articles/how-to-use-.net-aspire-with-abp-framework-h29km4kk) +* [Aspire documentation](https://aspire.dev/) +* [How to use Aspire with ABP framework](https://abp.io/community/articles/how-to-use-.net-aspire-with-abp-framework-h29km4kk) diff --git a/docs/en/Community-Articles/2024-10-23-abpio-platform-90-rc-has-been-published/post.md b/docs/en/Community-Articles/2024-10-23-abpio-platform-90-rc-has-been-published/post.md index a7dfa896bd..3cdec2269e 100644 --- a/docs/en/Community-Articles/2024-10-23-abpio-platform-90-rc-has-been-published/post.md +++ b/docs/en/Community-Articles/2024-10-23-abpio-platform-90-rc-has-been-published/post.md @@ -205,7 +205,7 @@ There are exciting articles contributed by the ABP community as always. I will h * [Mohammad AlMohammad AlMahmoud](https://abp.io/community/members/Mohammad97Dev) has created **two** new community articles: * [Implementing Multi-Language Functionality With ABP Framework](https://abp.io/community/articles/implementing-multilanguage-functionality-with-abp-framework-loq7kfx4) * [Configure Quartz.Net in Abp FrameWork](https://abp.io/community/articles/configure-quartz.net-in-abp-framework-3bveq4y1) -* [.NET Aspire vs ABP Studio: Side by Side](https://abp.io/community/articles/.net-aspire-vs-abp-studio-side-by-side-t1c73d1l) by [Halil İbrahim Kalkan](https://twitter.com/hibrahimkalkan) +* [Aspire vs ABP Studio: Side by Side](https://abp.io/community/articles/.net-aspire-vs-abp-studio-side-by-side-t1c73d1l) by [Halil İbrahim Kalkan](https://twitter.com/hibrahimkalkan) * [PoC of using GrapesJS for ABPs CMS Kit](https://abp.io/community/articles/poc-of-using-grapesjs-for-abps-cms-kit-1rmv4q41) by [Jack Fistelmann](https://abp.io/community/members/jfistelmann) * [ABP-Powered Web App with Inertia.js, React, and Vite](https://abp.io/community/articles/abppowered-web-app-with-inertia.js-react-and-vite-j7cccvad) by [Anto Subash](https://antosubash.com/) * [Multi-Tenancy Support in Angular Apps with ABP.IO](https://abp.io/community/articles/multitenancy-support-in-angular-apps-with-abp.io-lw9l36c5) by [HeadChannel Team](https://headchannel.co.uk/) diff --git a/docs/en/Community-Articles/2024-11-05-.NET Aspire 9.0 Features/Post.md b/docs/en/Community-Articles/2024-11-05-.NET Aspire 9.0 Features/Post.md index 174aca756d..91008416df 100644 --- a/docs/en/Community-Articles/2024-11-05-.NET Aspire 9.0 Features/Post.md +++ b/docs/en/Community-Articles/2024-11-05-.NET Aspire 9.0 Features/Post.md @@ -1,27 +1,27 @@ -# .NET Aspire 9.0 Features +# Aspire 9.0 Features -.NET Aspire 9.0 is the next major release, supporting both .NET 8 and .NET 9. This version includes new features and improvements. +Aspire 9.0 is the next major release, supporting both .NET 8 and .NET 9. This version includes new features and improvements. -## Upgrade to .NET Aspire +## Upgrade to Aspire -Now, you don't need workloads to develop .NET Aspire applications. In your project, you can add an SDK reference to `Aspire.AppHost.Sdk`. -For more information, you can check out [https://learn.microsoft.com/en-us/dotnet/aspire/whats-new/dotnet-aspire-9?tabs=windows#upgrade-to-net-aspire-9](https://learn.microsoft.com/en-us/dotnet/aspire/whats-new/dotnet-aspire-9?tabs=windows#upgrade-to-net-aspire-9) which explains upgrading an existing project in details. +Now, you don't need workloads to develop Aspire applications. In your project, you can add an SDK reference to `Aspire.AppHost.Sdk`. +For more information, you can check out [https://aspire.dev/whats-new/aspire-9/#upgrade-to-aspire-9](https://aspire.dev/whats-new/aspire-9/#upgrade-to-aspire-9) which explains upgrading an existing project in details. ## Dashboard -.NET Aspire offers a nice dashboard for developers to observe the performance and behavior of their applications. In this version, there are some enhancements; +Aspire offers a nice dashboard for developers to observe the performance and behavior of their applications. In this version, there are some enhancements; * **Manage resource lifecycle**: You can stop, start, and restart resources. -* **Mobile and responsive support**: The .NET Aspire dashboard is now mobile-friendly. +* **Mobile and responsive support**: The Aspire dashboard is now mobile-friendly. * **Sensitive properties**: Properties can be marked as sensitive, automatically masking them in the dashboard UI. * **Volumes**: Configured container volumes are listed in resource details. -* **Health checks**: .NET Aspire 9 adds support for health checks. +* **Health checks**: Aspire 9 adds support for health checks. ![Resource Lifecycle](./aspire_resource_lifecycle.jpg) ## Telemetry -.NET Aspire 9 comes with many new features to the Telemetry service. +Aspire 9 comes with many new features to the Telemetry service. * **Improve telemetry filtering**: Telemetry data can now be filtered by attribute values. * **Combine telemetry from multiple resources**: If a resource has multiple replicas, you can now filter telemetry data to view from all instances. @@ -32,23 +32,23 @@ For more information, you can check out [https://learn.microsoft.com/en-us/dotne ## Orchestration The .NET App Host is a core component of the .NET runtime that helps launch and execute .NET applications. -.NET Aspire 9 introduces many new features to the app host. Let's take a look; +Aspire 9 introduces many new features to the app host. Let's take a look; * **Waiting for dependencies**: You can configure a resource to wait for another resource to start before starting. * **Resource health checks**: The `Waiting for dependencies` feature uses health checks to determine if a resource is ready. ## Integrations -.NET Aspire has integrations with some services and tools that make it easy to get started. New integrations are coming with .NET Aspire 9. +Aspire has integrations with some services and tools that make it easy to get started. New integrations are coming with Aspire 9. * Redis Insight * OpenAI (Preview) * MongoDB * Azure -For Azure part, it is better to check the official documentation here [https://learn.microsoft.com/en-us/dotnet/aspire/whats-new/dotnet-aspire-9-release-candidate-1?tabs=windows&pivots=visual-studio#azure](https://learn.microsoft.com/en-us/dotnet/aspire/whats-new/dotnet-aspire-9-release-candidate-1?tabs=windows&pivots=visual-studio#azure) because it has a very detailed explanation. +For Azure part, it is better to check the official documentation here [https://aspire.dev/whats-new/aspire-9/#important-azure-improvements](https://aspire.dev/whats-new/aspire-9/#important-azure-improvements) because it has a very detailed explanation. ## ABP Studio -.NET Aspire and [ABP Studio](https://abp.io/studio) are tools for different purposes with different scopes, and they have different approaches to solving problems; many developers may still be confused since they also have some similar functionalities and solve some common problems. You can check the comparison of .NET Aspire and ABP Studio in this [article](https://abp.io/community/articles/.net-aspire-vs-abp-studio-side-by-side-t1c73d1l). +Aspire and [ABP Studio](https://abp.io/studio) are tools for different purposes with different scopes, and they have different approaches to solving problems; many developers may still be confused since they also have some similar functionalities and solve some common problems. You can check the comparison of Aspire and ABP Studio in this [article](https://abp.io/community/articles/.net-aspire-vs-abp-studio-side-by-side-t1c73d1l). diff --git a/docs/en/Community-Articles/2025-11-30-NET-Conf-China-2025/POST.md b/docs/en/Community-Articles/2025-11-30-NET-Conf-China-2025/POST.md index 6f8dfb96a1..94602b4188 100644 --- a/docs/en/Community-Articles/2025-11-30-NET-Conf-China-2025/POST.md +++ b/docs/en/Community-Articles/2025-11-30-NET-Conf-China-2025/POST.md @@ -10,9 +10,9 @@ This year’s conference focused on three main themes: performance improvements, ### Opening Keynote -Scott Hanselman kicked off .NET Conf China 2025 with a video keynote, announcing that .NET 10 is now available on the official website. He framed the release around four pillars—AI, cloud-native, cross-platform, and performance—including integration with the Microsoft Agent Framework for building and orchestrating multi-agent systems in .NET/C#, industry-leading container and Kubernetes support with .NET Aspire simplifying local containerized development, a richer cross-platform desktop ecosystem (.NET MAUI, Avalonia, Uno Platform), and major performance gains such as Native AOT and single-file publishing for faster startup and easier distribution across platforms. +Scott Hanselman kicked off .NET Conf China 2025 with a video keynote, announcing that .NET 10 is now available on the official website. He framed the release around four pillars—AI, cloud-native, cross-platform, and performance—including integration with the Microsoft Agent Framework for building and orchestrating multi-agent systems in .NET/C#, industry-leading container and Kubernetes support with Aspire simplifying local containerized development, a richer cross-platform desktop ecosystem (.NET MAUI, Avalonia, Uno Platform), and major performance gains such as Native AOT and single-file publishing for faster startup and easier distribution across platforms. -He underscored China’s importance as .NET’s second-largest market, with roughly 13% of users, and noted that generative AI usage in China has doubled in 2025. The local community is seeing strong momentum around ML.NET, .NET Aspire, and the C# Dev Kit in VS Code. Reflecting on his Baby Smash game written 20 years ago, which now runs cross-platform on .NET 10, he called on developers to modernize: move existing Web, WinForms, and WPF apps to the cloud, improve performance, ship as a single executable, and weave in AI capabilities. +He underscored China’s importance as .NET’s second-largest market, with roughly 13% of users, and noted that generative AI usage in China has doubled in 2025. The local community is seeing strong momentum around ML.NET, Aspire, and the C# Dev Kit in VS Code. Reflecting on his Baby Smash game written 20 years ago, which now runs cross-platform on .NET 10, he called on developers to modernize: move existing Web, WinForms, and WPF apps to the cloud, improve performance, ship as a single executable, and weave in AI capabilities. On AI, he emphasized a human-centered stance: AI and agents should augment, not replace, developers. In the future, developers will orchestrate and govern agents, and human judgment will matter more than ever. He closed by thanking the open-source community for its many proposals and pull requests, stressing that .NET is an open-source platform built together by Microsoft and the community, and wishing everyone an inspiring conference and a joyful journey with .NET 10. @@ -28,7 +28,7 @@ The roundtable discussion, titled “Empowering with AI, Breaking Through Cross- The afternoon featured four breakout sessions, covering a wide range of topics with deep dives into both foundational technologies and real-world project reviews: -- **Frontend and Cross-Platform:** Focused on the progress of Avalonia, Blazor, and WebAssembly, as well as the integrated experience of .NET Aspire in multi-service applications. Speakers shared insights on reusing core logic between desktop and web, shortening cold start times with incremental compilation and resource trimming, and performance profiling and optimization in WASM scenarios. +- **Frontend and Cross-Platform:** Focused on the progress of Avalonia, Blazor, and WebAssembly, as well as the integrated experience of Aspire in multi-service applications. Speakers shared insights on reusing core logic between desktop and web, shortening cold start times with incremental compilation and resource trimming, and performance profiling and optimization in WASM scenarios. - **AI Agents and Enterprise Adoption:** Discussed multi-agent orchestration, the MCP plugin ecosystem, and enterprise data compliance. From common pitfalls of “demo-level” AI to the “five-step method” for moving from POC to production, the session covered use cases like knowledge retrieval, process automation, intelligent customer service, and developer assistants, emphasizing evaluation metrics, prompt engineering, and monitoring governance. - **.NET Practices and Engineering:** Focused on the latest capabilities and performance practices of EF Core, the boundaries of NativeAOT, automated testing strategies, and observability implementation. Discussions included database migration strategies, caching and concurrency control for hot paths, end-to-end tracing, and structured logging. - **Solutions and Case Studies:** From Clean Architecture/DDD to AI-powered business evolution, topics included application modernization, SaaS transformation, and edge-cloud collaboration in AIoT. Speakers broke down modular governance, team collaboration, and release strategies for complex systems, putting “delivering value continuously” at the center stage. diff --git a/docs/en/Community-Articles/2026-07-07-resource-based-api-for-angular/POST.md b/docs/en/Community-Articles/2026-07-07-resource-based-api-for-angular/POST.md new file mode 100644 index 0000000000..aaccc1febc --- /dev/null +++ b/docs/en/Community-Articles/2026-07-07-resource-based-api-for-angular/POST.md @@ -0,0 +1,450 @@ +# Angular Resource APIs Explained: Generating Signal-Based Service Proxies + +Angular's shift toward **Signals** has changed how applications model state and data loading. Instead of manually coordinating subscriptions, loading flags, and error handling, Angular now provides resource APIs that integrate asynchronous data fetching directly into the signal ecosystem. + +To embrace this programming model, ABP now offers an **optional Resource API generation mode** for Angular service proxies. When enabled, the proxy generator produces signal-friendly APIs for read operations while preserving the familiar Observable-based experience for the rest of your application. + +This article introduces the new Resource API generation mode, explains why it exists, how it works, and when it should be preferred over traditional Observable-based proxies. + +--- + +## Why Resource APIs + +For years, Angular applications have relied on observable-based services to communicate with backend APIs. While Observables remain extremely powerful, consuming them inside components often requires additional state management. + +A typical read operation usually involves: + +- subscribing to an Observable, +- tracking loading state, +- storing the latest value, +- handling errors, +- cleaning up subscriptions when necessary. + +As applications adopt Signals for local state, this pattern starts to feel increasingly imperative. The component becomes responsible not only for displaying data, but also for orchestrating the entire request lifecycle. + +Angular's Resource APIs address this problem by treating asynchronous data as reactive state. Instead of manually reacting to changes, you describe **what the request depends on**, and Angular automatically keeps the resource synchronized. + +For example, if a request depends on an entity ID represented as a `Signal`, changing that signal automatically triggers a new request. The component no longer needs to manually subscribe or invoke refresh logic simply because an input changed. + +This approach offers several benefits: + +- loading, error, and value state are managed together, +- requests automatically react to signal changes, +- components become more declarative, +- significantly less boilerplate is required. + +Resource APIs are therefore an excellent fit for **read-only data retrieval**, where the primary goal is to keep the UI synchronized with backend state. + +--- + +## What Angular Gives Us + +Angular provides several APIs for working with asynchronous resources, each targeting a slightly different use case. + +### `resource` + +The `resource` API is Angular's generic primitive for asynchronous state. + +It is designed for loaders that return promise-based results and automatically exposes: + +- the current value, +- loading status, +- errors, +- reload capabilities. + +This API is ideal when your asynchronous source is not based on RxJS. + +### `rxResource` + +Most Angular applications—including ABP applications—already communicate with the backend through `HttpClient`, whose APIs return Observables. + +The `rxResource` helper bridges these existing Observable streams with Angular's Resource model. Instead of rewriting existing services to use Promises, it simply wraps an Observable-producing function and exposes it as a reactive resource. + +Internally, the new ABP proxy generation mode uses this approach. Generated resource methods eventually call the existing `RestService` request pipeline, while exposing the result as an Angular `ResourceRef`. This means existing authentication, interceptors, multi-tenancy, localization, error handling, and other ABP infrastructure continue to work exactly as before. + +### `httpResource` + +Angular also provides `httpResource`, which is a specialized resource implementation built directly on top of `HttpClient`. + +For applications making direct HTTP requests, this can be a convenient option. + +However, ABP applications already centralize HTTP communication through `RestService`, which adds framework-specific behavior around every request. Because of that, the generated proxies rely on `rxResource` rather than `httpResource`, allowing them to preserve the entire ABP request pipeline while still providing a signal-based API. + +In short: + +| API | Intended for | +| --- | --- | +| `resource` | Generic asynchronous loaders returning Promises | +| `rxResource` | Existing RxJS/Observable-based data sources | +| `httpResource` | Direct `HttpClient` requests without additional abstraction | + +Since ABP proxies already build on top of `RestService`, `rxResource` is the natural choice for bringing Signal-based data loading to generated client proxies. + +--- + +## Why This Feature Is Opt-In + +One of the primary goals of the new Resource API generation mode is to introduce a modern, Signal-friendly API **without disrupting existing applications**. + +ABP's generated Angular service proxies have been Observable-based for years, and they continue to serve a wide range of applications effectively. Many projects already rely on RxJS operators, custom Observable pipelines, and existing component patterns. Replacing those generated APIs would introduce unnecessary breaking changes for little benefit. + +Instead, Resource API generation is **completely opt-in**. + +By passing the `--resource-api` option to the `abp generate-proxy` command, the generator produces additional resource helpers designed for Angular's Signal ecosystem. If you do not enable the option, proxy generation behaves exactly as it always has, producing the familiar Observable-based services. + +This gradual approach offers several advantages: + +- Existing applications continue working without modification. +- Teams can adopt Signals incrementally instead of performing a large migration. +- New pages can embrace Resource APIs while older features continue using Observables. +- Developers remain free to choose the programming model that best fits each feature. + +Another intentional design decision is that **only read operations receive Resource API helpers**. + +Resource APIs naturally model asynchronous state that can be refreshed whenever their reactive inputs change. This makes them an excellent fit for `GET` requests, where the goal is to retrieve and synchronize data. + +Write operations such as `POST`, `PUT`, `PATCH`, and `DELETE` represent user actions rather than continuously synchronized state. These operations are typically composed with RxJS pipelines, optimistic updates, notifications, or custom error handling, making Observables the more appropriate abstraction. + +By limiting Resource APIs to read operations, generated proxies follow Angular's recommended usage patterns while keeping mutation APIs predictable and familiar. + +--- + +## Generator Behavior + +Enabling Resource API generation requires only a single additional option: + +```bash +abp generate-proxy -t ng --resource-api +``` + +Without this option, the generator behaves exactly as before, producing standard Observable-based service methods. + +For example, a generated service might expose a method like: + +```tsx +bookService.getList(input); +``` + +which returns an `Observable` and can be consumed with RxJS operators or converted into Signals using Angular's interoperability utilities. + +When `--resource-api` is enabled, the generator **preserves these existing methods** and additionally generates companion Resource API methods for every `GET` endpoint. + +For example: + +```tsx +bookService.getList(...); // Observable +bookService.getListResource(...); // ResourceRef +``` + +These generated resource methods internally use Angular's `rxResource` while continuing to execute requests through ABP's existing `RestService`. As a result, the complete ABP request pipeline—including authentication, interceptors, localization, multi-tenancy, and error handling—remains unchanged. + +The generator only creates resource helpers for `GET` endpoints. Mutation methods such as `create`, `update`, and `delete` continue to return Observables exactly as before. + +This selective generation keeps the generated API straightforward: + +- **Read operations** gain Signal-friendly Resource APIs. +- **Write operations** continue using Observables. +- **Existing Observable methods remain available**, allowing gradual adoption without forcing a migration. + +In the next section, we'll examine the shape of the generated Resource API methods and see how they integrate naturally with Angular Signals. + +--- + +## Generated API Shape + +The generated Resource API methods closely resemble their Observable counterparts, making them easy to adopt. Rather than introducing an entirely new programming model, they adapt the existing proxy APIs to Angular's Signal ecosystem. + +There are, however, a few important differences. + +### Signal-Based Inputs + +Traditional proxy methods accept plain values: + +```tsx +bookService.get(id); +``` + +The generated Resource API methods instead accept **Signals**. + +```tsx +const id = signal('42'); + +const book = bookService.getResource(id); +``` + +Because the input is reactive, Angular automatically re-executes the request whenever the signal value changes. + +```tsx +id.set('43'); +``` + +No additional method calls, subscriptions, or refresh logic are required—the resource stays synchronized with its dependencies automatically. + +### Returning a `ResourceRef` + +Observable-based proxy methods return an `Observable`. + +Resource methods instead return a `ResourceRef`, which exposes the request state as Signals. + +This gives components access to everything they typically need during data loading: + +- the current value, +- loading status, +- any request error, +- reload functionality. + +A component can consume the resource directly: + +```tsx +const book = bookService.getResource(id); + +book.value(); +book.isLoading(); +book.error(); +book.reload(); +``` + +Instead of maintaining separate signals for loading, data, and errors, the resource keeps these states together in a single reactive object. + +### Reactive Request Construction + +Many API endpoints require multiple parameters or request objects. + +Rather than asking developers to manually rebuild those objects whenever an input changes, the generated methods construct the request reactively using Angular's `computed()` API. + +Suppose a request depends on pagination and a search keyword: + +```tsx +const page = signal(1); +const filter = signal(''); +``` + +The generated proxy internally derives the request object from these Signals. + +Whenever either value changes, Angular recomputes the request and automatically performs a new HTTP request. + +This means developers only manage application state. The generated proxy takes care of determining **when** a request should be refreshed. + +--- + +## Examples + +Let's compare a few common scenarios to see how generated Resource APIs look in practice. + +### Fetching a Single Entity + +A traditional generated proxy might be used like this: + +```tsx +bookService.get(id).subscribe(...); +``` + +With Resource API generation enabled: + +```tsx +const id = signal('42'); + +const book = bookService.getResource(id); +``` + +Changing the ID automatically reloads the resource. + +```tsx +id.set('84'); +``` + +The component simply reads the latest value: + +```tsx +book.value(); +``` + +Angular handles the request lifecycle automatically. + +### Fetching a List with Query Parameters + +List endpoints become even more interesting because they usually depend on multiple reactive inputs. + +Consider a search page with pagination. + +```tsx +const filter = signal(''); +const skipCount = signal(0); +const maxResultCount = signal(10); +``` + +Using the generated proxy is straightforward: + +```tsx +const books = bookService.getListResource({ + filter, + skipCount, + maxResultCount, +}); +``` + +Whenever any of these Signals changes, Angular automatically refreshes the resource. + +```tsx +filter.set('Angular'); +skipCount.set(20); +``` + +There is no need to manually call `getList()` again or synchronize subscriptions with UI state. + +### Behind the Scenes + +Although the generated API feels simple to consume, the proxy performs a considerable amount of work internally. + +Conceptually, the generated method looks similar to the following: + +```tsx +getListResource(input: { + filter: Signal; + skipCount: Signal; + maxResultCount: Signal; +}): ResourceRef> { + return this.restService.requestResource({ + method: 'GET', + url: '/api/app/books', + params: computed(() => ({ + filter: input.filter(), + skipCount: input.skipCount(), + maxResultCount: input.maxResultCount(), + })), + }); +} +``` + +Notice that every request parameter is read inside a `computed()` callback. This establishes Angular's reactive dependency tracking, ensuring that any change to an input Signal automatically triggers a new request. + +As a consumer, you never need to think about this implementation detail. You simply update your Signals, and the generated proxy keeps the resource synchronized with your application's state. + +--- + +## Best Practices + +As with any new Angular feature, Resource APIs are most effective when used in the scenarios they were designed for. The following recommendations can help you get the most out of generated Resource-based proxies while keeping your codebase clean and maintainable. + +### Use Resource APIs for Read Operations + +Resource APIs are designed to represent **reactive, read-only state**. + +Whenever your UI needs to retrieve data that should stay synchronized with one or more Signals, generated resource methods are an excellent choice. + +Typical examples include: + +- entity details, +- paginated lists, +- search results, +- dashboard widgets, +- lookup data. + +These scenarios naturally benefit from automatic reloading whenever their reactive inputs change. + +### Keep Mutations as Observable Methods + +Operations that modify server state—such as creating, updating, or deleting data—should continue using the standard Observable-based proxy methods. + +Mutation requests often involve additional workflows such as: + +- displaying success notifications, +- handling validation errors, +- optimistic UI updates, +- chaining additional requests, +- navigation after completion. + +These workflows fit naturally into RxJS pipelines, which is why the generator intentionally keeps write operations unchanged. + +### Let Signals Drive Your Requests + +One of the biggest advantages of Resource APIs is that you no longer decide **when** to issue a request. + +Instead, you describe **what the request depends on**, and Angular takes care of the rest. + +Rather than writing code like: + +```tsx +filter.valueChanges.subscribe(() => loadBooks()); +``` + +simply update the underlying Signals. + +Whenever those Signals change, the generated resource automatically refreshes itself. + +This declarative approach removes much of the manual subscription and synchronization logic that traditionally accumulates in Angular components. + +### Build Request Objects with `computed()` + +When an endpoint accepts multiple parameters, derive the request object using `computed()` instead of constructing it manually. + +For example: + +```tsx +const request = computed(() => ({ + filter: filter(), + skipCount: skipCount(), + maxResultCount: maxResultCount(), +})); +``` + +This ensures Angular can correctly track every dependency involved in the request. + +Likewise, avoid reading Signal values outside of the reactive computation. + +Instead of extracting Signal values first: + +```tsx +const currentFilter = filter(); + +const request = computed(() => ({ + filter: currentFilter, +})); +``` + +read them directly inside the `computed()` callback: + +```tsx +const request = computed(() => ({ + filter: filter(), +})); +``` + +Doing so allows Angular to react whenever those Signals change. + +### Consume the Entire `ResourceRef` + +A generated resource provides much more than the retrieved value. + +Instead of creating separate Signals for loading and error state, consume the `ResourceRef` directly. + +For example: + +- `value()` exposes the latest successful result. +- `isLoading()` indicates whether a request is in progress. +- `error()` provides the latest request failure. +- `reload()` manually refreshes the resource when needed. + +Keeping these states together makes components easier to understand and reduces state duplication. + +### Choose the Right Resource API + +Angular offers multiple Resource APIs, each serving a different purpose. + +For generated ABP service proxies, the recommended approach is the generated Resource API based on `rxResource`, since it preserves the existing `RestService` pipeline and all of its framework integrations. + +If you're writing standalone Angular services that communicate directly with `HttpClient`, `httpResource` may be a better fit. + +Choosing the appropriate abstraction helps keep both your generated code and handwritten services consistent with Angular's intended usage patterns. + +--- + +## Conclusion + +Angular Signals have introduced a more declarative way to manage application state, and Resource APIs naturally extend that model to asynchronous data loading. + +With Resource API generation, ABP brings this programming model directly into generated Angular service proxies. Read operations become reactive, Signal-driven, and significantly easier to consume, while write operations continue using the familiar Observable-based APIs that already work well for mutations. + +Most importantly, this evolution is completely opt-in. Existing applications can continue using their current proxies without modification, while new features can gradually adopt Resource APIs wherever they provide the greatest benefit. + +Whether you're building a new Signal-first Angular application or incrementally modernizing an existing ABP solution, Resource-based proxy generation offers a straightforward path toward cleaner components, less boilerplate, and a more reactive data-fetching experience. \ No newline at end of file diff --git a/docs/en/Community-Articles/2026-08-06-tips-for-developers-new-to-abp-framework/Post.md b/docs/en/Community-Articles/2026-08-06-tips-for-developers-new-to-abp-framework/Post.md new file mode 100644 index 0000000000..35e23f7ccb --- /dev/null +++ b/docs/en/Community-Articles/2026-08-06-tips-for-developers-new-to-abp-framework/Post.md @@ -0,0 +1,511 @@ +If you come from plain ASP.NET Core and open your first ABP solution, the initial reaction is often the same: *why are there so many projects, layers, DTOs, interfaces and base classes just to build a simple feature?* 🤔 + +That reaction is normal 👌 + +ABP Framework gives you a lot on day one: modularity, DDD-friendly structure, application services, repositories, auto API controllers, authorization, auditing, multi-tenancy and UI integration patterns. +The upside is speed and consistency on serious business apps. +The downside is that beginners can hit an abstraction wall before they see the payoff. + +After reviewing recent discussions, one pattern is clear: most developers do not struggle with C# or ASP.NET Core itself. +They struggle with *where code is supposed to go* in ABP and *which parts are essential versus optional*. + +In this post, I'll focus on that gap. If you are new to ABP, here is what actually helps. + +## The biggest learning barrier is not syntax! It is responsibility boundaries + +The hardest part for most newcomers is not learning one more framework API. +It's understanding the architectural split: + +- What belongs in the **Domain** layer? +- What belongs in **Application** services? +- Why do **DTOs** exist if you already have entities? +- When do you need a **repository**? +- Why are there separate projects like `Application.Contracts`, `Domain.Shared` and `EntityFrameworkCore`? + +In plain ASP.NET Core apps, many developers put a lot of this logic in controllers, services or even EF Core models. +ABP forces you toward clearer separation. + +A practical mental model: + +- **Entity / Aggregate Root**: business state and core invariants +- **Domain Service**: domain logic that does not naturally belong to a single entity +- **Repository**: persistence access for aggregates +- **Application Service**: use-case orchestration, authorization, DTO mapping, transaction boundary +- **DTO**: data contract for input/output +- **UI / API layer**: presentation concerns only + +> That sounds clean on paper... +> The confusion starts when you build something real 🥴 + +### A simple example: where should validation go? + +Suppose you are creating an `Order`. + +- If the rule is "order total must be greater than zero," **that's domain logic**. +- If the rule is "only users with the Orders.Create permission can create an order," **that belongs in the application layer**. +- If the rule is "customer name is required on this page," **that may exist in DTO validation too**. + +New ABP developers often ask which layer owns relationships, validation and business rules. + +> The honest answer is: different validation lives in different places. + +That is the first ABP lesson worth learning👍 + + + +![Generated illustration](abp-layers.png) + +## Why ABP Feels Heavy at First! + +**ABP is opinionated**. It's not trying to be the thinnest possible wrapper over ASP.NET Core. + +What beginners usually experience as "**too much structure**" comes from 4 things: + +### 1. Project and layer count + +A typical ABP solution can include: + +- `Domain` +- `Domain.Shared` +- `Application` +- `Application.Contracts` +- `EntityFrameworkCore` +- `HttpApi` +- `HttpApi.Client` +- UI project such as MVC, Razor Pages, Blazor or Angular +- Test projects + +For a small feature, that can feel excessive... **For a long-lived business system, it starts to make sense**. + +### 2. Generated convenience hides the mechanics + +ABP can generate a lot of CRUD plumbing and generic base classes like `CrudAppService` reduce repetitive code. +That's useful, but it can also hide how things connect. + +A beginner sees a working page and API without fully understanding: + +- how the application service is exposed as an API +- where repository methods are coming from +- how DTO mapping works +- why the UI calls application contracts instead of entities + +### 3. DDD terminology raises the entry cost + +You do not need to become a DDD master to use ABP well... But ABP definitely assumes some familiarity with: + +- entities +- aggregate roots +- repositories +- value objects +- domain services +- bounded contexts and modules + +If those ideas are new, ABP can feel harder than it really is. + +### 4. UI integration is not always obvious + +Newcomers also get stuck on the end-to-end flow: + +1. User clicks a button on a Razor Page or Blazor page +2. UI sends data to an application service or HTTP API +3. Application service validates permissions and input +4. Domain and repository code runs +5. DTO comes back to the UI + +Once you understand that flow, ABP becomes much more predictable. + +## Start with CRUD, but do not stop there + +A common question is whether beginners should start with simple CRUD or jump straight into a realistic business module. + +My view: **start with CRUD, then quickly move to a business feature with real rules**. + +### Why CRUD is the right first step + +CRUD teaches the ABP basics with low cognitive load: + +- project structure +- entity definition +- DTOs +- repositories +- application services +- permissions +- UI page wiring +- migrations and database updates + +This is why the [ABP BookStore tutorial](https://abp.io/docs/latest/tutorials/book-store) is a useful starting point. + +### Why CRUD alone is not enough + +Pure CRUD can give you a false sense of understanding. + +A generated Create / Read / Update / Delete screen does not force you to deal with: + +- aggregate boundaries +- child collections +- business invariants +- cross-entity rules +- domain services +- richer authorization scenarios +- multi-tenancy behavior +- auditing decisions + +Those are the areas where ABP starts to justify its structure. + +### A better learning sequence + +Use this progression: + +1. Build one very small CRUD module +2. Rebuild part of it manually instead of relying only on generation +3. Build one realistic business module with at least one non-trivial rule +4. Add authorization, validation and a relationship +5. Add tests around the domain or application service + +That path keeps the early win while exposing the real architecture. + + + +![Generated illustration](crud-vs-manual.png) + +## Generated CRUD vs manual CRUD: learn both + +This is one of the most useful mindset shifts for ABP beginners. + +**Generated CRUD is for productivity. Manual CRUD is for understanding.** + +You need both. + +### When generated CRUD helps + +ABP Suite and ABP base services can save time when the feature is mostly standard admin functionality: + +- back-office reference data +- simple management screens +- low-risk maintenance pages +- conventional DTO/entity flows + +If the goal is shipping business software efficiently, generated code is not cheating. It is leverage. + +### When manual implementation matters + +You should manually implement at least one feature end to end so you understand: + +- how `CrudAppService` reduces boilerplate +- what repository methods are doing +- where validation belongs +- how authorization is applied +- how auto API controllers expose application services + +A lot of Reddit confusion around ABP comes from learning generated patterns before understanding the underlying manual version. + +### A good exercise + +Build `Product` management twice: + +- First with `CrudAppService` +- Then manually with custom application service methods and domain rules + +Compare both implementations. That single exercise teaches more than reading docs for hours. + +## Which DDD patterns real ABP teams often simplify + +This is where many beginners get relief: **not every ABP project uses full-strength DDD all the time.** + +Real teams often simplify the model, especially early on. + +### Patterns teams commonly keep + +These tend to deliver value quickly in ABP: + +- clear application service boundaries +- entities and aggregate roots +- repositories +- DTO separation +- modular structure +- permission-based authorization + +### Patterns teams often delay or reduce + +These are useful in the right context, but many teams do not force them into every feature: + +- dedicated domain services for very simple logic +- value objects for every tiny concept +- specification pattern everywhere +- excessive interface layering where no variation is expected +- over-splitting modules too early + +### A practical rule of thumb + +Use the simplest thing that preserves clarity. + +For example: + +- If a rule is trivial and local to one use case, putting it in an application service may be fine. +- If a rule protects business invariants and must hold regardless of caller, move it into the domain model. +- If a concept has behavior and invariants of its own, a value object may help. +- If it is just a shared enum or constant, `Domain.Shared` is often enough. + +ABP supports rich DDD patterns, but it does not require ceremony for ceremony's sake. + + + +![Generated illustration](abp-learning-path.png) + +## A concrete “ASP.NET Core to ABP” learning path + +If I had to design a practical learning path for experienced ASP.NET Core developers, it would look like this. + +### Step 1: Know what ABP is adding on top of ASP.NET Core + +Before touching templates, be comfortable with: + +- dependency injection +- configuration +- middleware basics +- EF Core or MongoDB +- controllers or Razor Pages or Blazor basics +- validation and authorization in ASP.NET Core + +> ABP builds on top of these. It does not replace the need to understand them. + +### Step 2: Learn the ABP solution structure + +Let's see each layer's goal: + +- `Domain`: core business model +- `Domain.Shared`: shared enums, constants, localization resources, simple shared types +- `Application.Contracts`: DTOs and service contracts +- `Application`: use cases and orchestration +- `EntityFrameworkCore`: database mappings and repository implementation details +- `HttpApi`: API exposure +- UI project: user interaction + +### Step 3: Understand modules and dependencies + +ABP's modularity is a major feature, but beginners often treat modules like folders with extra steps. + +They are more than that. + +A module defines: + +- dependency boundaries +- service registration scope +- reusable feature packaging +- initialization points via module lifecycle methods and `[DependsOn]` + +At first, use modules as organizational boundaries inside a modular monolith. Do not rush into distributed or microservice-style decomposition. + +### Step 4: Build one CRUD feature the ABP way + +Create a simple feature such as Books, Products or Categories. + +Make sure you understand: + +- entity creation +- migration flow +- DTO mapping +- application service methods +- permission checks +- how the UI or API calls the application layer + +### Step 5: Rebuild one part manually + +Now remove the training wheels for one feature. + +Instead of only leaning on base classes, explicitly write: + +- a custom application service method +- a custom repository query if needed +- domain validation or invariants +- a tailored DTO instead of generic CRUD shapes + +This is where ABP usually clicks. + +### Step 6: Build a realistic business module + +A good example is `Order Management`, `Leave Requests` or `Inventory Transfer`. + +Choose something with: + +- one-to-many relationship +- status transitions +- authorization rules +- at least one business invariant +- audit visibility + +That reveals why ABP's layered structure exists. + +### Step 7: Add built-in ABP concerns on purpose + +ABP shines when you use its built-in platform features intentionally: + +- authorization +- auditing +- validation +- localization +- multi-tenancy +- settings and permissions + +Do not treat these as advanced extras. They are part of the framework's real value. + +### Step 8: Learn testing by layer + +Even if you do not build a full testing strategy immediately, understand the testing shape: + +- domain tests for invariants and business rules +- application tests for use cases and permissions +- integration tests for persistence and module wiring + +A lot of ABP's architecture pays off once you start testing behavior in isolation. + +## A small example of responsibility split + +Here is a deliberately small example to make the layering less abstract. + +Suppose you have a leave request system. + +**Domain** concerns: + +- a leave request cannot be approved after rejection +- end date cannot be before start date +- total leave days must be positive + +**Application** concerns: + +- only managers can approve requests +- map input DTO to entity operations +- return a DTO shaped for the UI +- coordinate repository access and unit of work + +**UI** concerns: + +- disable approve button when user lacks permission +- show validation messages +- render status badges and filters + +That split is the heart of ABP. Once you start seeing features this way, the framework becomes much easier to navigate. + +## When to use ABP and when not to + +**ABP is powerful, but it is not automatically the right default for every ASP.NET Core project.** + +### When to use ABP + +ABP is a strong fit when you are building: + +- line-of-business applications +- admin-heavy platforms +- SaaS or multi-tenant systems +- modular monoliths that may grow over time +- systems that need built-in authorization, auditing, localization and consistent conventions +- teams that benefit from standardized architecture + +### When NOT to use ABP + +ABP may be excessive in the following situations: + +- a tiny API with minimal business logic +- a short-lived internal tool where framework structure would dominate the workload +- a team with no interest in layered architecture or DDD-style thinking +- a highly custom architecture where ABP conventions would mostly be bypassed + +The main cost of ABP is not performance or syntax 🤜 It is **architectural overhead**. +If the app is too small, that overhead may not pay back. + +--- + + + +## Common mistakes new ABP developers make + +These are the mistakes I see most often in early ABP learning. + +### 1. Trying to understand everything before building anything + +Do not wait until every project, package and abstraction makes sense. Build one feature first. + +### 2. Using generated code without reading it + +Generated CRUD is useful, but inspect what it created. Otherwise you will stay dependent on tooling. + +### 3. Forcing textbook DDD into every feature + +Not every screen needs aggregates, value objects, domain services and custom repositories all at once. + +### 4. Putting all business logic in application services + +This works for a while, but you eventually lose domain consistency. Protect important invariants closer to the domain model. + +### 5. Splitting into too many modules too early + +Start with a modular monolith mindset. Extract boundaries when they become meaningful. + +### 6. Ignoring built-in ABP features + +If you manually rebuild authorization, auditing or tenant-aware behavior without understanding ABP's built-ins, you are fighting the framework. + + + +## The learning path I would actually recommend to a new team + +If a team asked me for a practical ABP onboarding sequence, I would keep it simple: + +### 📚 Week 1: Basics and orientation + +- Review ABP solution structure +- Build the BookStore-style tutorial once +- Identify what each layer is responsible for + +### 📚 Week 2: Manual feature implementation + +- Build one small module manually +- Avoid too much generation +- Trace one request from UI to application service to repository to database + +### 📚 Week 3: Real business rules + +- Add relationships +- Add authorization +- Add a workflow or state transition +- Write tests for a few business rules + +### 📚 Week 4: Productivity and conventions + +- Reintroduce generated tooling where it saves time +- Standardize module patterns +- Decide which DDD patterns the team will use by default and which are optional + +That sequence teaches both the architecture and the productivity side of ABP. + +--- + + + +## Final perspective: learn the intent, not just the template + +ABP can feel complicated when approached as a collection of projects and base classes. It gets easier when you see the intent behind the structure: + +- protect business rules +- standardize application boundaries +- make common enterprise features reusable +- keep large apps maintainable + +If you are new to ABP, do not aim to master every pattern immediately. Aim to answer these four questions clearly for each feature: + +- What is the business rule? +- Which layer owns it? +- What data crosses the boundary? +- Which ABP feature already solves part of this problem? + +Once those answers become natural, ABP stops feeling heavy and starts feeling productive. + +--- + +## As a Summary + +- **The biggest ABP learning barrier is** understanding responsibility boundaries between domain, application services, DTOs, repositories and UI. +- **Start with a small CRUD feature**, but move quickly to a realistic business module with rules, relationships and permissions. +- **Learn both generated and manual CRUD**; one gives productivity, the other gives understanding. +- Real ABP teams often simplify DDD and adopt advanced patterns **only when the complexity justifies them**. +- **The best learning path is ASP.NET Core basics first**, then ABP layers, one manual feature, one real module and built-in features like authorization and auditing. \ No newline at end of file diff --git a/docs/en/Community-Articles/2026-08-06-tips-for-developers-new-to-abp-framework/abp-layers.png b/docs/en/Community-Articles/2026-08-06-tips-for-developers-new-to-abp-framework/abp-layers.png new file mode 100644 index 0000000000..a9c0742d8a Binary files /dev/null and b/docs/en/Community-Articles/2026-08-06-tips-for-developers-new-to-abp-framework/abp-layers.png differ diff --git a/docs/en/Community-Articles/2026-08-06-tips-for-developers-new-to-abp-framework/abp-learning-path.png b/docs/en/Community-Articles/2026-08-06-tips-for-developers-new-to-abp-framework/abp-learning-path.png new file mode 100644 index 0000000000..6eec1b52f2 Binary files /dev/null and b/docs/en/Community-Articles/2026-08-06-tips-for-developers-new-to-abp-framework/abp-learning-path.png differ diff --git a/docs/en/Community-Articles/2026-08-06-tips-for-developers-new-to-abp-framework/cover.png b/docs/en/Community-Articles/2026-08-06-tips-for-developers-new-to-abp-framework/cover.png new file mode 100644 index 0000000000..85ea752b96 Binary files /dev/null and b/docs/en/Community-Articles/2026-08-06-tips-for-developers-new-to-abp-framework/cover.png differ diff --git a/docs/en/Community-Articles/2026-08-06-tips-for-developers-new-to-abp-framework/crud-vs-manual.png b/docs/en/Community-Articles/2026-08-06-tips-for-developers-new-to-abp-framework/crud-vs-manual.png new file mode 100644 index 0000000000..267dedea1a Binary files /dev/null and b/docs/en/Community-Articles/2026-08-06-tips-for-developers-new-to-abp-framework/crud-vs-manual.png differ diff --git a/docs/en/Community-Articles/2026-08-10-oss-sustainability-in-.net-commercialization-of-key/12m9D9rhnUDaiDElvNysSXw.png b/docs/en/Community-Articles/2026-08-10-oss-sustainability-in-.net-commercialization-of-key/12m9D9rhnUDaiDElvNysSXw.png new file mode 100644 index 0000000000..42e9188172 Binary files /dev/null and b/docs/en/Community-Articles/2026-08-10-oss-sustainability-in-.net-commercialization-of-key/12m9D9rhnUDaiDElvNysSXw.png differ diff --git a/docs/en/Community-Articles/2026-08-10-oss-sustainability-in-.net-commercialization-of-key/1479e3iBZ4il0F0tlpUQDYw.png b/docs/en/Community-Articles/2026-08-10-oss-sustainability-in-.net-commercialization-of-key/1479e3iBZ4il0F0tlpUQDYw.png new file mode 100644 index 0000000000..bbb19e327e Binary files /dev/null and b/docs/en/Community-Articles/2026-08-10-oss-sustainability-in-.net-commercialization-of-key/1479e3iBZ4il0F0tlpUQDYw.png differ diff --git a/docs/en/Community-Articles/2026-08-10-oss-sustainability-in-.net-commercialization-of-key/1EBeje4kIw0tQ4dGrI5i18A.png b/docs/en/Community-Articles/2026-08-10-oss-sustainability-in-.net-commercialization-of-key/1EBeje4kIw0tQ4dGrI5i18A.png new file mode 100644 index 0000000000..173e2fd966 Binary files /dev/null and b/docs/en/Community-Articles/2026-08-10-oss-sustainability-in-.net-commercialization-of-key/1EBeje4kIw0tQ4dGrI5i18A.png differ diff --git a/docs/en/Community-Articles/2026-08-10-oss-sustainability-in-.net-commercialization-of-key/1U_z6zDB8GIK2oVVTbKmslg.png b/docs/en/Community-Articles/2026-08-10-oss-sustainability-in-.net-commercialization-of-key/1U_z6zDB8GIK2oVVTbKmslg.png new file mode 100644 index 0000000000..917d49716f Binary files /dev/null and b/docs/en/Community-Articles/2026-08-10-oss-sustainability-in-.net-commercialization-of-key/1U_z6zDB8GIK2oVVTbKmslg.png differ diff --git a/docs/en/Community-Articles/2026-08-10-oss-sustainability-in-.net-commercialization-of-key/1YCRTIV3eHwgGvEOVlHBDCg.png b/docs/en/Community-Articles/2026-08-10-oss-sustainability-in-.net-commercialization-of-key/1YCRTIV3eHwgGvEOVlHBDCg.png new file mode 100644 index 0000000000..775a3519d6 Binary files /dev/null and b/docs/en/Community-Articles/2026-08-10-oss-sustainability-in-.net-commercialization-of-key/1YCRTIV3eHwgGvEOVlHBDCg.png differ diff --git a/docs/en/Community-Articles/2026-08-10-oss-sustainability-in-.net-commercialization-of-key/1Zz-6JQ0gzPq2AvN1_FjbtA.png b/docs/en/Community-Articles/2026-08-10-oss-sustainability-in-.net-commercialization-of-key/1Zz-6JQ0gzPq2AvN1_FjbtA.png new file mode 100644 index 0000000000..d88a3055b1 Binary files /dev/null and b/docs/en/Community-Articles/2026-08-10-oss-sustainability-in-.net-commercialization-of-key/1Zz-6JQ0gzPq2AvN1_FjbtA.png differ diff --git a/docs/en/Community-Articles/2026-08-10-oss-sustainability-in-.net-commercialization-of-key/1tKQUwPK70eQXvad1eiXoPA.png b/docs/en/Community-Articles/2026-08-10-oss-sustainability-in-.net-commercialization-of-key/1tKQUwPK70eQXvad1eiXoPA.png new file mode 100644 index 0000000000..aa020fe1b5 Binary files /dev/null and b/docs/en/Community-Articles/2026-08-10-oss-sustainability-in-.net-commercialization-of-key/1tKQUwPK70eQXvad1eiXoPA.png differ diff --git a/docs/en/Community-Articles/2026-08-10-oss-sustainability-in-.net-commercialization-of-key/Cover.png b/docs/en/Community-Articles/2026-08-10-oss-sustainability-in-.net-commercialization-of-key/Cover.png new file mode 100644 index 0000000000..7390a91856 Binary files /dev/null and b/docs/en/Community-Articles/2026-08-10-oss-sustainability-in-.net-commercialization-of-key/Cover.png differ diff --git a/docs/en/Community-Articles/2026-08-10-oss-sustainability-in-.net-commercialization-of-key/Post.md b/docs/en/Community-Articles/2026-08-10-oss-sustainability-in-.net-commercialization-of-key/Post.md new file mode 100644 index 0000000000..4381924b8e --- /dev/null +++ b/docs/en/Community-Articles/2026-08-10-oss-sustainability-in-.net-commercialization-of-key/Post.md @@ -0,0 +1,308 @@ +For years, many .NET teams treated core open source libraries as stable background infrastructure: useful, battle-tested, and effectively free forever. That assumption is starting to break. + +When widely used projects like IdentityServer, AutoMapper, and MediatR move toward commercial or more restrictive licensing, the discussion is no longer just about one package or one maintainer. It becomes a bigger question about how the .NET ecosystem pays for the software it depends on. + +This matters because modern .NET applications are built on layers of third-party dependencies. If one of those layers changes its pricing, support model, or license terms, the impact is not theoretical. It affects procurement, architecture, upgrade strategy, compliance, and long-term maintenance. + +## The pattern is no longer isolated + +A few years ago, licensing changes in .NET could still be dismissed as exceptions. That is getting harder. + +Several important projects now illustrate the same underlying tension: software that became critical infrastructure was often maintained with a funding model better suited to side projects than production-critical systems. + +## Duende IdentityServer is the clearest example + +The IdentityServer story is probably the most visible case in .NET. What started as a widely adopted open-source identity solution evolved into Duende IdentityServer, which requires paid licenses for production use, while free usage is limited to development, testing, personal projects, or qualifying community scenarios. + +More recently, Duende moved again with its v8 generation and introduced a more tiered licensing model, including Lite, Standard, Advanced, and Custom options, plus paid add-ons for additional capabilities. At the same time, support windows are clearly tied to .NET versions, making the product feel even more like managed commercial infrastructure than community software. + +> That is not necessarily a bad thing. Identity is security-critical software. It is expensive to maintain, expensive to support, and risky to underfund. But it does mark a major shift in expectations for teams that still think of it primarily as an OSS building block. + +## AutoMapper and MediatR point to a broader shift + +AutoMapper and MediatR are different kinds of libraries, but their direction matters just as much. + +These are not niche components. They are deeply embedded in enterprise codebases, tutorials, templates, and architectural conventions. So when they move toward dual licensing, commercial terms, or more restrictive licensing, the message is clear: **even highly popular and culturally central .NET libraries may no longer fit the old “free and permissive forever” model.** + +AutoMapper’s move away from .NET Foundation membership after adopting a non-permissive license is especially notable because it highlights a governance boundary. The ecosystem may celebrate OSS, but institutions such as the .NET Foundation still rely on clear licensing rules. Once a project changes those terms, it often changes its place in the ecosystem too. + +## Why maintainers are doing this + +The easy reaction is to call commercialization a betrayal. The more honest reaction is to admit that many maintainers have been subsidizing the industry for years. + +A project can be free for users and still very expensive for its authors. +Maintaining a popular library often means: + +![image-20260816151702299](image-20260816151702299.png) + +Once a library becomes critical infrastructure, users expect reliability similar to commercial software. But expectations usually rise faster than funding. + +That imbalance creates a predictable outcome: maintainers either burn out, slow down, seek sponsorship, or commercialize. + +--- + + + +## Open-source popularity does not automatically create sustainability + +This is the part many teams still underestimate. + +A package can have massive adoption and still be financially fragile. Downloads, GitHub stars, and conference mentions do not pay for maintenance. In fact, popularity often increases the burden without improving sustainability. + +From a maintainer’s perspective, commercialization can be a rational correction: + +- charge the organizations getting the most value +- fund long-term maintenance +- offer support contracts and SLAs +- justify time spent on roadmap work +- reduce dependence on unpaid labor + +### In other words, the move to commercial licensing is often less about greed than about replacing an unrealistic business model. + +--- + + + +## Why the community reaction is so mixed + +Even if the economics make sense, the backlash is real. And frankly, some of it is justified. + +The friction usually comes from the gap between legal reality and social expectation. + +### Legally, maintainers can often change how future versions are licensed. Socially, users feel that a trusted community dependency has changed the rules after becoming embedded in thousands of systems + +--- + + + +## What bothers teams most + +In practice, teams react to more than cost. They are reacting to uncertainty. +The common concerns are familiar: + +- unexpected licensing costs appearing in mature products +- fear of future pricing increases +- procurement delays for something developers previously installed with `dotnet add package` +- license compatibility and compliance reviews +- vendor lock-in around foundational infrastructure +- migration costs if a team decides to leave later +- concern that previously core features move behind paid tiers + +This is why the strongest reactions usually happen when the library is infrastructural rather than optional. Authentication, mapping, messaging, and mediator patterns sit close to the core of many architectures. **Replacing them is possible, but rarely cheap.** + +--- + + + +## Suddenness matters as much as pricing + +A reasonable commercial model can still create anger if the transition feels abrupt. Teams generally accept that maintainers need funding. What they do not accept as easily is: + +- vague roadmap communication +- surprise license changes +- unclear grandfathering rules +- unclear distinctions between old and new versions +- feature packaging that feels like a trap for existing users + +That trust dimension matters. In OSS, the license is not the whole relationship. Predictability is part of the product. + +--- + + + +## What this signals for the .NET ecosystem + +The larger lesson is not simply that some maintainers want to get paid. It is that the .NET ecosystem is maturing into one where critical libraries are increasingly treated like products, not just repositories. That has several consequences. + +## 1. Dependency selection is now a governance decision + +Choosing a package is no longer only a technical choice. + +Press enter or click to view image in full size + +![img](1U_z6zDB8GIK2oVVTbKmslg.png) + +This does not mean avoiding all commercially backed OSS. It means evaluating dependencies the same way you evaluate databases, cloud services, or authentication providers. + +## 2. Foundation membership and community trust will matter more + +When a project leaves a permissive governance environment, it sends a signal, even if the software remains technically strong. + +Press enter or click to view image in full size + +![img](12m9D9rhnUDaiDElvNysSXw.png) + +The .NET Foundation’s stance on permissive licensing creates a useful boundary here. It does not solve commercialization, but it helps clarify which projects still fit traditional OSS expectations. + +## 3. Forks and alternatives will become more common + +When licensing changes upset users, forks appear. That is a normal OSS response. + +Press enter or click to view image in full size + +![img](1Zz-6JQ0gzPq2AvN1_FjbtA.png) + +> A reactive fork may help teams buy time, but it does not automatically become sustainable infrastructure. + +In many cases, the fork inherits the same funding problem that triggered the original commercialization. + +--- + + + +## The practical risk for engineering teams + +The biggest mistake teams can make is treating this as community drama instead of delivery risk. + +Press enter or click to view image in full size + +![img](1EBeje4kIw0tQ4dGrI5i18A.png) + +This is especially relevant for organizations with long-lived internal platforms or multi-tenant SaaS products, where one dependency can affect dozens of services. + +--- + + + +## A realistic example + +Imagine a company running an internal platform and several customer-facing .NET applications. + +- **The identity layer uses IdentityServer.** +- **Multiple services use MediatR for application-layer orchestration.** +- **Older codebases rely heavily on AutoMapper profiles.** + +If all three become cost, licensing, or governance concerns at the same time, the company suddenly has a portfolio-level problem rather than a package-level problem. + +Press enter or click to view image in full size + +![img](1479e3iBZ4il0F0tlpUQDYw.png) + +That is architecture, budgeting, and compliance converging in one decision. + +## How teams should respond + +> Panic is not useful. Blind trust is not useful either. + +A better response is to become more deliberate about dependency management. + +--- + +## Build a dependency review habit + +For critical packages, review more than API quality. + +Press enter or click to view image in full size + +![img](1tKQUwPK70eQXvad1eiXoPA.png) + +If a package sits in authentication, authorization, persistence, messaging, or application architecture, the review should be stricter than for a small utility library. + +--- + + + +## Categorize dependencies by replacement cost + +Not every package deserves the same scrutiny. + +**A useful model is:** + +- low replacement cost: small utilities, isolated helpers +- medium replacement cost: libraries used across one bounded context +- high replacement cost: foundational cross-cutting libraries used everywhere + +Commercialization risk matters most in the third category. If replacing the library means touching every service, pipeline, or authentication flow, that risk belongs on the architecture radar early., + +--- + + + +## Budget for critical OSS + +Many companies are comfortable paying for cloud hosting but still resist paying for the libraries that shape their actual application architecture. + +That mindset is becoming outdated. + +If a dependency is business-critical, teams should assume one of these will eventually be required: + +Press enter or click to view image in full size + +![img](1YCRTIV3eHwgGvEOVlHBDCg.png) + +> You will pay somehow! +> The only real question is whether you pay proactively or reactively. + +--- + +## When to use commercially backed OSS and when not to ⛔ + +Commercialization is not automatically a reason to avoid a project. + +## ✔ WHEN TO USE IT + +**Commercially backed OSS can be a good fit when:** + +![image-20260816151255530](image-20260816151255530.png) + +Identity infrastructure is the obvious example. A mature, well-supported identity product may be worth paying for if the alternative is building and maintaining security-sensitive code yourself. + +--- + + + +## ⛔ WHEN NOT TO USE IT + +**Be cautious when:** + +![be-careful](image-20260816150848261.png) + +This is where some teams may rethink packages like object mappers or mediator frameworks. If the dependency is mostly ergonomic and the long-term governance risk is rising, simpler code may be the better tradeoff. + +--- + + + +## What this means for maintainers, companies, and the community + +The ecosystem now needs more honest expectations on all sides. + +## * For maintainers + +If your library underpins production systems, sustainability needs to be part of the strategy early. Commercialization is easier to accept when it is transparent, gradual, and communicated as part of a long-term model rather than a sudden pivot. + +## * For companies + +If your business depends on OSS, treating maintainers as an infinite free resource is no longer credible. Critical dependencies should have owners, budgets, and risk reviews. + +## * For the .NET community + +The community may need to become more selective about what it normalizes as default architecture. If a pattern depends heavily on a few centralized libraries, then a licensing change in one project can ripple widely. Simpler stacks are often more resilient. + +--- + + + +## A likely next phase for .NET OSS + +The next few years will probably bring more segmentation across the .NET ecosystem. + +Expect to see more of this: + +![image-20260816151051144](image-20260816151051144.png) + +That does not mean open source in .NET is weakening. It means the ecosystem is facing the same sustainability pressures seen elsewhere: maintenance is expensive, infrastructure software has real business value, and someone eventually has to fund it. + +The healthiest outcome is not pretending commercialization should never happen. It is making sure it happens with predictable governance, fair communication, and realistic expectations from users. + +--- + + + +## SUMMARY + +- Commercialization of key .NET libraries is a sustainability signal, not an isolated incident. +- Teams should evaluate dependencies by license, governance, support policy, and replacement cost. +- Commercial OSS can be the right choice for critical infrastructure, especially where support and security matter. +- The real risk is not paying for software; it is being surprised by cost, lock-in, or migration pressure too late. +- .NET teams should treat dependency strategy as an architectural and business decision, not just a NuGet decision. diff --git a/docs/en/Community-Articles/2026-08-10-oss-sustainability-in-.net-commercialization-of-key/image-20260816150848261.png b/docs/en/Community-Articles/2026-08-10-oss-sustainability-in-.net-commercialization-of-key/image-20260816150848261.png new file mode 100644 index 0000000000..191a3e1f83 Binary files /dev/null and b/docs/en/Community-Articles/2026-08-10-oss-sustainability-in-.net-commercialization-of-key/image-20260816150848261.png differ diff --git a/docs/en/Community-Articles/2026-08-10-oss-sustainability-in-.net-commercialization-of-key/image-20260816151051144.png b/docs/en/Community-Articles/2026-08-10-oss-sustainability-in-.net-commercialization-of-key/image-20260816151051144.png new file mode 100644 index 0000000000..0ee2770c7c Binary files /dev/null and b/docs/en/Community-Articles/2026-08-10-oss-sustainability-in-.net-commercialization-of-key/image-20260816151051144.png differ diff --git a/docs/en/Community-Articles/2026-08-10-oss-sustainability-in-.net-commercialization-of-key/image-20260816151255530.png b/docs/en/Community-Articles/2026-08-10-oss-sustainability-in-.net-commercialization-of-key/image-20260816151255530.png new file mode 100644 index 0000000000..19d4c49562 Binary files /dev/null and b/docs/en/Community-Articles/2026-08-10-oss-sustainability-in-.net-commercialization-of-key/image-20260816151255530.png differ diff --git a/docs/en/Community-Articles/2026-08-10-oss-sustainability-in-.net-commercialization-of-key/image-20260816151702299.png b/docs/en/Community-Articles/2026-08-10-oss-sustainability-in-.net-commercialization-of-key/image-20260816151702299.png new file mode 100644 index 0000000000..ba1b406c9c Binary files /dev/null and b/docs/en/Community-Articles/2026-08-10-oss-sustainability-in-.net-commercialization-of-key/image-20260816151702299.png differ diff --git a/docs/en/Community-Articles/2026-08-13-building-a-modular-monolith-with-abp-studio/Post.md b/docs/en/Community-Articles/2026-08-13-building-a-modular-monolith-with-abp-studio/Post.md new file mode 100644 index 0000000000..9aa3eb6e8c --- /dev/null +++ b/docs/en/Community-Articles/2026-08-13-building-a-modular-monolith-with-abp-studio/Post.md @@ -0,0 +1,601 @@ +Most monoliths do not fail because they are monoliths. They fail because they become tangled. + +That is exactly why the modular monolith is such a practical architecture for business applications. You keep the operational simplicity of a single deployment, but you organize the codebase around clear business boundaries. With ABP Studio, this approach is not an afterthought. It is built into the way you create and evolve a solution. + +In this article, I will walk through how to build a modular monolith with ABP Studio, how ABP modules fit together, where teams usually get the boundaries wrong, and how to structure your solution so it stays maintainable as it grows. + +If you are building a line-of-business app and want something more disciplined than a traditional monolith, but less expensive than microservices, this is one of the strongest options in the .NET ecosystem. + +## Why a modular monolith fits many real projects + +A modular monolith gives you: + +- one deployable application +- one main runtime host +- clear module boundaries by business capability +- the option to evolve selected modules later +- less distributed systems overhead than microservices + +That trade-off matters in real teams. Most products do not need network boundaries on day one. They need: + +- faster delivery +- simpler debugging +- less infrastructure +- a codebase that does not collapse after six months + +ABP Framework is designed around modularity. A module in ABP can own its own: + +- domain model +- application services +- database integration +- API endpoints +- UI pieces +- tests + +That makes ABP a natural fit for modular monolith architecture rather than a framework you have to bend into shape. + +## What ABP Studio creates for a modular monolith + +When you choose the Modular Monolith option in ABP Studio's New Solution Wizard, ABP creates a solution structure intended for a modern modular application. + +At a high level, you typically get: + +- `main/` for the main host application +- `modules/` for business modules +- `etc/` for shared infrastructure and configuration assets + +This is a useful default because it separates the host from the business capabilities from the start. + +A simplified layout looks like this: + +```text +src/ + main/ + MyCompany.MyProduct.Web + MyCompany.MyProduct.HttpApi.Host + modules/ + Catalog/ + MyCompany.MyProduct.Catalog.Domain + MyCompany.MyProduct.Catalog.Application + MyCompany.MyProduct.Catalog.EntityFrameworkCore + MyCompany.MyProduct.Catalog.HttpApi + MyCompany.MyProduct.Catalog.Web + Ordering/ + MyCompany.MyProduct.Ordering.Domain + MyCompany.MyProduct.Ordering.Application + MyCompany.MyProduct.Ordering.EntityFrameworkCore + MyCompany.MyProduct.Ordering.HttpApi + MyCompany.MyProduct.Ordering.Web +etc/ + docker/ + k8s/ + configs/ +``` + +The exact projects depend on your choices, but the important idea is consistent: the host app lives in `main`, and business capabilities live under `modules`. + +ABP Studio also lets you choose modules up front or add them later. That is important because most teams do not know their final module map on day one. You can start with a few strong boundaries and evolve from there. + + + +![Generated illustration](inline-1.png) + +## Understanding ABP modules in practice + +In ABP, modules are first-class building blocks. They are not just folders. + +A module typically declares dependencies using attributes such as `DependsOn`, which tells ABP how pieces should be initialized and wired together. + +A minimal example looks like this: + +```csharp +using Volo.Abp.Modularity; + +[DependsOn( + typeof(AbpDddDomainModule) +)] +public class CatalogDomainModule : AbpModule +{ +} +``` + +That may look small, but it is central to the architecture. Dependencies are explicit, and the framework uses those module relationships during startup. + +In practical terms, this gives you: + +- a consistent module lifecycle +- explicit compile-time references +- less hidden coupling +- clearer ownership boundaries + +ABP also distinguishes between framework modules and your application modules. + +- Framework modules provide infrastructure features like validation, caching, permission management, and persistence integration. +- Application modules represent your business capabilities like Catalog, Ordering, Billing, or Support. + +Structurally, they are similar. The difference is their role in the system. + +## A practical module structure that scales + +One of the most useful ABP practices is layered modules. Instead of throwing everything into a single project, you separate concerns inside each module. + +A common structure is: + +- Domain +- Application +- Infrastructure or provider-specific persistence +- HttpApi +- Web or UI +- Tests + +For example, a Catalog module may look like this: + +### Domain + +This is where business rules live: + +- entities +- value objects +- domain services +- domain events +- repository interfaces + +Keep this layer focused on business behavior, not framework plumbing. + +### Application + +This layer orchestrates use cases: + +- application services +- DTOs +- authorization checks +- transaction boundaries +- coordination across domain objects + +This is usually where external callers interact with the module. + +### EntityFrameworkCore or MongoDB + +This layer handles persistence details: + +- DbContext or Mongo collections +- repository implementations +- mappings +- migrations where relevant + +ABP supports different providers, and a module can include the provider projects it actually needs. + +### HttpApi + +This exposes the module over HTTP when needed: + +- controllers +- remote service contracts +- serialization-related setup + +### Web + +If your solution includes server-side or MVC-style UI integration, this is where UI pieces for the module can live. + +### Tests + +A solid module usually has separate tests for: + +- domain logic +- application logic +- persistence integration + +For EF Core, in-memory SQLite is a practical option for provider-level tests. For MongoDB, ephemeral test instances are a common approach. + +## Step-by-step: creating a modular monolith with ABP Studio + +The tooling matters because architecture tends to decay when it is inconvenient. ABP Studio reduces that friction. + +A practical setup flow looks like this. + +### 1. Create the solution with the Modular Monolith template + +In ABP Studio: + +- create a new solution +- choose the Modular Monolith template +- select your UI and database preferences +- decide which business modules you want to include initially + +This gives you the host app under `main` and a `modules` area for business capabilities. + +### 2. Start with business boundaries, not technical layers + +Before adding modules, identify your real capabilities. Good early candidates are usually things like: + +- Catalog +- Ordering +- Inventory +- Customer Management +- Billing + +Bad module boundaries are usually technical buckets like: + +- Utilities +- Common Business Logic +- Shared Services + +Those become dumping grounds fast. + +A simple rule helps: if a module name would make sense to a product owner, it is probably closer to the right boundary. + +### 3. Add modules incrementally + +You do not need to model the whole enterprise on day one. + +Start with two or three meaningful modules. For example: + +- Catalog manages products and pricing rules +- Ordering manages carts, orders, and order state +- Identity handles users and permissions via ABP's existing modules + +This is enough to validate your architecture without over-designing it. + +### 4. Keep each module independently understandable + +A developer should be able to open `modules/Catalog` and understand: + +- what the module owns +- what it exposes publicly +- what it depends on +- how it is tested + +If the module constantly reaches into another module's internals, the boundary is already weak. + +### 5. Wire modules through explicit dependencies + +ABP's module system encourages declaring dependencies up front. + +For example, an application layer may depend on its own domain layer and some framework modules: + +```csharp +[DependsOn( + typeof(CatalogDomainModule), + typeof(AbpDddApplicationModule) +)] +public class CatalogApplicationModule : AbpModule +{ +} +``` + +This is much healthier than hidden runtime coupling or random service lookups scattered across the codebase. + + + +![Generated illustration](inline-2.png) + +## How modules should communicate + +This is where many modular monoliths either stay clean or slowly become a distributed mess inside one process. + +In ABP, module communication generally falls into two categories: + +- synchronous communication through interfaces or public application services +- asynchronous communication through events + +Both are useful. The mistake is using one for everything. + +### Option 1: synchronous calls for direct business workflows + +Use direct service calls when: + +- one module needs an immediate answer +- the workflow is naturally request-response +- the dependency is acceptable and explicit + +Example: + +- Ordering needs to verify product availability from Catalog before creating an order line. + +In that case, a clear application service contract is often the simplest solution. + +Benefits: + +- easy to trace +- easier to debug +- strong flow control +- fewer hidden side effects + +Costs: + +- tighter coupling between modules +- dependency direction must be managed carefully + +### Option 2: events for decoupled reactions + +Use events when: + +- a module publishes something that others may react to +- the publisher should not know all consumers +- eventual consistency is acceptable + +Example: + +- Ordering publishes `OrderPlaced` +- Inventory reserves stock +- Billing starts invoicing +- Notifications sends a confirmation + +Benefits: + +- lower direct coupling +- easier to add new consumers later +- better long-term separation + +Costs: + +- debugging is harder +- side effects are less obvious +- too many events can create implicit dependencies + +A good default is simple: + +- use direct calls for core request-response flows +- use events for reactions and cross-cutting side effects + +## An example module interaction design + +Imagine a small commerce system with Catalog and Ordering modules. + +### Catalog owns + +- products +- product pricing +- availability rules + +### Ordering owns + +- carts +- orders +- order state transitions + +A clean interaction might look like this: + +1. A user places an order through Ordering. +2. Ordering calls a public Catalog service to validate selected products. +3. Ordering creates the order in its own domain. +4. Ordering publishes an order-created event. +5. Other modules react as needed. + +Notice what does not happen: + +- Ordering does not directly query Catalog tables. +- Catalog does not modify Ordering aggregates. +- Shared internal entities are not passed around freely. + +That discipline matters more than the fact that everything runs in one process. + +## Database design in a modular monolith + +A modular monolith does not force a single database strategy. + +With ABP, you can support: + +- a shared database for the whole application +- separate schemas per module +- module-specific databases in some cases + +For most teams, the best starting point is a single database with clear ownership boundaries in code. + +Why this is usually the right default: + +- simpler operations +- easier local development +- straightforward transactions +- less infrastructure overhead + +But even with one database, treat data ownership seriously. + +That means: + +- each module owns its own tables and mappings +- cross-module table access is avoided +- modules interact through services or events, not direct persistence shortcuts + +If you later decide to extract a module into a separate service, this discipline will matter far more than whether you started with one database or three. + + + +![Generated illustration](inline-3.png) + +## When to use layered modules and when not to overdo them + +ABP encourages a layered structure because it scales well, but you should still apply judgment. + +### Use layered modules when + +- the module has real business complexity +- multiple developers will work on it +- you want clear separation between domain, use cases, and persistence +- the module may grow into a reusable building block + +### Do not over-layer when + +- the module is tiny and stable +- the behavior is simple CRUD with little business logic +- extra projects would create more ceremony than clarity + +There is no prize for turning a 300-line feature into six projects. + +A useful practical rule: + +- start simple, but not sloppy +- add more structure when the module earns it + +ABP makes layered modules easy, but that does not mean every feature deserves the full treatment immediately. + +## Testing strategy for a modular monolith + +Modular architecture only pays off if modules can be tested with confidence. + +A practical testing setup includes: + +### Domain tests + +Use these for pure business rules: + +- invariants +- state transitions +- validation rules +- domain service behavior + +These should be fast and framework-light. + +### Application tests + +Use these for use cases: + +- application service behavior +- authorization checks +- DTO mapping expectations +- orchestration across domain objects + +### Persistence tests + +Use these for provider-specific concerns: + +- EF Core mappings +- repository behavior +- query correctness +- migration-related assumptions + +In ABP-based solutions, this usually means separate test projects per layer or concern. That keeps failures localized and makes refactoring safer. + +## Common mistakes that break modular monoliths + +The architecture is solid, but the failure modes are predictable. + +### 1. Fake modules with real coupling + +This is the most common problem. Teams create module folders, but the code still behaves like one giant application. + +Symptoms: + +- modules reference each other's internals +- shared entities leak everywhere +- services depend on concrete implementations across modules +- repositories are used across boundaries + +If that is happening, you have namespaces, not modules. + +### 2. A shared project that becomes a dumping ground + +Be very careful with anything named: + +- Common +- Shared +- Core +- Utilities + +Some shared infrastructure is fine. Shared business logic is often a sign that boundaries are unclear. + +Prefer: + +- duplicated tiny code over premature shared abstractions +- explicit module contracts over giant common libraries + +### 3. Overusing events + +Events are powerful, but they can hide the system's real behavior. + +If every use case fires multiple events that trigger more events, debugging becomes painful. + +Use events deliberately for decoupled reactions, not as a replacement for clear application flows. + +### 4. Choosing module boundaries by org chart or UI screens + +A screen is not necessarily a module. Neither is a department name. + +Choose boundaries based on business capability and ownership of rules and data. + +### 5. Ignoring future extraction concerns entirely + +You do not need to design for microservices from day one, but you should avoid decisions that make extraction impossible later. + +Examples: + +- direct table joins across module boundaries +- exposing internal entities everywhere +- no public contracts between modules + +ABP's modular style helps here, but only if you actually respect it. + +## Modular monolith vs microservices in ABP + +ABP supports both styles, which makes the comparison especially relevant. + +### Choose a modular monolith when + +- your team is small to medium-sized +- you want fast delivery with lower ops cost +- business boundaries exist, but independent deployment is not yet needed +- you want a cleaner architecture than a traditional monolith + +### Choose microservices when + +- modules must be deployed independently +- scaling characteristics differ sharply by capability +- organizational ownership is strongly separated +- you can absorb the cost of distributed systems complexity + +### When NOT to use a modular monolith + +Do not use it if you already know that: + +- teams need full autonomy over deployment cadence +- strict runtime isolation is required +- independent data ownership must be enforced operationally from the start + +For many products, a modular monolith is the better first architecture because it preserves optionality. You can grow into more distribution later instead of paying for it before you need it. + +## A practical path for future extraction + +One of the best reasons to build a modular monolith with ABP is that the module shape is already compatible with a more distributed future. + +That does not mean extraction is free. It never is. But you can make it realistic. + +To keep that option open: + +- keep public contracts narrow +- avoid direct database coupling across modules +- communicate through application services and events +- keep module-specific logic inside the module +- treat each module as owning its own data and rules + +If one day Ordering needs to become its own service, the work becomes an architectural transition instead of a rescue mission. + +## Recommended approach for a first real project + +If I were starting a new ABP Studio solution today, I would keep it practical. + +I would: + +- create a modular monolith solution in ABP Studio +- start with 2 to 4 meaningful business modules +- use layered modules only where the complexity justifies it +- default to a single database +- enforce module boundaries in code review +- use direct service calls first, events second +- add tests per module from the beginning + +I would avoid: + +- designing ten modules before shipping one feature +- building a giant shared library +- using events for every interaction +- leaking persistence details across modules + +That balance is usually what keeps the architecture alive after the first few sprints. + +## TL;DR + +- ABP Studio makes modular monolith architecture practical by separating the host app in `main` and business capabilities in `modules`. +- ABP modules should own their domain, application logic, persistence, APIs, and tests with explicit dependencies. +- Keep module communication intentional: direct calls for request-response flows, events for decoupled reactions. +- Start with a single deployment and usually a single database, but protect boundaries as if extraction may happen later. +- The biggest risk is not the monolith itself; it is weak module boundaries that turn the codebase back into a big ball of mud. \ No newline at end of file diff --git a/docs/en/Community-Articles/2026-08-13-building-a-modular-monolith-with-abp-studio/cover.png b/docs/en/Community-Articles/2026-08-13-building-a-modular-monolith-with-abp-studio/cover.png new file mode 100644 index 0000000000..c1e45d9a62 Binary files /dev/null and b/docs/en/Community-Articles/2026-08-13-building-a-modular-monolith-with-abp-studio/cover.png differ diff --git a/docs/en/Community-Articles/2026-08-13-building-a-modular-monolith-with-abp-studio/inline-1.png b/docs/en/Community-Articles/2026-08-13-building-a-modular-monolith-with-abp-studio/inline-1.png new file mode 100644 index 0000000000..41ae0ba03a Binary files /dev/null and b/docs/en/Community-Articles/2026-08-13-building-a-modular-monolith-with-abp-studio/inline-1.png differ diff --git a/docs/en/Community-Articles/2026-08-13-building-a-modular-monolith-with-abp-studio/inline-2.png b/docs/en/Community-Articles/2026-08-13-building-a-modular-monolith-with-abp-studio/inline-2.png new file mode 100644 index 0000000000..08e0631110 Binary files /dev/null and b/docs/en/Community-Articles/2026-08-13-building-a-modular-monolith-with-abp-studio/inline-2.png differ diff --git a/docs/en/Community-Articles/2026-08-13-building-a-modular-monolith-with-abp-studio/inline-3.png b/docs/en/Community-Articles/2026-08-13-building-a-modular-monolith-with-abp-studio/inline-3.png new file mode 100644 index 0000000000..cb7fd8fcdb Binary files /dev/null and b/docs/en/Community-Articles/2026-08-13-building-a-modular-monolith-with-abp-studio/inline-3.png differ diff --git a/docs/en/Community-Articles/2026-09-02-abp-studio-vs-aspire-ai-ides-and-crud-generators/ABP-Studio-vs-Alternatives-Cover.png b/docs/en/Community-Articles/2026-09-02-abp-studio-vs-aspire-ai-ides-and-crud-generators/ABP-Studio-vs-Alternatives-Cover.png new file mode 100644 index 0000000000..31b01f6dfd Binary files /dev/null and b/docs/en/Community-Articles/2026-09-02-abp-studio-vs-aspire-ai-ides-and-crud-generators/ABP-Studio-vs-Alternatives-Cover.png differ diff --git a/docs/en/Community-Articles/2026-09-02-abp-studio-vs-aspire-ai-ides-and-crud-generators/ABP-Studio-vs-Alternatives-Inline.png b/docs/en/Community-Articles/2026-09-02-abp-studio-vs-aspire-ai-ides-and-crud-generators/ABP-Studio-vs-Alternatives-Inline.png new file mode 100644 index 0000000000..9ce893732f Binary files /dev/null and b/docs/en/Community-Articles/2026-09-02-abp-studio-vs-aspire-ai-ides-and-crud-generators/ABP-Studio-vs-Alternatives-Inline.png differ diff --git a/docs/en/Community-Articles/2026-09-02-abp-studio-vs-aspire-ai-ides-and-crud-generators/Post.md b/docs/en/Community-Articles/2026-09-02-abp-studio-vs-aspire-ai-ides-and-crud-generators/Post.md new file mode 100644 index 0000000000..2c6fa77354 --- /dev/null +++ b/docs/en/Community-Articles/2026-09-02-abp-studio-vs-aspire-ai-ides-and-crud-generators/Post.md @@ -0,0 +1,163 @@ +You already have an IDE. You might already have Aspire. You might already have Cursor. The remaining question is how those tools handle ABP solution structure, modules, run profiles, and generated application code. + +Teams compare [ABP Studio](https://abp.io/studio) with three neighbors. This is not an “IDE replacement” debate. + +1. .NET Aspire, for describing distributed resources as code and watching them on a dashboard. +2. Generic AI IDEs (Cursor, GitHub Copilot, Claude Code), for repo-wide chat and file edits. +3. CRUD scaffolders, such as `dotnet aspnet-codegenerator` and visual Blazor builders (for example Radzen). + +Those tools are good. Keep Visual Studio, Rider, or VS Code. Studio can [open the solution in them](https://abp.io/docs/latest/studio/solution-explorer). This article is about what the ABP workflow brings together in one environment: templates, module graph, Solution Runner (Studio’s tool for starting, stopping, and inspecting applications), the ABP Agent, and [ABP Suite](https://abp.io/suite) (including React). + +## TL;DR + +Choose ABP Studio when the work is ABP: solution shape, module graph, Solution Runner, AI Agent, and Suite CRUD (including React on modern solutions). + +Keep Visual Studio, Rider, or VS Code beside it for refactor, tests, and language services. + +Add .NET Aspire when you want resource-as-code and the Aspire dashboard. Studio does not forbid it; microservice templates can wire Aspire in. + +Use a generic AI IDE as an extra editor if the team already lives there. Prefer the ABP Agent when the change needs modules, migrations, proxies, or live run telemetry. + +Tables in this article follow [official ABP documentation](https://abp.io/docs/latest). + +## If the bottleneck is ABP, not the C# file + +Studio may be a suitable choice when your team is (or will be) on the ABP Platform and you want one place to: + +- Scaffold production templates (including React Modern and Classic MVC / Blazor / Angular). +- Run many services, containers, and UIs from a [Solution Runner](https://abp.io/docs/latest/studio/running-applications) profile (the set of applications and services started together). +- Ask, plan, and implement with AI against modules, packages, migrations, and live telemetry. +- Generate layered CRUD with ABP Suite for MVC, Blazor, Angular, and React. + +If you only need a general editor, keep using your IDE. If you only need container orchestration and OpenTelemetry locally, Aspire may already be on the machine. Add Studio when the solution graph and ABP conventions are the bottleneck, not the C# file. + +## What actually sits next to Studio + +| Capability | ABP Studio + Agent | .NET Aspire | General AI IDEs (Cursor, Copilot, Claude Code, …) | Visual Studio / Rider / VS Code | +|---|---|---|---|---| +| Role | ABP solution lifecycle + AI coding in context | Cloud-native orchestration, service discovery, dashboard | Repo-wide AI edit / chat / agents | General-purpose IDE | +| ABP / DDD structure in context | Solution, modules, packages, run profiles in the [agent system context](https://abp.io/docs/latest/studio/ai-agent) | Unaware of ABP modules | Files and text; no ABP module graph | Solution explorer of projects, not ABP modules | +| ABP-shaped artifacts | Suite generates entity, app service, DTOs, repository, and UI; Agent follows those module conventions | No | Generic C# unless you prompt every ABP convention | Language services only | +| Production ABP templates | Layered, modular, microservice; Modern React or Classic UIs | Minimal host templates for Aspire | None | `dotnet new` / ABP CLI if you add it | +| Run + monitor | [Solution Runner](https://abp.io/docs/latest/studio/running-applications): start/stop apps and containers, HTTP requests, exceptions, logs, events, browse UI | Aspire dashboard: resources, logs, traces, metrics | Shell / terminal processes | Multi-project debug | +| AI that can build, migrate, generate proxies | Agent mode: files, shell, [Studio tools](https://abp.io/docs/latest/studio/ai-agent-built-in-capabilities) (`dotnet_build`, `start_applications`, `generate_csharp_proxies`, `get_exceptions`, …), MCP | Not an ABP coding agent | Shell-wrapped `dotnet` if you teach it | Copilot in the editor (generic) | +| Kubernetes | Studio Kubernetes integration for ABP solutions | Publish / deploy story for Aspire apps | No | No (unless you add tools) | +| Code edit / refactor | Agent writes code; Open with your IDE for deep refactor | Not an editor | Strong | Strongest language tooling | +| Use together? | Yes, open IDE from Studio; optional Aspire integration | Yes with ABP microservice template | Yes as an extra editor | Yes; Studio launches them | + +How to read the table: these tools stack. Studio does not replace Rider's refactorings or Aspire's resource model. Its differentiated value is the ABP-aware workflow across solution structure, modules, run profiles, and agent tools. + +Kubernetes. Studio’s Kubernetes integration is for developing against a cluster (browse and health using service names from the run profile). It is not Helm, GitOps, or your production deploy pipeline. + +## The ABP Agent vs “just ask Cursor” + +![Generic AI IDE and ABP Agent: repository context and ABP Studio context](ABP-Studio-vs-Alternatives-Inline.png) + +Cursor and Copilot are excellent at finishing a LINQ query or explaining a regex. That is not the argument. + +Ask a generic AI IDE: "Add a Product entity, make it multi-tenant, add the EF Core migration, generate the React UI." A generic AI IDE can work effectively when it has sufficient repository context and explicit project conventions. ABP Studio's differentiated value is that solution, module, run-profile, and telemetry context are available through first-class Studio capabilities. For cross-layer ABP changes, this can reduce the amount of context and manual coordination the developer must provide. + +[ABP Studio AI Agent](https://abp.io/docs/latest/studio/ai-agent) is not limited to the currently open text buffer. The session can use the solution, modules, packages, runnable apps, run profile, AI scope, and enabled tools. [ABP Suite](https://abp.io/suite) remains the CRUD generator, while the Agent is designed to work with the module graph, add a migration, start the profile, and inspect live exceptions. + +Modes: + +- Ask, read-only answers. Can search ABP documentation. +- Plan, read-only implementation plans. +- Agent, read/write files, shell, add migrations, run Studio tools, MCP, update plan steps. + +The ABP Agent fits changes where module, solution, and runtime context should remain available throughout the work. + +That is the difference versus a generic AI IDE: + +| What you ask | ABP Agent | Generic AI IDE | +|---|---|---| +| “Add an app service following ABP layering” | Receives solution, module, and ABP documentation context through Studio | Works from the repository context and instructions provided to it | +| “Why did this HTTP call fail?” | `get_requests` / `get_exceptions` / `get_logs` on the running profile | You paste a log or attach a debugger | +| “Generate C# / Angular proxies” | First-class Studio tools | A shell command if the model guesses it | +| “Start the apps, then continue” | `start_applications` / `start_containers` | Terminal + wait | +| Scope | AI scopes limit which modules the agent may touch; `.abpignore` blocks secrets | Works from the repository context and instructions provided to it | + +You still review the diff. Agent mode is execution with a permission boundary, not unsupervised production deploys. + +The [privacy boundary](https://abp.io/docs/latest/studio/ai-agent) is the session you give it: files, prompts, Studio tool output, attachments, and allowed URLs. Privacy depends on the selected model, configured provider, accessible scope, and enabled tools. [`.abpignore`](https://abp.io/docs/latest/studio/ai-agent-configuration) prevents excluded files from entering the agent context. + +## Why Aspire does not replace Studio (they stack) + +[Solution Runner](https://abp.io/docs/latest/studio/running-applications) is how you run an ABP modular or microservice tree: profiles per team, folders for apps/gateways/services, C# hosts, CLI tasks (for example Angular), Docker containers, start/stop/build, browse, health, and live HTTP / exception / log / event views. + +.NET Aspire is how many .NET teams describe distributed resources as code and watch them on a dashboard (OpenTelemetry, containers, connection strings). + +Their responsibilities overlap around local orchestration, but their primary scopes are different. Aspire focuses on distributed resource orchestration, while ABP Studio adds ABP solution templates, module workflows, Suite, and the ABP Agent. + +You do not have to pick one. ABP microservice templates can enable Aspire so AppHost starts infrastructure and services; you can still use Studio’s runner and Agent. See [Aspire integration](https://abp.io/docs/latest/solution-templates/microservice/aspire-integration). + +Pairing ABP Studio with Aspire works well when ABP solution workflows and distributed resource orchestration are both needed. + +## Suite: a CRUD slice, not a pretty grid + +[ABP Suite](https://abp.io/docs/latest/suite) generates a CRUD slice of an ABP application from an entity: domain type, repository, application service, migration, UI, tests, navigation properties, multi-tenant flag, localization keys. + +| | ABP Suite | `dotnet aspnet-codegenerator` / EF scaffolding | Visual Blazor app builders (for example Radzen) | +|---|---|---|---| +| Output | Entity through application layer + UI + optional tests | Controllers, Razor Pages, Blazor CRUD, or Minimal API endpoints against a DbContext | Blazor UI + data wiring from a database or REST source | +| UI stacks | MVC, Blazor (Blazorise or MudBlazor, detected), Angular, and React (modern solutions) | MVC views, Razor Pages, and Blazor components. No Angular. No React. | Blazor only (Server, WebAssembly, Auto) | +| ABP permissions, tenancy, audit base classes | Options on the entity ([CRUD generation](https://abp.io/docs/latest/suite/generating-crud-page)) | Does not use ABP permission and tenancy conventions | Does not use ABP permission and tenancy conventions | +| Custom code on regenerate | Customizable code [hook points](https://abp.io/docs/latest/suite/customizing-the-generated-code) for MVC, Blazor, and Angular; React pages require extra care when regenerated | Often requires manually preserving custom changes | Varies by product | +| React UI | Yes, template-based CRUD for modern React apps, including search, paging, validation, permissions, localization, and navigation properties. Registers routes and menu | No React generator in the official scaffolding set (`blazor`, `razorpage`, `view`, `controller`, `identity`, `minimalapi`) | Blazor-focused rather than React-based | + +Suite supports the official web UI stacks, including React. [ABP Agent](https://abp.io/docs/latest/studio/ai-agent) is an extra path when you want AI to evolve those pages, not a substitute for Suite React output. + +Suite is a fit when generated CRUD should follow the application's ABP layers, conventions, and selected UI stack. + +## When Studio is the right tool in the stack + +Choose ABP Studio when the work is ABP: new solution shape, module graph, run profiles, Kubernetes-connected browse, Agent that can migrate and generate proxies, Suite for CRUD. + +Keep your IDE open beside it for refactor, tests, and language services. Studio expects that. + +Add Aspire when you want resource-as-code and the Aspire dashboard. Studio does not forbid it. + +Use a generic AI IDE as an extra editor if your team already lives there. Prefer Agent for ABP-structured changes so the model is not guessing module boundaries from filenames. + +Studio works best when ABP-specific solution workflows complement your existing IDE. + +## FAQ + +### We already run .NET Aspire (AppHost + dashboard). What does Studio still do that Aspire does not? +Aspire models resources (projects, containers, connection strings, OpenTelemetry) as code. Studio models an ABP solution: modules, package installation, production templates, Suite, Kubernetes browse for ABP services, and an agent that can migrate and generate proxies. Their responsibilities overlap around local orchestration, but their primary scopes are different. You can keep AppHost; microservice templates can integrate Aspire. You do not need to replace Aspire with Studio. + +### If the team already uses Cursor or Copilot on the same repo, when is ABP Agent the better tool for a task? +When the task needs ABP structure or a live run, not only a file edit: module/package scope, `generate_csharp_proxies` / `generate_angular_proxies`, `start_applications`, or `get_exceptions` / `get_requests` / `get_logs` against the [Solution Runner](https://abp.io/docs/latest/studio/running-applications) profile. Generic IDEs can work in the same repository when given the relevant context and conventions. Agent provides first-class access to module, run-profile, and Studio tool context for changes that coordinate ABP modules and running services. + +### After Suite generates React CRUD, how should we customize the page? +For MVC, Blazor, and Angular, use Suite’s [customizable code](https://abp.io/docs/latest/suite/customizing-the-generated-code) hook points. React pages require extra care when regenerated, so keep additional React UI in files Suite does not generate or evolve it with [ABP Agent](https://abp.io/docs/latest/studio/ai-agent). Suite React generation itself is template-based, not AI. + +### Can Agent start the microservice profile, then use real HTTP/exception data in the same session? +Yes, in Agent mode with a run profile: tools include `start_applications` / `start_containers` and then `get_requests`, `get_exceptions`, `get_logs`, `get_events` ([built-in capabilities](https://abp.io/docs/latest/studio/ai-agent-built-in-capabilities)). Ask/Plan cannot mutate or start apps. If nothing is running, those telemetry tools have nothing to read. That is why “AI that sees production-like local traffic” is a Studio and Runner loop, not a chat sidebar. + +### Does Studio Kubernetes integration replace Helm, GitOps, or our cluster deploy pipeline? +No. It is for developing against a cluster (browse/health using Kubernetes service names from the run profile, manage connected services). Aspire’s publish story and your CI remain how you ship. Do not treat the Studio K8s panel as the production deployment product. + +### Can one developer live in Rider and another in VS Code while sharing the same Studio solution? +Yes. Studio holds solution/run-profile metadata; [Open with](https://abp.io/docs/latest/studio/solution-explorer) launches whatever IDE is installed. Run profiles and Agent sessions are not tied to a single editor vendor. The constraint is ABP Studio itself on the machine, not a mandate to abandon Rider or VS. + +## Next step + +[Download ABP Studio](https://abp.io/studio) · [AI Agent docs](https://abp.io/docs/latest/studio/ai-agent) · [Generate a CRUD page](https://abp.io/docs/latest/suite/generating-crud-page) · [ABP Framework](https://abp.io/framework) + +### Sources + +- [ABP Studio overview](https://abp.io/docs/latest/studio) +- [AI Agent](https://abp.io/docs/latest/studio/ai-agent) +- [AI Agent built-in capabilities](https://abp.io/docs/latest/studio/ai-agent-built-in-capabilities) +- [Solution Runner](https://abp.io/docs/latest/studio/running-applications) +- [Solution Explorer / Open with IDE](https://abp.io/docs/latest/studio/solution-explorer) +- [ABP Suite](https://abp.io/docs/latest/suite) +- [Generating a CRUD page](https://abp.io/docs/latest/suite/generating-crud-page) +- [Customizing the generated code](https://abp.io/docs/latest/suite/customizing-the-generated-code) +- [ASP.NET Core `aspnet-codegenerator`](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/tools/dotnet-aspnet-codegenerator) +- [.NET Aspire overview](https://learn.microsoft.com/en-us/dotnet/aspire/get-started/aspire-overview) +- [Radzen Blazor Studio](https://www.radzen.com/blazor-studio/) +- [Microservice Aspire integration](https://abp.io/docs/latest/solution-templates/microservice/aspire-integration) + +Product names in this article belong to their owners. Mention is for identification in a technical comparison, not affiliation or endorsement. diff --git a/docs/en/Community-Articles/2026-09-02-abp-vs-clean-architecture-templates-and-starter-kits/ABP-vs-Alternatives-Cover.png b/docs/en/Community-Articles/2026-09-02-abp-vs-clean-architecture-templates-and-starter-kits/ABP-vs-Alternatives-Cover.png new file mode 100644 index 0000000000..0ccad75e69 Binary files /dev/null and b/docs/en/Community-Articles/2026-09-02-abp-vs-clean-architecture-templates-and-starter-kits/ABP-vs-Alternatives-Cover.png differ diff --git a/docs/en/Community-Articles/2026-09-02-abp-vs-clean-architecture-templates-and-starter-kits/ABP-vs-Alternatives-Inline.png b/docs/en/Community-Articles/2026-09-02-abp-vs-clean-architecture-templates-and-starter-kits/ABP-vs-Alternatives-Inline.png new file mode 100644 index 0000000000..e4f5ec2667 Binary files /dev/null and b/docs/en/Community-Articles/2026-09-02-abp-vs-clean-architecture-templates-and-starter-kits/ABP-vs-Alternatives-Inline.png differ diff --git a/docs/en/Community-Articles/2026-09-02-abp-vs-clean-architecture-templates-and-starter-kits/Post.md b/docs/en/Community-Articles/2026-09-02-abp-vs-clean-architecture-templates-and-starter-kits/Post.md new file mode 100644 index 0000000000..93afbb03a7 --- /dev/null +++ b/docs/en/Community-Articles/2026-09-02-abp-vs-clean-architecture-templates-and-starter-kits/Post.md @@ -0,0 +1,223 @@ +Every serious .NET team hits the same whiteboard sooner or later. Do we build the multi-tenant SaaS from scratch? Grab a starter kit? Adopt a platform? + +Search “ABP vs …” and you will land on pages written by kits and tenancy libraries. Fair. Those pages exist because the question is real. They are not comparing two products of the same kind. + +You are choosing among four shapes: + +1. Build it yourself on ASP.NET Core, often with a tenancy library such as Finbuckle.MultiTenant. +2. A Clean Architecture template (Jason Taylor, Ardalis) that gives you folders, layers, and a sample feature. +3. A starter kit that copies a snapshot of production modules into your repo (fullstackhero, Brick, and similar kits). +4. A maintained application platform. Architecture, infrastructure, modules, and tools that keep moving. + +ABP competes across several decision categories rather than against one uniform product set. Some teams compare it with Clean Architecture and DDD references or starter kits because they prefer to own and assemble the application foundation themselves. Others evaluate .NET application and service frameworks such as ServiceStack, model-driven RAD platforms such as DevExpress XAF, or cross-stack SaaS platforms and starter kits. Existing ASP.NET Boilerplate applications are usually a migration and adoption consideration rather than a same-generation alternative. The table below focuses on the architecture and application-foundation decision; these other categories can still enter the same broader technology discussion. + +[ABP](https://abp.io) takes the application-platform approach. The rest of this article is about the things teams evaluate later: multi-tenancy, identity, permissions, modularity, UI (including React), and a path from modular monolith (one deployable application organized into independent modules) to microservices. + +## TL;DR + +Choose ABP when you are shipping a long-lived, multi-tenant, modular .NET product and want a maintained platform: tenancy, identity, modules, official UIs (including React), and Studio / Suite on the same stack. + +Choose a Clean Architecture template (Jason Taylor, Ardalis) when the goal is to own every architectural decision from a well-named skeleton. + +Choose a starter kit (fullstackhero, Brick, and similar) when you prefer a copy of modules in your repo on day one and you are willing to maintain that snapshot. + +Choose Finbuckle (or custom tenant middleware) when tenant resolution is the only additional capability you need on an app you already own. ABP also connects tenancy with application concerns such as identity, permissions, and audit. + +Tables in this article follow [official ABP documentation](https://abp.io/docs/latest). + +## This is for the long haul + +ABP is the recommended choice when you are building a long-lived, multi-tenant, modular .NET product. B2B SaaS. Line of business. A platform several teams will still be extending in a few years. + +You want: + +- Cross-cutting concerns (auth, tenancy, audit, jobs, localization) already solved and documented. +- Official UI options that match your team: React, Angular, Blazor, MVC, MAUI, or React Native. +- A way to add pre-built modules and, later, split a module into a service without rewriting the application code. +- Tooling (Studio, Suite, CLI) and, if you need it, commercial modules and support, without leaving the same platform. + +Yes, ABP is opinionated. The initial learning cost is real: teams need to understand modules, application services, and unit of work conventions before those conventions become productive. Then, when a module needs to become a microservice, the contracts are already there. The conventions become team-wide standards so the next project does not invent a second way to do the same thing. + +## Four shapes. One table. + +![DIY ASP.NET Core, Clean Architecture, starter kit, and ABP Platform as four different shapes](ABP-vs-Alternatives-Inline.png) + +| Capability | ABP Platform | DIY ASP.NET Core | Clean Architecture templates (Jason Taylor, Ardalis) | Starter kits (fullstackhero, Brick, and similar) | +|---|---|---|---|---| +| What you get | Maintained framework + modules + templates + tooling | Empty host and libraries you assemble | Layered/CQRS skeleton + a sample feature | A copy of modules in your repo on day one | +| Multi-tenancy | Native: [single database, database-per-tenant, or hybrid](https://abp.io/docs/latest/framework/architecture/multi-tenancy); identity and authentication/token infrastructure wired for tenants | You design isolation, filters, and cache keys, or add a library such as Finbuckle.MultiTenant | Not included | Often via a tenancy library you still own end-to-end | +| Identity, permissions, audit | Application modules + automatic tenant-data filtering, [audit logging](https://abp.io/docs/latest/framework/infrastructure/audit-logging), permission system | You compose Identity, policies, and audit yourself | Identity sample at most | Bundled in the kit; you maintain the fork | +| Modularity | First-class [module system](https://abp.io/docs/latest/framework/architecture/modularity/basics); install/uninstall packages | You invent module boundaries | Folders and layers, not a product module catalog | Modular folders; upgrades are merge/cherry-pick | +| UI | [React (Modern)](https://abp.io/docs/latest/framework/ui/react), MVC, Blazor, Angular, [React Native](https://abp.io/docs/latest/framework/ui/react-native), [MAUI](https://abp.io/docs/latest/framework/ui/maui) | You pick and integrate | Template-specific (often Angular/React/API) | Kit-specific (often one SPA) | +| Monolith → microservices | Same application contracts; HTTP/C# proxies replace in-process calls | You design the split | You design the split | Extract-a-module if the kit allows it | +| Tooling | [ABP Studio](https://abp.io/studio) (including AI Agent), [ABP Suite](https://abp.io/suite), CLI | `dotnet` CLI and your IDE | Template CLI + IDE | Kit CLI / Aspire host, varies | +| How it evolves | NuGet upgrades for the framework and modules, plus documented migrations | You upgrade every library | You copy the next template over your tree | You merge upstream into source you already customized | +| Support | Open-source core plus commercial extras and vendor support | Your team | Community | Community | + +ABP may be a suitable fit when the application needs architecture, infrastructure modules, and development tooling to remain integrated and maintainable as the product grows. + +How to read the table: templates teach structure. Starter kits give you a snapshot you own. ABP combines application architecture, infrastructure modules, and development tooling in one platform. Names in the headers are examples of the category, not a review of every repository. + +Identity, permissions, and audit. ABP ships these as application modules: permission UI, automatic filtering of tenant data, and audit logging. On plain ASP.NET Core you compose Identity, policies, and audit yourself. A Clean Architecture template usually stops at an Identity sample. A starter kit may bundle them; you then maintain that copy. + +How the stack evolves. When a customized starter kit is updated, identity and tenancy code may already contain local changes. Reconciling those changes across the files you now own can add significant maintenance work. That is a different upgrade model from updating framework packages. + +ABP uses framework and module packages, together with documented migrations. A Clean Architecture template’s next version is something you copy forward. A kit’s next version is reconciled with the snapshot you already changed. + +## Let’s be honest: what are you actually downloading? + +### What you build yourself + +ASP.NET Core is phenomenal. It is a foundation, not a complete application platform. Building from scratch gives teams maximum control, but also leaves tenant resolution, permission checks, audit logs, job plumbing, and module boundaries to the team. + +That work is legitimate if the architecture is unique. For a standard business product, it is infrastructure before the first domain feature. + +ABP sits on ASP.NET Core. You keep the Microsoft stack. ABP provides established conventions and modules for teams that prefer those decisions to be part of the platform. See [Why ABP Platform](https://abp.io/docs/latest/others/why-abp-platform). + +ABP suits teams that want application infrastructure to remain integrated with the product as it grows. + +### Clean Architecture templates + +This category includes the templates most often compared with ABP: Jason Taylor’s Clean Architecture template and Ardalis’s Clean Architecture template. They provide a good classroom and a clean slate. Their focus is architectural structure and ownership rather than a built-in application module catalog or ABP-specific tooling. + +Choose a Clean Architecture template when architectural ownership and a focused starting point matter most. + +ABP is a fit when architectural conventions and application modules need to evolve together. + +### Starter kits + +A starter kit copies identity, tenancy, auditing, and a few domain modules into your repository. You own every line. That is a real preference for some teams. + +Starter kits are another common option in this decision. fullstackhero is a copy-and-own MIT kit (identity, tenancy, React admin, modules in your repo). Other starter kits, such as Brick, can also provide a prebuilt starting point; the exact features, ownership model, and update process depend on the kit. They can provide a fast starting point, but long-term maintenance depends on how each kit handles updates to customized code. + +With ABP, framework and module updates are distributed through packages and documented migrations. With a kit, teams have direct ownership of the source, while updates may require reconciling local changes with upstream code. These are different maintenance models. + +Choose a starter kit when an existing set of application features and direct source ownership can accelerate your team. + +Choose ABP when you want those application concerns, modules, and tooling to evolve as part of a maintained platform. ABP’s open-source core is yours to use; your business code lives in your repo. There is no separate proprietary runtime for that core. Commercial extras (themes, Pro modules, Suite, support) are optional layers on the same platform, not a rewrite. + +Package-based framework and module updates may suit teams that prefer them to reconciling changes in an owned source snapshot. + +## If you last looked a year ago: React is official + +This is easy to miss if you last looked at ABP a year ago. + +Official UI options ([ABP UI](https://abp.io/docs/latest/framework/ui)): + +- React, in the [Modern template system](https://abp.io/docs/latest/solution-templates/modern-vs-classic) (ABP Studio or `abp new --modern`). +- MVC / Razor Pages, Blazor (WebAssembly, Server, WebApp), and Angular, on Classic templates. +- React Native and MAUI for mobile / hybrid. + +[Modern vs Classic](https://abp.io/docs/latest/solution-templates/modern-vs-classic): Classic is not a deprecated track. It is the actively supported family with the broadest UI matrix (MVC, Angular, Blazor, MAUI) and the template-first Studio flow. Modern is the newer architecture-first Studio flow, React (or no UI), and the Admin Console / Low-Code path (metadata-driven screens configured through a designer). Choose Classic when the team’s UI is MVC, Angular, or Blazor. Choose Modern when the web UI is React. + +One backend, the UI your team already knows. + +## Multi-tenancy without a side project + +ABP treats tenancy as infrastructure, not a feature you bolt on: + +- Current tenant is resolved per request. +- Entities implementing `IMultiTenant` (ABP’s contract for separating tenant-owned data) are automatically filtered; new records get a `TenantId` identifying the tenant. +- You can use one database for all tenants, one database per tenant, or a hybrid. + +That isolation also applies to cache and related concerns so business code stays mostly tenancy-agnostic. Details: [Multi-Tenancy](https://abp.io/docs/latest/framework/architecture/multi-tenancy). + +A tenancy library on raw ASP.NET Core, including Finbuckle.MultiTenant, can resolve the tenant. It does not automatically give you permission UI, audit, jobs, Identity/OpenIddict authentication and token wiring for tenants, and module installs on the same model. That is the platform difference. Pages titled “Finbuckle vs ABP vs custom” are answering a library question. This article is answering the application-platform question. + +ABP is worth considering when tenancy needs to stay connected to identity, permissions, data filtering, and the rest of the application model. + +## Modularity that can become microservices + +ABP modules are real packages (domain, application, HTTP API, UI) with documented dependency rules. You can start with a [modular monolith](https://abp.io/architecture/modular-monolith) and later replace in-process calls with HTTP using the same application service contracts and [client proxies](https://abp.io/docs/latest/framework/api-development/dynamic-csharp-clients) (typed clients that call application services over HTTP). + +That path is the point. You do not throw away the monolith to “do microservices”; you change the hosting of a module that already had a boundary. + +This approach fits teams that want modular boundaries to support both a modular monolith and a later service split. + +## ABP Low-Code: admin screens inside the same app + +[ABP Low-Code](https://abp.io/docs/latest/low-code) is a module in your ABP application (Team license or higher). You model entities, pages, forms, permissions, and scripts in the Admin Console. The runtime uses that metadata in the same app, with the same identity, audit, and EF Core model. There is no separate low-code database. + +Designer, [Studio AI Agent](https://abp.io/docs/latest/studio/ai-agent), and hand-written C# / Script API land on one model. + +The documented runtime UI is React. You can still keep MVC, Razor Pages, Angular, or Blazor as the main UI and host the React Low-Code runtime beside it ([non-React integration](https://abp.io/docs/latest/low-code/non-react-ui-integration)). + +Docs still label the system Preview (APIs and designer may change before GA). That is a maturity label, not a missing product. + +| | ABP Low-Code | External low-code platform | Hand-written CRUD every time | +|---|---|---|---| +| Where it runs | Inside your ABP app | Separate product / runtime | Your repo | +| Data and identity | Same database and ABP authorization | Often a parallel model | Whatever you build | +| Extend with code | C#, Script API, Agent | Platform limits | Always code | +| Screens | Grid, form, calendar, kanban, gallery, dashboard, import/export | Vendor widgets | Custom pages | +| How you enable it | Studio modern wizard (layered, single-layer, modular monolith + EF Core) or [add to an existing EF Core solution](https://abp.io/docs/latest/low-code/add-to-existing-solution) | Vendor onboarding | Always code | + +Studio’s *new-solution wizard step* is omitted for microservice architecture and when MongoDB is selected, because runtime-managed tables use EF Core. Layered and modular-monolith EF Core solutions are the documented enablement path today. + +Use Low-Code for the admin CRUD and metadata-driven screens. Keep distinctive product UX in normal ABP UI, including Suite-generated React CRUD on modern solutions. + +## When this is the right call + +Pick ABP when: + +- The product will have tenants, roles, audit, and more than one team. +- You want React *or* Blazor *or* Angular *or* MVC on a shared backend. +- You expect to grow from modular monolith to services without a rewrite. +- You want Studio, Suite, and (optionally) Low-Code on the same stack. + +A Clean Architecture template is a solid choice when architectural ownership and a focused starting point matter most. + +A starter kit is a solid choice when an existing set of application features and direct source ownership can accelerate your team. ABP is a better fit when those application concerns, modules, and tooling should evolve as part of a maintained platform. + +ASP.NET Boilerplate is the predecessor, not a same-generation starter kit. If that is the comparison, it is a migration to the current ABP platform, not a fork-and-own kit decision. + +DevExpress XAF and similar commercial frameworks follow a model-driven RAD approach built around a vendor UI ecosystem. That approach can reduce application boilerplate and accelerate internal business applications, while also placing the application’s model and much of its UI experience within DevExpress conventions and controls. ABP is an application platform on ASP.NET Core, with an open-source core, modular architecture, and multiple UI options. It gives teams more direct control over the application layers and frontend choices, including MVC, Blazor, Angular, and React, while supporting a modular-monolith-to-microservices path. XAF may be the better fit when the priority is delivering a model-driven business application quickly within the DevExpress ecosystem. ABP may be the better fit when the product needs ASP.NET Core, a more customized frontend experience, multiple client options, or a modular architecture that can evolve toward services. + +## FAQ + +### Is ABP free or commercial? +ABP Framework has an open-source core. Some themes, modules, generators, Studio capabilities, support, and other commercial offerings require an appropriate commercial license. Exact availability depends on the product and license level. + +### If we stop paying for commercial extras, or we leave ABP later, is the app a black box? +No. The application is still ASP.NET Core, your C#, and EF Core (or MongoDB). The [open-source framework](https://abp.io/docs/latest/others/why-abp-platform) stays in the solution as packages you already reference. Leaving ABP means replacing those packages the way you would replace any framework, not extracting code from a closed runtime. Suite output is source in your repo. Commercial modules, themes, and Suite itself are optional layers; dropping them does not delete your domain. + +### If we already have a Clean Architecture or starter-kit repo (Jason Taylor, Ardalis, fullstackhero, Brick), can we “just add ABP” like a NuGet? +No. ABP’s module pipeline, interceptors, automatic tenant-data filters (which limit queries to the current tenant), and startup conventions assume it is the host. Teams adopt ABP on a new solution (or plan a migration), they do not drop `Volo.Abp.*` onto an existing CA template and keep the old composition root unchanged. That is the real cost versus a tenancy library you add to code you already own. See [Why ABP Platform](https://abp.io/docs/latest/others/why-abp-platform). + +### We already use Finbuckle (or custom tenant middleware). What does ABP tenancy still do that that library does not? +A tenancy library resolves *who the tenant is*. ABP also isolates queries and inserts (`IMultiTenant` data filters), wires Identity and OpenIddict for tenants, and applies the same tenant context to cache and related infrastructure. That covers [single database, database-per-tenant, or hybrid](https://abp.io/docs/latest/framework/architecture/multi-tenancy). Permissions, audit, and jobs then run inside that model instead of each being a separate integration project. + +### If we start Modern/React, can the same backend later serve a second UI (public MVC, partner Blazor, mobile)? +Yes. Application services and HTTP APIs are UI-agnostic. [Official UIs](https://abp.io/docs/latest/framework/ui) (React, Angular, Blazor, MVC, React Native, MAUI) are hosts on that backend. You choose Modern vs Classic at solution creation for the primary web app; extra clients consume the same APIs. You do not rewrite domain or application layers to add a second frontend. + +### When we split a module into a microservice, do we rewrite application services as controllers? +Not as the default path. Module contracts stay; in-process calls become HTTP (or messaging) via [client proxies](https://abp.io/docs/latest/framework/api-development/dynamic-csharp-clients) against the same application-service interfaces. You change hosting, not the feature’s application API. That is the comparison point versus a starter kit whose “modules” are folders with no proxy story. + +### For the same admin entity, should we use Suite-generated React CRUD or Low-Code pages? +[Suite](https://abp.io/docs/latest/suite) writes source into your layers (entity, app service, UI, tests) that you commit and customize, including React on modern solutions. [Low-Code](https://abp.io/docs/latest/low-code) keeps the entity in metadata (designer + runtime APIs/pages) without generating those classes for the standard flow. Use Suite when the screen will grow into product code; use Low-Code when the screen should stay designer-driven. They are not substitutes for each other. + +### Can we keep MediatR / vertical-slice handlers for new features inside an ABP solution? +You can reference extra libraries, but ABP’s default application surface is [application services](https://abp.io/docs/latest/framework/architecture/domain-driven-design/application-services) with unit of work, validation, and authorization conventions. Comparison with CA templates is not “MediatR vs nothing”; it is whether the team standardizes on ABP’s application layer or on a handler-per-feature folder as the public API. Mixing both without a rule usually duplicates the same use case in two styles. + +## Next step + +Create a solution in [ABP Studio](https://abp.io/studio) and pick Modern (React) or Classic (MVC / Blazor / Angular). Then add only the modules you need. + +[Create a free ABP solution](https://abp.io/studio) · [Read the framework overview](https://abp.io/framework) · [Why ABP Platform](https://abp.io/docs/latest/others/why-abp-platform) + +### Sources + +- [ABP UI options](https://abp.io/docs/latest/framework/ui) +- [Modern vs Classic templates](https://abp.io/docs/latest/solution-templates/modern-vs-classic) +- [React UI](https://abp.io/docs/latest/framework/ui/react) +- [Multi-tenancy](https://abp.io/docs/latest/framework/architecture/multi-tenancy) +- [Why ABP Platform](https://abp.io/docs/latest/others/why-abp-platform) +- [Low-Code System](https://abp.io/docs/latest/low-code) +- [Jason Taylor Clean Architecture template](https://github.com/jasontaylordev/CleanArchitecture) +- [Ardalis Clean Architecture template](https://github.com/ardalis/CleanArchitecture) +- [fullstackhero starter kit](https://github.com/fullstackhero/dotnet-starter-kit) +- [Finbuckle.MultiTenant documentation](https://www.finbuckle.com/MultiTenant/Docs) +- [ServiceStack documentation](https://docs.servicestack.net/why-servicestack) +- [DevExpress XAF overview](https://www.devexpress.com/products/net/application_framework/) + +Product names in this article belong to their owners. Mention is for identification in a technical comparison, not affiliation or endorsement. diff --git a/docs/en/Community-Articles/2026-09-06-How-to-Present-Your-Project-To-Your-Mother/Cover.png b/docs/en/Community-Articles/2026-09-06-How-to-Present-Your-Project-To-Your-Mother/Cover.png new file mode 100644 index 0000000000..b9e13e4e9f Binary files /dev/null and b/docs/en/Community-Articles/2026-09-06-How-to-Present-Your-Project-To-Your-Mother/Cover.png differ diff --git a/docs/en/Community-Articles/2026-09-06-How-to-Present-Your-Project-To-Your-Mother/Post.md b/docs/en/Community-Articles/2026-09-06-How-to-Present-Your-Project-To-Your-Mother/Post.md new file mode 100644 index 0000000000..9517661b73 --- /dev/null +++ b/docs/en/Community-Articles/2026-09-06-How-to-Present-Your-Project-To-Your-Mother/Post.md @@ -0,0 +1,177 @@ +# How to Present Your .NET Project To Your Mother? + +**I'm writing this article while camping in the middle of the forest 🌲⛺.** I came here to get away from computers for a while... but apparently, I'm still thinking about software and how we explain it to people. You can see me in the cover image 😄 + +![image-20260906225734694](image-20260906225734694.png) + +Hey there! I'm Alper, giving international conference talks and mostly I don't know the audience demography (knowledge level/position/tech stack etc...). And I need to be very careful how I present my talk. Recently I've been studying on this topic. My audience is mostly developers or IT guys. And when I explain a technical topic to those people, I'm very comfortable 🤠🤠 But, sometimes we need to explain what we do (our project) to our friends, mother or child. In other words; anyone who is not technical. Then things are getting a little bit different and harder 🤯 + +To have a strong technical knowledge does not automatically make someone a good communicator. +For scientists, engineers, developers and technical leaders, the real challenge is not knowing the subject 👉 **deciding what the audience needs to know and how to make it meaningful for them.** + +Empathy is very important in all our life steps. I wrote an article about [empathy in workspace](https://abp.io/community/articles/empathy-in-the-workplace-for-software-companies-wsjjw9we), please read it when you have time because it's also important for this topic. Imagine you are explaining your .NET project to an investor or customer, concepts which you use in your project might be simple for you, but feel that empathy (please) for a moment, **does that guy understand what you mean**? Before starting your presentation collect information about him so that you can adjust your sentences according to him. + +> AND TELL HIM ONLY WHAT WORKS FOR HIM. + +No need to tell how the algorithm behind this project works! Tell him why it's good for him. From now on, when I tell "him/his" I mean the customer / investor / friend / father / son / non-IT guy. + + + +--- + +## Don't Focus Too Much on the Details + +We are all good software engineers and we want to show the art behind that work 👏 That's absolutely natural feeling 👍 +We all want to show people the details how our project work because we are proud of it and that's a bad practise!! +Too much detail will definitely hide your main message!!! You are consuming his energy, focus and time with all those details. +So what happens, your main goal is not being transferred to him 🤔..💭...🥺 + +![image-20260906212829582](image-20260906212829582.png) + +Ok we know the problem, now how will you fix this? SIIMMPLEE: Before mentioning a topic, ask yourself: + +> Does he need this info to understand my idea or make his decision? + +If not, please save it for yourself and don't mention about that. +Maybe later, if he's very much interested in you can explain him (IF ONLY he asks 😄) + + + +--- + +## Don't Make It Too Simple Also *-- are you kidding me!* + +Well! Don't be angry 😡 at me. In the previous section I said *don't go in details* and now I'm telling **do not explain too simple** 🙃 +While we are trying to not make it too complicated or detailed, we shouldn't make it inaccurate or treating the listener as idiot🐑 + +Keep the science and technical meaning balanced. Let's reduce unnecessary software jargons. Use clear language, examples and familiar concepts when you explain something complex. +**My technique is using analogies**, especially for my projects I often give a car example which is as simple as everybody can easily understand (*even my kid understands it*). + +> MAKE IT SIMPLE, but NOT OVER-SIMPLE! + + + +--- + +## Start With Why It Matters + +In Turkey, there are some street sellers... They stop you and say "Can I tell you something?". Actually I know he's a seller and probably he'll redirect me to a barber, cosmetic store or some shops which are upper floors in a passage. And I mostly say "NO!" and I'm walking my way... But imagine if he tells me first which benefit I'll get from what he sells, maybe I'll go to his shop. (*this paragraph is also explaining my topic in a simple way which I explained in the previous section so I'm still using these techniques in this article* 🤫) + +![image-20260906212109817](image-20260906212109817.png) + +One of the most common mistakes in technical presentations is starting with the technology itself. + +> Our project runs the Dijkstra algorithm with the multi-tenant and DDD architecture 🧑‍🔬 + +The above sentence doesn't mean anything to him. Tell it like this: + +> Our project finds the shortest path efficiently, you can have many isolated customers with clean design and long years maintainable way.” + +When people understand why your project matters, they'll have a reason to listen the next sections. + +So far, so good 💯 You did a good job reading until here 🙏 ᵗʰᵃᶰᵏᵧₒᵤ ... Keep reading please ...👀...👇 + + +--- + +## Think About What You Want Him to Remember + +Your audience will not remember many technical points after your presentation. +**They will remember 1-2 topics.** +Decide what those points are 🎯 then build the presentation around them. +Everything else must support those core messages. + + + + +--- + +## Your Voice Tone Matters Too! + +Imagine you did everything 👏 very good until here... but you are talking very monotonous way. Or you are talking quickly. Sorry, that's also not a good talk! **Your emphasis, eye contact, body language, tone of voice are all important.** You can make small jokes to give him a relaxing break to understand your complex technical work. + +> COMMUNICATION IS NOT ONLY ABOUT WHAT YOU SAY but also HOW YOU SAY IT 🗣 + +Watch the📹 [ShadeZahrai -very short- tiktok video](https://www.tiktok.com/@shadezahrai/video/7177549216464571650) + +![image-20260906210745253](image-20260906210745253.png) + + +--- + +## Use Images to Make Your Subject Clear + +Especially when you are presenting on slides, you should show some funny images related to your topic or you can show analogic images that explains the problem. +For example to tell about a risky case which you covered in your project, you can use the below image :) +Yes, people will laugh at first but later they'll listen to you more carefully because you took their attention. (*I created another paradox here, I’m explaining this topic using a funny related image and I know you’re now reading my article more carefully*🤝) + +![image-20260906201600152](image-20260906201600152.png) + + +--- + + + +## How to Handle Questions? 😡 Especially Which You Don't Like + +![image-20260906202807792](image-20260906202807792.png) + +In technical presentations, people can ask aggressive or stupid questions or you may not like their questions 😡 +Don't immediately try to defend yourself by giving more and more technical details. Or don't try to show them it's a silly question. +If you don't know, tell it honestly. If that feature doesn't exist, tell that you took note and you'll evaluate it later. +Even if it’s a stupid question, don’t shut him down. **Later, he will remember only that moment and all your efforts you’ve made will be lost.** + + + + +--- + +## Your Goal Is To Be Understandable 🫱🏽‍🫲🏻 Not Showing Everything You Know + +Anddd again, we come back to empathy! + +> The best technical explainer is not the person who gives the most information. + +![image-20260906204302915](image-20260906204302915-1788717035148-1.png) + +Okay, you know a lot and you want to show that. But try to be empathetic again. Giving someone all the technical details doesn't mean they will understand your point. **Good communication means sharing what matters in a way people can easily understand.** + +> Don't tell people everything you know. Tell them what they need to know and please make sure they understand it. + + + +--- + +## Explaining Something and Convincing Someone Are Not the Same 🙄 + +Providing accurate & correct information and persuading someone to take action are different. +But in business life, **technical presentations often need to do both**. +You need to explain how something works and also helping management approve a project. + +YOU CAN USE THIS PATH WHEN PRESENTING YOUR PROJECT: + +![image-20260906203343446](image-20260906203343446.png) + +--- + +I appreciate you taking the time to read this article 🙏. +I like to share what I learn which is the main reason I wrote this article. +By applying these techniques, we can become better presenters and communicate our ideas more effectively 👌. +When we combine our technical strengths with strong soft skills, I believe we can make a greater impact, inspire others and grow together 🙌💪. + + + +--- + +Alper Ebicoglu + +Software architect since the early 2000s. +Learning, inspiring, sharing, talking... + +||| +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | [linkedin.com/in/ebicoglu](https://www.linkedin.com/in/ebicoglu/) | +| | [x.com/alperebicoglu](https://x.com/alperebicoglu) | +| | [alperonline.medium.com](https://alperonline.medium.com) | +| | [github.com/ebicoglu](https://github.com/ebicoglu) | + diff --git a/docs/en/Community-Articles/2026-09-06-How-to-Present-Your-Project-To-Your-Mother/image-20260906201600152.png b/docs/en/Community-Articles/2026-09-06-How-to-Present-Your-Project-To-Your-Mother/image-20260906201600152.png new file mode 100644 index 0000000000..7cc2c3bddc Binary files /dev/null and b/docs/en/Community-Articles/2026-09-06-How-to-Present-Your-Project-To-Your-Mother/image-20260906201600152.png differ diff --git a/docs/en/Community-Articles/2026-09-06-How-to-Present-Your-Project-To-Your-Mother/image-20260906202807792.png b/docs/en/Community-Articles/2026-09-06-How-to-Present-Your-Project-To-Your-Mother/image-20260906202807792.png new file mode 100644 index 0000000000..5e9b0c352b Binary files /dev/null and b/docs/en/Community-Articles/2026-09-06-How-to-Present-Your-Project-To-Your-Mother/image-20260906202807792.png differ diff --git a/docs/en/Community-Articles/2026-09-06-How-to-Present-Your-Project-To-Your-Mother/image-20260906203343446.png b/docs/en/Community-Articles/2026-09-06-How-to-Present-Your-Project-To-Your-Mother/image-20260906203343446.png new file mode 100644 index 0000000000..581d8b3967 Binary files /dev/null and b/docs/en/Community-Articles/2026-09-06-How-to-Present-Your-Project-To-Your-Mother/image-20260906203343446.png differ diff --git a/docs/en/Community-Articles/2026-09-06-How-to-Present-Your-Project-To-Your-Mother/image-20260906204302915-1788717035148-1.png b/docs/en/Community-Articles/2026-09-06-How-to-Present-Your-Project-To-Your-Mother/image-20260906204302915-1788717035148-1.png new file mode 100644 index 0000000000..d05bfebe6b Binary files /dev/null and b/docs/en/Community-Articles/2026-09-06-How-to-Present-Your-Project-To-Your-Mother/image-20260906204302915-1788717035148-1.png differ diff --git a/docs/en/Community-Articles/2026-09-06-How-to-Present-Your-Project-To-Your-Mother/image-20260906210745253.png b/docs/en/Community-Articles/2026-09-06-How-to-Present-Your-Project-To-Your-Mother/image-20260906210745253.png new file mode 100644 index 0000000000..db5d1ef512 Binary files /dev/null and b/docs/en/Community-Articles/2026-09-06-How-to-Present-Your-Project-To-Your-Mother/image-20260906210745253.png differ diff --git a/docs/en/Community-Articles/2026-09-06-How-to-Present-Your-Project-To-Your-Mother/image-20260906212109817.png b/docs/en/Community-Articles/2026-09-06-How-to-Present-Your-Project-To-Your-Mother/image-20260906212109817.png new file mode 100644 index 0000000000..d993848029 Binary files /dev/null and b/docs/en/Community-Articles/2026-09-06-How-to-Present-Your-Project-To-Your-Mother/image-20260906212109817.png differ diff --git a/docs/en/Community-Articles/2026-09-06-How-to-Present-Your-Project-To-Your-Mother/image-20260906212829582.png b/docs/en/Community-Articles/2026-09-06-How-to-Present-Your-Project-To-Your-Mother/image-20260906212829582.png new file mode 100644 index 0000000000..45340db0bd Binary files /dev/null and b/docs/en/Community-Articles/2026-09-06-How-to-Present-Your-Project-To-Your-Mother/image-20260906212829582.png differ diff --git a/docs/en/Community-Articles/2026-09-06-How-to-Present-Your-Project-To-Your-Mother/image-20260906225734694.png b/docs/en/Community-Articles/2026-09-06-How-to-Present-Your-Project-To-Your-Mother/image-20260906225734694.png new file mode 100644 index 0000000000..ae2a31cec5 Binary files /dev/null and b/docs/en/Community-Articles/2026-09-06-How-to-Present-Your-Project-To-Your-Mother/image-20260906225734694.png differ diff --git a/docs/en/Community-Articles/2026-09-14-ABP-Studio-AI-Agent-Bring-Your-Own-Key/Post.md b/docs/en/Community-Articles/2026-09-14-ABP-Studio-AI-Agent-Bring-Your-Own-Key/Post.md new file mode 100644 index 0000000000..5ade83b84f --- /dev/null +++ b/docs/en/Community-Articles/2026-09-14-ABP-Studio-AI-Agent-Bring-Your-Own-Key/Post.md @@ -0,0 +1,137 @@ +# BYOK: Use Your Own AI Models in ABP Studio + +ABP Agent already lives inside ABP Studio and understands your solution: modules, permissions, DbContexts, run profiles, migrations, proxies, and runtime logs. Until now, it talked to models through **Built-in AI**; the catalog that comes with your ABP AI Credits. No API keys, no extra setup. + +That is still the default, and it is still the fastest way to start. + +Enterprise teams often cannot stop there. They already have an approved OpenAI, Azure OpenAI, or company gateway. They run Ollama on a developer machine. Their security policy says prompts and code context must stay on a private endpoint. They do not want a second AI bill on top of the one they already pay. + +That is what **AI connection** is for. In **Settings → Models**, you choose one source for the assistant: + +- **Built-in AI** ;models included with your ABP AI Credits. No API key required. +- **Provider connections** ;your own OpenAI-compatible service or Ollama, with your own keys (or no key at all for a local server). + +Pick one. The agent then uses that connection for chat, tools, and the model picker at the bottom of the ABP Agent panel. + +![AI connection in ABP Studio Settings](ai-connection-settings.png) + +## Who can use this? + +Using ABP Agent with **Built-in AI** is available on paid Studio editions where AI is enabled. + +**Provider connections (bring your own LLM) is Enterprise-only.** Team, Business, Personal, Trial, and Community cannot activate it. + +| License Type | Bring Your Own Key: Your own OpenAI / Ollama | +|---|---| +| Community | ❌ No | +| Team | ❌ No | +| Business | ❌ No | +| **Enterprise** | ✔ **Yes** | + +On a Team (or any non-Enterprise) license, the Models page still shows Provider connections, but the option is locked. Clicking **Upgrade** opens the Enterprise upsell. If someone already saved a custom profile and later drops off Enterprise, Studio switches the active connection back to Built-in AI. Saved profiles are kept; they just cannot be the active connection until Enterprise is available again. + +--- + +## How To Switch To The Bring Your Own Key Models + +1. Open **File → Settings**. +2. Select **Models**. +3. Under **AI connection**, choose **Built-in AI** or **Provider connections**. + +If you stay on Built-in AI, tick the models you want under **Included models**. Those are exactly the models offered in the chat picker. If the picker is empty, nothing is ticked here. + +--- + +## Which LLMs can you use with Built-in AI? + +Built-in AI does not require your own API keys. Studio loads a **live catalog** of coding-capable models, billed through **ABP AI Credits**. Use **Search models...**, the **Category** dropdown, and **Refresh models** to browse it. + +![Included models catalog and Category filter](included-models-catalog.png) + +Only a subset is ticked by default. Anything you tick here appears in the chat model picker. Models that fail coding-agent checks (too-small context, no tool support, expired, or over the price cap) are hidden. + +### Shipped defaults + +A fresh Built-in AI install pre-selects these models. **Claude Sonnet 5** is the default main model; **Claude Haiku 4.5** is the default for research, browser, and lightweight text processing. + +| Model | Provider | Typical use | +|---|---|---| +| Claude Sonnet 5 | Anthropic | Default main model for Ask, Plan, and Agent | +| Claude Opus 5 | Anthropic | Stronger reasoning and careful review | +| Claude Fable 5 | Anthropic | Additional Claude 5-family option | +| Claude Haiku 4.5 | Anthropic | Fast research, docs search, and text processing | +| GPT-5.6 Sol | OpenAI | Strong GPT option for main or review work | +| GPT-5.6 Terra | OpenAI | Strong GPT option for main or review work | +| GPT-5.6 Luna | OpenAI | Strong GPT option for main or review work | +| GLM-5.2 | Z.ai | Text/code work; no image input | + + + +### What else is in the catalog? + +ABP Studio's built-in AI supports 600 different LLMs. I'll add a list of support models in the end of this article as of 14 September 2026. Every time a new model comes, the list will be automatically updated. + +## Add your own provider + +1. Select **Provider connections**. +2. Click **Add provider connection**. +3. Choose a **Provider type**: + - **OpenAI Compatible** ;OpenAI, Azure OpenAI, company gateways, vLLM, LM Studio, or any service that speaks `/v1/chat/completions` and `/v1/models`. + - **Ollama** ;defaults to `http://localhost:11434/v1` with keyless authentication. +4. Give the connection a name and set the **Base URL**. +5. Add at least one API key, or enable keyless auth for a local server. +6. Click **Discover models**, then tick the models you want under **Enabled models**. +7. Save. Select the connection card and pick the active API key if you added more than one. + +After save, Studio switches the active AI connection to your provider. The Included models catalog is replaced by the Provider connections list. Enabled models show up in the chat model picker. + +You can keep up to **3** provider profiles, **3** credentials per profile, and **10** custom request headers (for enterprise gateways that need extra auth). Keys and header values go into platform secure storage, not into the profile JSON. + +### Common problems + +- **Provider connections shows Upgrade.** Your license is below Enterprise. Built-in AI remains the only connection mode. +- **Discover models fails.** Check the base URL, API key, and network access to the endpoint. Ollama defaults to `http://localhost:11434/v1`. +- **Chat input says custom LLM is not configured.** Select the connection card, choose an API key, and ensure at least one model is enabled. +- **The chat says no model is selected.** You changed the connection but did not tick any model under **Included models** / **Enabled models**. + +## What stays the same + +The agent is still ABP Agent. Changing the connection does not turn Studio into a generic chat box. + +- Agent / Plan / Ask modes still work. +- ABP-aware tools, solution context, Git snapshots, and scopes still work. +- You can still assign cheaper models to background jobs (research, text processing, git review, browser) under **Task models**. +- Workspace semantic search still needs an embedding model on the **active** connection. If your custom endpoint has no `/embeddings` API, configure an embedding override or accept that semantic code search stays off for that connection. + +A few built-in behaviors are tied to Built-in AI on purpose: + +- **Auto mode** (Studio picks the best model per message) requires the built-in connection. If you switch to a custom provider, Auto turns off. +- Web search and some managed extras may fall back to the built-in connection when your custom provider cannot perform them. + +## Headless / CI + +The same connection model works outside the desktop UI. With an Enterprise license, the agent daemon can take `ABP_STUDIO_LLM_*` environment variables and apply a custom LLM profile at startup ;the same settings manager the Settings window uses. External clients can see which path is live (`StudioManaged` vs `CustomLlm`). + +## When to use which + +**Stay on Built-in AI** when you want the current catalog, Auto mode, and no key management. That is the out-of-the-box experience. + +**Switch to a provider connection** when: + +- Your company already pays OpenAI / Azure / a private gateway and you want those keys in Studio. +- Code and prompts must stay on a self-hosted endpoint (Ollama, vLLM, LM Studio, internal OpenAI-compatible API). +- You need a specific model that is not in the built-in catalog. +- You are fine managing discovery, keys, and embeddings yourself. + +You are not choosing a different assistant. You are choosing **where the same ABP Agent sends tokens**. + +--- + +## ABP Studio's Supported LLMs as of September 14, 2026 + +*This list is automatically updated whenever a new model becomes available.* + +```` +inference-net/schematron-v2-turbo, inference-net/schematron-v2-small, ~openai/gpt-astra-latest, ~openai/gpt-sol-latest, ~openai/gpt-terra-latest, ~openai/gpt-luna-latest, sakana/fugu-ultra-v2, sakana/fugu-max, inclusionai/ling-3.0-flash-vl, inclusionai/ling-3.0-flash-vl:free, deepseek/deepseek-v4.1-flash, inception/mercury-2.5, nex-agi/nex-n2.5-mini:free, nex-agi/nex-n2.5-pro:free, openai/gpt-6-astra, openai/gpt-6-astra:batch, openai/gpt-6-astra-pro, openai/gpt-6-astra-pro:batch, inclusionai/ling-3.0-flash-sante:free, qwen/qwen3.8-max-0902, meta/muse-spark-1.3-contributor, meta/muse-spark-1.3, google/gemini-3.8-flash, google/gemini-3.8-flash:batch, anthropic/claude-fable-5.1, anthropic/claude-fable-5.1:batch, ibm-granite/granite-4.2-8b, tencent/hy4-preview, inclusionai/ling-3.0-flash-fin, inclusionai/ling-3.0-flash-fin:free, ~z-ai/glm-flash-latest, qwen/qwen3.8-flash, z-ai/glm-5.3-flash, z-ai/glm-5.3-flash:batch, meta/muse-spark-1.2-contributor, deepseek/deepseek-v4-flash-vision-exp, deepseek/deepseek-v4-flash-vision-exp:batch, tencent/hy-mt2-1.8b, tencent/hy-mt2-30b-a3b, ~z-ai/glm-latest, tencent/hy-mt2-7b, z-ai/glm-5.3, z-ai/glm-5.3:batch, qwen/qwen3.8-27b, dots-studio/dots-3-note-preview:free, google/gemini-3.7-flash, google/gemini-3.7-flash:batch, bytedance-seed/seed-2-1-turbo, qwen/qwen3.8-2.4t-a95b, qwen/qwen3.8-2.4t-a95b:batch, bytedance-seed/seed-2.0-code, deepseek/deepseek-v4-pro-0813, deepseek/deepseek-v4-pro-0813:batch, x-ai/grok-4.6, liquid/lfm-2.5-2.6b:free, nvidia/nemotron-3.5-lightning, nvidia/nemotron-3.5-lightning:free, sakana/sakana-namazu, upstage/solar-pro4, meta/muse-glimmer-30b, meta/muse-glimmer-30b:batch, meta/muse-spark-1.2, ~deepseek/deepseek-v4-flash-latest, deepseek/deepseek-v4-flash-0731, deepseek/deepseek-v4-flash-0731:batch, thinkingmachines/inkling-small, thinkingmachines/inkling-small:batch, thinkingmachines/inkling-small:free, qwen/qwen3.7-flash, anthropic/claude-opus-5, anthropic/claude-opus-5:batch, inclusionai/ling-3.0-flash, poolside/laguna-s-2.1, poolside/laguna-s-2.1:free, google/gemini-3.6-flash, google/gemini-3.6-flash:batch, google/gemini-3.5-flash-lite, google/gemini-3.5-flash-lite:batch, meituan/longcat-2.0, thinkingmachines/inkling, thinkingmachines/inkling:batch, thinkingmachines/inkling:free, openrouter/auto-beta, moonshotai/kimi-k3, moonshotai/kimi-k3:batch, meta/muse-spark-1.1, kwaipilot/kat-coder-pro-v2.5, openai/gpt-5.6-luna-pro, openai/gpt-5.6-luna-pro:batch, openai/gpt-5.6-luna, openai/gpt-5.6-luna:batch, openai/gpt-5.6-terra-pro, openai/gpt-5.6-terra-pro:batch, openai/gpt-5.6-terra, openai/gpt-5.6-terra:batch, openai/gpt-5.6-sol-pro, openai/gpt-5.6-sol-pro:batch, openai/gpt-5.6-sol, openai/gpt-5.6-sol:batch, x-ai/grok-4.5, ~x-ai/grok-latest, aion-labs/aion-3.0-mini, aion-labs/aion-3.0, tencent/hy3, poolside/laguna-xs-2.1, poolside/laguna-xs-2.1:free, anthropic/claude-sonnet-5, anthropic/claude-sonnet-5:batch, google/gemini-3.1-flash-lite-image, sakana/fugu-ultra, google/gemini-3.1-flash-image, google/gemini-3-pro-image, cohere/north-mini-code:free, z-ai/glm-5.2, z-ai/glm-5.2:batch, openrouter/fusion, moonshotai/kimi-k2.7-code, ~anthropic/claude-fable-latest, anthropic/claude-fable-5, anthropic/claude-fable-5:batch, nvidia/nemotron-3.5-content-safety, nvidia/nemotron-3.5-content-safety:free, nvidia/nemotron-3-ultra-550b-a55b, nvidia/nemotron-3-ultra-550b-a55b:free, qwen/qwen3.7-plus, minimax/minimax-m3, minimax/minimax-m3:batch, stepfun/step-3.7-flash, anthropic/claude-opus-4.8, anthropic/claude-opus-4.8:batch, qwen/qwen3.7-max, x-ai/grok-build-0.1, google/gemini-3.5-flash, google/gemini-3.5-flash:batch, perceptron/perceptron-mk1, google/gemini-3.1-flash-lite, google/gemini-3.1-flash-lite:batch, openai/gpt-chat-latest, x-ai/grok-4.3, x-ai/grok-4.3:batch, mistralai/mistral-medium-3-5, mistralai/mistral-medium-3-5:batch, nvidia/nemotron-3-nano-omni-30b-a3b-reasoning:free, ~anthropic/claude-haiku-latest, ~openai/gpt-mini-latest, ~google/gemini-pro-latest, ~moonshotai/kimi-latest, ~google/gemini-flash-latest, ~anthropic/claude-sonnet-latest, qwen/qwen3.5-plus-20260420, qwen/qwen3.6-flash, qwen/qwen3.6-35b-a3b, qwen/qwen3.6-max-preview, qwen/qwen3.6-27b, openai/gpt-5.5-pro, openai/gpt-5.5-pro:batch, openai/gpt-5.5, openai/gpt-5.5:batch, deepseek/deepseek-v4-pro, deepseek/deepseek-v4-flash, tencent/hy3-preview, xiaomi/mimo-v2.5-pro, xiaomi/mimo-v2.5, openai/gpt-5.4-image-2, ~anthropic/claude-opus-latest, openrouter/pareto-code, moonshotai/kimi-k2.6, anthropic/claude-opus-4.7, anthropic/claude-opus-4.7:batch, z-ai/glm-5.1, google/gemma-4-26b-a4b-it, google/gemma-4-26b-a4b-it:free, google/gemma-4-31b-it, google/gemma-4-31b-it:batch, google/gemma-4-31b-it:free, qwen/qwen3.6-plus, z-ai/glm-5v-turbo, arcee-ai/trinity-large-thinking, x-ai/grok-4.20-multi-agent, x-ai/grok-4.20, google/lyria-3-pro-preview, google/lyria-3-clip-preview, kwaipilot/kat-coder-pro-v2, rekaai/reka-edge, minimax/minimax-m2.7, openai/gpt-5.4-nano, openai/gpt-5.4-nano:batch, openai/gpt-5.4-mini, openai/gpt-5.4-mini:batch, mistralai/mistral-small-2603, mistralai/mistral-small-2603:batch, z-ai/glm-5-turbo, nvidia/nemotron-3-super-120b-a12b, nvidia/nemotron-3-super-120b-a12b:free, bytedance-seed/seed-2.0-lite, qwen/qwen3.5-9b, qwen/qwen3.5-9b:batch, openai/gpt-5.4-pro, openai/gpt-5.4-pro:batch, openai/gpt-5.4, openai/gpt-5.4:batch, inception/mercury-2, google/gemini-3.1-flash-lite-preview, bytedance-seed/seed-2.0-mini, google/gemini-3.1-flash-image-preview, qwen/qwen3.5-35b-a3b, qwen/qwen3.5-27b, qwen/qwen3.5-122b-a10b, qwen/qwen3.5-flash-02-23, google/gemini-3.1-pro-preview-customtools, openai/gpt-5.3-codex, aion-labs/aion-2.0, google/gemini-3.1-pro-preview, google/gemini-3.1-pro-preview:batch, anthropic/claude-sonnet-4.6, anthropic/claude-sonnet-4.6:batch, qwen/qwen3.5-plus-02-15, qwen/qwen3.5-397b-a17b, minimax/minimax-m2.5, z-ai/glm-5, qwen/qwen3-max-thinking, anthropic/claude-opus-4.6, anthropic/claude-opus-4.6:batch, qwen/qwen3-coder-next, openrouter/free, stepfun/step-3.5-flash, moonshotai/kimi-k2.5, upstage/solar-pro-3, minimax/minimax-m2-her, writer/palmyra-x5, openai/gpt-audio, openai/gpt-audio-mini, z-ai/glm-4.7-flash, openai/gpt-5.2-codex, bytedance-seed/seed-1.6-flash, bytedance-seed/seed-1.6, minimax/minimax-m2.1, z-ai/glm-4.7, google/gemini-3-flash-preview, google/gemini-3-flash-preview:batch, nvidia/nemotron-3-nano-30b-a3b, openai/gpt-5.2-chat, openai/gpt-5.2-pro, openai/gpt-5.2-pro:batch, openai/gpt-5.2, openai/gpt-5.2:batch, mistralai/devstral-2512, relace/relace-search, z-ai/glm-4.6v, openrouter/bodybuilder, openai/gpt-5.1-codex-max, amazon/nova-2-lite-v1, mistralai/ministral-14b-2512, mistralai/ministral-8b-2512, mistralai/ministral-8b-2512:batch, mistralai/ministral-3b-2512, mistralai/mistral-large-2512, mistralai/mistral-large-2512:batch, deepseek/deepseek-v3.2, anthropic/claude-opus-4.5, anthropic/claude-opus-4.5:batch, google/gemini-3-pro-image-preview, openai/gpt-5.1, openai/gpt-5.1:batch, openai/gpt-5.1-codex, openai/gpt-5.1-codex-mini, moonshotai/kimi-k2-thinking, amazon/nova-premier-v1, perplexity/sonar-pro-search, mistralai/voxtral-small-24b-2507, openai/gpt-oss-safeguard-20b, minimax/minimax-m2, qwen/qwen3-vl-32b-instruct, ibm-granite/granite-4.0-h-micro, openai/gpt-5-image-mini, anthropic/claude-haiku-4.5, anthropic/claude-haiku-4.5:batch, qwen/qwen3-vl-8b-thinking, qwen/qwen3-vl-8b-instruct, openai/gpt-5-image, google/gemini-2.5-flash-image, qwen/qwen3-vl-30b-a3b-thinking, qwen/qwen3-vl-30b-a3b-instruct, openai/gpt-5-pro, openai/gpt-5-pro:batch, z-ai/glm-4.6, anthropic/claude-sonnet-4.5, anthropic/claude-sonnet-4.5:batch, deepseek/deepseek-v3.2-exp, thedrummer/cydonia-24b-v4.1, relace/relace-apply-3, qwen/qwen3-vl-235b-a22b-thinking, qwen/qwen3-vl-235b-a22b-instruct, qwen/qwen3-max, qwen/qwen3-coder-plus, deepseek/deepseek-v3.1-terminus, qwen/qwen3-coder-flash, qwen/qwen3-next-80b-a3b-thinking, qwen/qwen3-next-80b-a3b-instruct, qwen/qwen-plus-2025-07-28, moonshotai/kimi-k2-0905, qwen/qwen3-30b-a3b-thinking-2507, nousresearch/hermes-4-405b, deepseek/deepseek-chat-v3.1, mistralai/mistral-medium-3.1, mistralai/mistral-medium-3.1:batch, z-ai/glm-4.5v, openai/gpt-5, openai/gpt-5:batch, openai/gpt-5-mini, openai/gpt-5-mini:batch, openai/gpt-5-nano, openai/gpt-5-nano:batch, openai/gpt-oss-120b, openai/gpt-oss-120b:batch, openai/gpt-oss-20b, openai/gpt-oss-20b:batch, anthropic/claude-opus-4.1, anthropic/claude-opus-4.1:batch, mistralai/codestral-2508, mistralai/codestral-2508:batch, qwen/qwen3-coder-30b-a3b-instruct, qwen/qwen3-30b-a3b-instruct-2507, z-ai/glm-4.5, z-ai/glm-4.5-air, qwen/qwen3-235b-a22b-thinking-2507, qwen/qwen3-coder, bytedance/ui-tars-1.5-7b, google/gemini-2.5-flash-lite, google/gemini-2.5-flash-lite:batch, qwen/qwen3-235b-a22b-2507, moonshotai/kimi-k2, cognitivecomputations/dolphin-mistral-24b-venice-edition, tencent/hunyuan-a13b-instruct, morph/morph-v3-large, morph/morph-v3-fast, baidu/ernie-4.5-vl-424b-a47b, mistralai/mistral-small-3.2-24b-instruct, minimax/minimax-m1, google/gemini-2.5-flash, google/gemini-2.5-flash:batch, google/gemini-2.5-pro, google/gemini-2.5-pro:batch, openai/o3-pro, google/gemini-2.5-pro-preview, deepseek/deepseek-r1-0528, anthropic/claude-opus-4, anthropic/claude-sonnet-4, mistralai/mistral-medium-3, google/gemini-2.5-pro-preview-05-06, meta-llama/llama-guard-4-12b, qwen/qwen3-30b-a3b, qwen/qwen3-8b, qwen/qwen3-14b, qwen/qwen3-32b, qwen/qwen3-235b-a22b, openai/o4-mini-high, openai/o3, openai/o3:batch, openai/o4-mini, openai/o4-mini:batch, openai/gpt-4.1, openai/gpt-4.1:batch, openai/gpt-4.1-mini, openai/gpt-4.1-mini:batch, openai/gpt-4.1-nano, openai/gpt-4.1-nano:batch, meta-llama/llama-4-maverick, meta-llama/llama-4-scout, deepseek/deepseek-chat-v3-0324, openai/o1-pro, mistralai/mistral-small-3.1-24b-instruct, google/gemma-3-4b-it, google/gemma-3-12b-it, cohere/command-a, rekaai/reka-flash-3, google/gemma-3-27b-it, thedrummer/skyfall-36b-v2, perplexity/sonar-reasoning-pro, perplexity/sonar-pro, perplexity/sonar-deep-research, mistralai/mistral-saba, openai/o3-mini-high, aion-labs/aion-rp-llama-3.1-8b, qwen/qwen2.5-vl-72b-instruct, qwen/qwen-plus, openai/o3-mini, openai/o3-mini:batch, mistralai/mistral-small-24b-instruct-2501, perplexity/sonar, deepseek/deepseek-r1-distill-llama-70b, deepseek/deepseek-r1, minimax/minimax-01, microsoft/phi-4, deepseek/deepseek-chat, sao10k/l3.3-euryale-70b, openai/o1, cohere/command-r7b-12-2024, meta-llama/llama-3.3-70b-instruct, amazon/nova-lite-v1, amazon/nova-micro-v1, amazon/nova-pro-v1, openai/gpt-4o-2024-11-20, mistralai/mistral-large-2407, qwen/qwen-2.5-coder-32b-instruct, thedrummer/unslopnemo-12b, anthracite-org/magnum-v4-72b, qwen/qwen-2.5-7b-instruct, meta-llama/llama-3.2-1b-instruct, meta-llama/llama-3.2-3b-instruct, qwen/qwen-2.5-72b-instruct, cohere/command-r-08-2024, cohere/command-r-plus-08-2024, sao10k/l3.1-euryale-70b, nousresearch/hermes-3-llama-3.1-70b, nousresearch/hermes-3-llama-3.1-405b, sao10k/l3-lunaris-8b, openai/gpt-4o-2024-08-06, meta-llama/llama-3.1-70b-instruct, meta-llama/llama-3.1-8b-instruct, mistralai/mistral-nemo, openai/gpt-4o-mini, openai/gpt-4o-mini-2024-07-18, openai/gpt-4o-mini:batch, google/gemma-2-27b-it, openai/gpt-4o, openai/gpt-4o-2024-05-13, openai/gpt-4o:batch, mistralai/mixtral-8x22b-instruct, microsoft/wizardlm-2-8x22b, openai/gpt-4-turbo, openai/gpt-4-turbo:batch, anthropic/claude-3-haiku, mistralai/mistral-large, openai/gpt-3.5-turbo-0613, openai/gpt-4-turbo-preview, openrouter/auto, openai/gpt-3.5-turbo-instruct, openai/gpt-3.5-turbo-16k, mancer/weaver, undi95/remm-slerp-l2-13b, gryphe/mythomax-l2-13b, openai/gpt-3.5-turbo, openai/gpt-3.5-turbo:batch, openai/gpt-4 +```` + diff --git a/docs/en/Community-Articles/2026-09-14-ABP-Studio-AI-Agent-Bring-Your-Own-Key/ai-connection-settings.png b/docs/en/Community-Articles/2026-09-14-ABP-Studio-AI-Agent-Bring-Your-Own-Key/ai-connection-settings.png new file mode 100644 index 0000000000..b362d4bd52 Binary files /dev/null and b/docs/en/Community-Articles/2026-09-14-ABP-Studio-AI-Agent-Bring-Your-Own-Key/ai-connection-settings.png differ diff --git a/docs/en/Community-Articles/2026-09-14-ABP-Studio-AI-Agent-Bring-Your-Own-Key/cover.png b/docs/en/Community-Articles/2026-09-14-ABP-Studio-AI-Agent-Bring-Your-Own-Key/cover.png new file mode 100644 index 0000000000..9d51d88487 Binary files /dev/null and b/docs/en/Community-Articles/2026-09-14-ABP-Studio-AI-Agent-Bring-Your-Own-Key/cover.png differ diff --git a/docs/en/Community-Articles/2026-09-14-ABP-Studio-AI-Agent-Bring-Your-Own-Key/included-models-catalog.png b/docs/en/Community-Articles/2026-09-14-ABP-Studio-AI-Agent-Bring-Your-Own-Key/included-models-catalog.png new file mode 100644 index 0000000000..11e518c222 Binary files /dev/null and b/docs/en/Community-Articles/2026-09-14-ABP-Studio-AI-Agent-Bring-Your-Own-Key/included-models-catalog.png differ diff --git a/docs/en/Community-Articles/2026-09-16-vector-search-and-hybrid-search-in-ef-core-11/POST.md b/docs/en/Community-Articles/2026-09-16-vector-search-and-hybrid-search-in-ef-core-11/POST.md new file mode 100644 index 0000000000..b59581e112 --- /dev/null +++ b/docs/en/Community-Articles/2026-09-16-vector-search-and-hybrid-search-in-ef-core-11/POST.md @@ -0,0 +1,406 @@ +# Vector and Hybrid Search with SQL Server in EF Core 11 + +> Requires .NET 11 and EF Core 11. Verified against EF Core `11.0.0-rc.1.26425.128`. + +A help center has a few thousand articles in SQL Server. Users type what went wrong in their own words — "login keeps timing out" — and the search returns nothing, because the article that answers them is titled "session expires too quickly" and shares no words with the query. + +The usual fix is to put a vector database next to the application: pick one, sync the rows into it, keep the two stores consistent, and accept a second system to operate, back up, and secure. That is a lot of infrastructure for one feature, and the articles are already sitting in SQL Server. + +SQL Server 2025 added a `vector` type, distance functions, and DiskANN vector indexes. EF Core 10 made the storage side usable from .NET. EF Core 11 adds the remaining query-side building blocks: approximate search over a vector index, full-text search table-valued functions, and translation for .NET 11's new `FullJoin` operator. + +This article follows that help center from the first embedding to a working hybrid search, adding each feature at the point where the previous step stops being enough. + +## Storing Embeddings Next to the Articles + +Add a `SqlVector` property and specify how many dimensions the column holds. The dimension count is mandatory; leaving it out fails model validation. + +```csharp +public class Article +{ + public int Id { get; set; } + public string Title { get; set; } = null!; + public string Content { get; set; } = null!; + + [Column(TypeName = "vector(1536)")] + public SqlVector Embedding { get; set; } +} +``` + +Generating the embedding happens outside the database. [`Microsoft.Extensions.AI`](https://learn.microsoft.com/en-us/dotnet/ai/microsoft-extensions-ai) provides a provider-agnostic `IEmbeddingGenerator>`, so which model produces the vector stays a configuration decision: + +```csharp +IEmbeddingGenerator> embeddingGenerator = /* your provider */; + +article.Embedding = new SqlVector( + await embeddingGenerator.GenerateVectorAsync(article.Content)); + +await context.SaveChangesAsync(); +``` + +The user's query goes through the same generator. That is not optional: distances are only meaningful between vectors from the same model, and a different dimension count will not fit the `vector(1536)` column at all. + +Keeping the vectors in the same database removes the sync problem between two stores, but the embedding is still derived data with a lifecycle. Regenerate it whenever the source text changes, or the search keeps matching the old wording. Version the model and dimension count, because switching models means backfilling every row. And long articles usually need chunking rather than one vector for the whole `Content`. + +```csharp +var query = new SqlVector( + await embeddingGenerator.GenerateVectorAsync(queryText)); +``` + +## Searching by Meaning + +With embeddings stored, the first working version of the search is an `OrderBy` on distance: + +```csharp +var hits = await context.Articles + .OrderBy(a => EF.Functions.VectorDistance("cosine", a.Embedding, query)) + .Select(a => new { a.Id, a.Title }) + .Take(5) + .ToListAsync(); +``` + +```sql +SELECT TOP(@p) [a].[Id], [a].[Title] +FROM [Articles] AS [a] +ORDER BY VECTOR_DISTANCE('cosine', [a].[Embedding], @query) +``` + +This is exact k-nearest-neighbor search. Every row is compared, so it returns the true nearest neighbors for the chosen metric. "login keeps timing out" now finds "session expires too quickly", and the help center ships. + +The supported metrics are `cosine`, `euclidean`, and `dot`. Cosine is common for text embeddings, but use whichever the model's documentation recommends, and note whether it expects normalized vectors. + +This is also where a lot of applications stop. Exact search stays reasonable up to roughly 50,000 vectors — or any table size, as long as a `WHERE` clause narrows the candidates first — and it is all stable EF Core 10 API. + +## When the Scan Becomes the Bottleneck + +The help center grows. Every search now computes a distance for every row, and the scan shows up in traces. + +Vector indexes exist to avoid that. SQL Server uses [DiskANN](https://www.microsoft.com/en-us/research/publication/diskann-fast-accurate-billion-point-nearest-neighbor-search-on-a-single-node), a graph index built for vectors that do not fit in memory, and a search walks a small part of the graph instead of the whole table. + +The trade-off is in the name: **approximate** nearest neighbor search can miss a true neighbor. That is usually acceptable for ranking, where a different item somewhere in the top-k changes nothing a user would notice — but it is worth measuring recall on your own corpus rather than assuming it. + +![Exact versus approximate search — conceptual example](images/exact-vs-approximate.png) + +Configure the index in the model: + +```csharp +modelBuilder.Entity
() + .HasVectorIndex(a => a.Embedding) + .HasMetric("cosine") + .HasType("DiskANN"); +``` + +`HasMetric` is required, and the metric configured here must match the one passed at query time or the index is not used. A vector index also covers exactly one column. + +Note that the second argument to `HasVectorIndex` is the index name, not the metric — the [documentation](https://learn.microsoft.com/en-us/ef/core/providers/sql-server/vector-search#vector-indexes) currently passes `"cosine"` there. Written that way the index is called `"cosine"`, no metric is set, and model validation fails. + +### Getting the Index Created at All + +Deploying that index is harder than it looks. A vector index cannot be created on a table with fewer than 100 non-null vectors, and creating it too early fails with `Msg 42266`. + +`UseSeeding` runs after the whole migration batch, so you cannot rely on it to prepare data for a later migration in the same update. Split the work into explicit ordered steps instead: create the table, write at least 100 non-null vectors with a data migration, then create the index in the migration after that. + +Three more constraints are worth knowing before you design the deployment. The table must have a clustered primary key — and SQL Server 2025 is stricter than the limitations page reads: error 42217 asks for that key to be *a single 4 byte INT column*. Azure SQL Database, which carries the newer index version, accepted `bigint` and `uniqueidentifier` keys when I tried it, so this one is worth testing on your own target rather than assuming either way. `TRUNCATE TABLE` is blocked while a vector index exists. And vector indexes cannot be deployed through DacPac or BACPAC, because the import creates schema before loading data and therefore hits the 100-row rule — drop the index before exporting and recreate it after the import. + +### Querying the Index + +```csharp +var hits = await context.Articles + .VectorSearch(a => a.Embedding, query, "cosine") + .OrderBy(r => r.Distance) + .Take(5) + .WithApproximate() + .ToListAsync(); +``` + +```sql +SELECT TOP(@p1) WITH APPROXIMATE [a].[Id], [a].[Content], [a].[Title], [v].[Distance] +FROM VECTOR_SEARCH( + TABLE = [Articles] AS [a], + COLUMN = [Embedding], + SIMILAR_TO = @p, + METRIC = 'cosine' +) AS [v] +ORDER BY [v].[Distance] +``` + +`VectorSearch()` returns `IQueryable>`, which carries both the entity (`Value`) and the computed `Distance`. `WithApproximate()` must come after `Take()` — it is what turns `TOP(n)` into `TOP(n) WITH APPROXIMATE`. On the latest index version, a `Where()` placed before `Take()` is applied inside the search, so filters narrow the candidate set rather than trimming results afterwards. + +The failure mode to guard against is forgetting `WithApproximate()`. On a platform that accepts the generated syntax at all — see the next section — the query still compiles, still runs, and still returns correct results, by scanning every row with the index unused. EF only warns in the log, so turn that warning into an error while developing: + +```csharp +options.UseSqlServer(connectionString) + .ConfigureWarnings(w => w.Throw(SqlServerEventId.VectorSearchWithoutApproximateIndexWarning)); +``` + +## Where This Actually Runs + +Before committing to that path, check that it runs on your target at all. The new approximate-search APIs — `VectorSearch()`, `WithApproximate()` and the vector index builder — carry `[Experimental("EF9105")]`, so your code does not compile until the diagnostic is acknowledged with `$(NoWarn);EF9105`. `VectorDistance()`, `FreeTextTable()`, `ContainsTable()` and the full-text modelling APIs are not marked. + +The attribute itself only affects compilation. What decides whether a query runs is the server product, its region, and the version of the vector index. + +| Capability | SQL Server 2025 container `17.0.5005.3` | Azure SQL Database | +|---|---|---| +| `vector` column, `SqlVector` | ✅ | ✅ | +| `EF.Functions.VectorDistance()` | ✅ | ✅ | +| `CREATE VECTOR INDEX` from a migration | ✅ | ✅ | +| **`VectorSearch()` + `WithApproximate()`** | ❌ | ✅ | +| Full-text search | ❌ not installed in the image | ✅ | +| `PREVIEW_FEATURES` required for indexes and `VECTOR_SEARCH` | ✅ | ❌ | + +The SQL Server 2025 column reports one tested build, the stock `mcr.microsoft.com/mssql/server:2025-latest` image. Full-text search is missing because that image does not ship the component, not because SQL Server 2025 lacks it. + +On SQL Server 2025, `CREATE VECTOR INDEX` and `VECTOR_SEARCH` are documented as preview features that need the database scoped configuration turned on first: + +```sql +ALTER DATABASE SCOPED CONFIGURATION SET PREVIEW_FEATURES = ON; +``` + +Azure SQL Database does not require it. + +Even with that enabled, the generated query is rejected on the tested `17.0.5005.3` build with `Incorrect syntax near 'APPROXIMATE'`. Dropping `WithApproximate()` gives a more informative failure, `Incorrect syntax near 'TOP_N'`, even though the generated SQL contains no `TOP_N` anywhere. + +That build requires `TOP_N` inside the function call, which is the older calling convention: + +```sql +SELECT TOP(3) t.Id, s.distance +FROM VECTOR_SEARCH(TABLE = Articles AS t, COLUMN = Embedding, SIMILAR_TO = @qv, + METRIC = 'cosine', TOP_N = 3) AS s +ORDER BY s.distance; +``` + +That form runs. The server supports approximate search; it speaks the older dialect, and EF generates only the newer one, with no compatibility switch. On Azure SQL Database — and on SQL database in Microsoft Fabric, which also carries the latest index version — the EF query runs unchanged. + +The two index versions differ in behaviour, not only in syntax. On the older version the table becomes read-only once the index exists. `ALLOW_STALE_VECTOR_INDEX` lifts that on Azure SQL Database and SQL database in Microsoft Fabric, but that database scoped configuration does not exist on SQL Server 2025, so on the build tested here there is no way back to a writable table. `WHERE` predicates are also applied after retrieval rather than during it, so `TOP_N` has to be widened by hand to survive filtering. The iterative filtering described above belongs to the latest index version. + +Two more environment notes. As of September 2026, Azure SQL Database vector search is live in North Europe and UK South only, so check region availability before planning around it. And `SERVERPROPERTY('IsFullTextInstalled')` returns 0 on `mcr.microsoft.com/mssql/server:2025-latest`, so full-text search needs a derived image that installs `mssql-server-fts`. + +## The Embeddings Come Back Empty + +A bug report arrives: an admin edits an article's title, saves, and the search stops finding it — or a background job that re-reads embeddings gets nothing. + +EF Core 11 excludes vector columns from the `SELECT` list by default when materializing entities: + +```sql +SELECT TOP(@p) [a].[Id], [a].[Content], [a].[Title] +FROM [Articles] AS [a] +ORDER BY [a].[Id] +``` + +There is no `[Embedding]`, and the property comes back with a length of zero even though every row has a value. + +The reasoning is sound. A 1,536-dimensional float vector is 6 KB per row, and embeddings are written rarely and searched against constantly but almost never read back. In a minimal benchmark, Microsoft measured roughly a 9x throughput improvement locally from not shipping them over the wire, and 22x against a remote Azure SQL database. + +Vectors still work in `WHERE` and `ORDER BY`. Reading one requires an explicit projection: + +```csharp +var embeddings = await context.Articles + .Select(a => new { a.Id, a.Embedding }) + .ToListAsync(); +``` + +So the title edit is safe: saving a tracked entity leaves the stored embedding untouched. That is correct here because the vector is generated from `Content` alone. The sample that ships with this article embeds the title as well, and there the same edit does leave a stale vector behind — which input feeds the embedding decides whether an edit invalidates it. What breaks is code that *reads* `Embedding` from a tracked entity: it gets an empty vector, and ordinary property access returns it without any warning. Check `context.Entry(article).Property(a => a.Embedding).IsLoaded` when it matters, or project the property explicitly. + +## Exact Terms Still Fail + +The next complaint is different. Users searching for an error number, a plan name, or a specific setting get articles that are thematically close and factually wrong. Vector search finds meaning and misses precision — that is what it is for. + +EF Core has translated `EF.Functions.FreeText()` and `EF.Functions.Contains()` for years, but those are predicates: they filter without ranking, which is no help when you need a merged ordering later. EF Core 11 adds the table-valued versions, which return SQL Server's relevance score: + +```csharp +var hits = await context.Articles + .FreeTextTable("session expires too quickly", topN: 20) + .Join(context.Articles, fts => fts.Key, a => a.Id, (fts, a) => new { a.Title, fts.Rank }) + .OrderByDescending(x => x.Rank) + .ToListAsync(); +``` + +`FullTextSearchResult` exposes only `Key` and `Rank`, so the join back to the table is explicit, and both generic type arguments must be supplied explicitly because `TKey` cannot be inferred. `ContainsTable()` has the same shape but takes a search condition (`"nebula OR quasar"`, `NEAR`, prefix terms) instead of free text. + +The catalog and index can be configured in the model as of EF Core 11: + +```csharp +modelBuilder.HasFullTextCatalog("ftCatalog"); + +modelBuilder.Entity
() + .HasFullTextIndex(a => new { a.Title, a.Content }) + .UseKeyIndex("PK_Articles") + .UseCatalog("ftCatalog"); +``` + +`UseKeyIndex` has to name a unique, single-column, non-nullable index — SQL Server uses it as the full-text key, which is what `FullTextSearchResult.Key` returns. + +That configuration has a side effect in the table definition rather than the index. `HasFullTextIndex` is built on `HasIndex`, so EF applies its ordinary index key size limit to the string properties involved, and a `Content` property that should map to `nvarchar(max)` comes out as `nvarchar(450)` — truncating the column you most wanted to search. Set the column type explicitly to keep the full length: + +```csharp +modelBuilder.Entity
() + .Property(a => a.Content) + .HasColumnType("nvarchar(max)"); +``` + +One more thing that looks like a bug in tests: full-text population is asynchronous. In a 120-row sample it took about 20 seconds to become searchable after `CREATE FULLTEXT INDEX`, so a seed routine that queries immediately gets an empty result. Wait until the indexed row count catches up: + +```sql +SELECT OBJECTPROPERTYEX(OBJECT_ID('Articles'), 'TableFulltextItemCount'); +``` + +Give that loop an interval and a timeout, and check `TableFulltextFailCount` as well — rows that fail indexing never arrive, so waiting for the count to reach the table total can hang forever. The catalog-level `FULLTEXTCATALOGPROPERTY('ftCatalog', 'PopulateStatus')` is the more obvious check, but Microsoft has marked that property for removal and advises against polling it in a tight loop. + +## Merging the Two Rankings + +Now the help center has two searches that each fail differently, and neither one alone is the product. They have to be merged. + +The standard merge is Reciprocal Rank Fusion: each document scores `1 / (k + position)` for every list it appears in, where `k` is a smoothing constant, and the scores are summed. With suitable parameters, a document that both retrievers rank moderately well can beat one that a single retriever ranks first. + +![Hybrid search with reciprocal rank fusion](images/hybrid-search.png) + +Evaluating a fusion needs a corpus where the two retrievers disagree. The one used here has 120 documents, a query text of `nebula quasar`, and an astronomy query vector: 12 documents match on both sides, 24 are semantically on topic but share no query words, 12 are lexical false friends — dessert menu items named *Nebula* and *Quasar*, embedded in a cooking topic — and 72 are unrelated. That corpus, and the console probe that produced every measurement below, are in the sample repository: [maliming/efcore11-vector-hybrid-search](https://github.com/maliming/efcore11-vector-hybrid-search). + +Each retriever on its own: + +```text +FreeTextTable Deep sky survey 4 (484), 9 (447), 6 (269), 8 (269), 2 (189), … +VectorSearch Observation log 26 (0.0112), 34 (0.0125), 18 (0.0134), 32 (0.0145), … +``` + +Both lists lead with one group each: full-text with documents the corpus makes match on both sides, vector search with the semantic-only ones. Neither puts a doubly-corroborated document first. + +### The Documented Single-Query Shape + +The documentation builds the fusion as a single query, joining the two retrievers with .NET 11's `FullJoin` and computing the score in the projection. As observed on `11.0.0-rc.1.26425.128`, that shape has three practical problems. Re-check the first two against GA before building on them. + +The first stops the build. The sample compares `vs == null`, but `VectorSearchResult` is a `readonly struct`, so that is `CS0019`. Projecting the vector side to a reference type first — `.Select(r => new { Article = r.Value, r.Distance })` — fixes it. + +The second is materialization. Once the fused score is computed in the projection, reading back a result set that contains rows matched on one side only throws `InvalidOperationException: Nullable object must have a value`. + +Projecting the same entity and nullable scalars without that score expression works, so it is the fused projection that breaks rather than the full join itself. + +The third is the score, and it is wrong in two separate ways. + +It inverts the full-text ranking. SQL Server's `RANK` is higher-is-better, so feeding it into `1 / (k + Rank)` gives the *least* relevant keyword matches the highest score. In the measured run, a document with `RANK` 119 scored above one with `RANK` 140. + +It also turns vector membership into a flat bonus. Cosine distances sit near zero, so with the documented `k` of 20 the vector term is about `1 / 20 = 0.05` for anything in the vector list, while the entire full-text term spans roughly 0.002 to 0.007 across the ranks in this run. Simply appearing in the vector results is worth seven to twenty-five times more than any difference in keyword relevance. + +Neither side uses rank positions, which is what RRF is defined over. + +### Fusing on Rank Positions + +Fetching the two ranked lists separately and applying RRF in memory avoids all three: + +```csharp +const int candidateCount = 20; +const int rrfK = 60; // the constant from the original RRF paper + +var lexical = await context.Articles + .FreeTextTable(queryText, topN: candidateCount) + .Join(context.Articles, fts => fts.Key, a => a.Id, (fts, a) => new { a.Id, a.Title, fts.Rank }) + .OrderByDescending(x => x.Rank) + .ThenBy(x => x.Id) + .ToListAsync(); + +var semantic = await context.Articles + .OrderBy(a => EF.Functions.VectorDistance("cosine", a.Embedding, queryVector)) + .ThenBy(a => a.Id) + .Select(a => new { a.Id, a.Title }) + .Take(candidateCount) + .ToListAsync(); + +var lexicalPosition = lexical.Select((x, i) => (x.Id, Position: i + 1)).ToDictionary(x => x.Id, x => x.Position); +var semanticPosition = semantic.Select((x, i) => (x.Id, Position: i + 1)).ToDictionary(x => x.Id, x => x.Position); + +var titles = lexical.Select(x => (x.Id, x.Title)) + .Concat(semantic.Select(x => (x.Id, x.Title))) + .DistinctBy(x => x.Id) + .ToDictionary(x => x.Id, x => x.Title); + +var fused = titles.Keys + .Select(id => new + { + Id = id, + Title = titles[id], + LexicalPosition = lexicalPosition.TryGetValue(id, out var l) ? l : (int?)null, + SemanticPosition = semanticPosition.TryGetValue(id, out var s) ? s : (int?)null, + Score = (lexicalPosition.TryGetValue(id, out var lp) ? 1.0 / (rrfK + lp) : 0.0) + + (semanticPosition.TryGetValue(id, out var sp) ? 1.0 / (rrfK + sp) : 0.0) + }) + .OrderByDescending(x => x.Score) + .ThenBy(x => x.Id) + .Take(10) + .ToList(); +``` + +The `ThenBy` calls matter at both levels. Full-text ranks tie often — two documents above share `RANK` 269 — and the positions those lists produce are what the score is built from, so an unstable input order moves the final score. Ties in the score itself are just as common: two pairs below land on exactly `0.01639` and `0.01613`. + +The semantic list here comes from `VectorDistance()`, which keeps the whole pipeline on stable API and runs on any SQL Server 2025 instance. On Azure SQL Database in a supported region, swap that one query for the indexed version and nothing else changes: + +```csharp +var semantic = await context.Articles + .VectorSearch(a => a.Embedding, queryVector, "cosine") + .OrderBy(r => r.Distance) + .Take(candidateCount) + .WithApproximate() + .Select(r => new { r.Value.Id, r.Value.Title, r.Distance }) + .ToListAsync(); + +// VECTOR_SEARCH accepts a single ascending ordering on the distance, so the tie-break the +// exact query does in SQL has to happen here instead. +semantic = [.. semantic.OrderBy(x => x.Distance).ThenBy(x => x.Id)]; +``` + +That last line is not decoration: `VECTOR_SEARCH` only takes one ordering key, so the approximate path cannot express the tie-break in SQL and has to apply it after the rows come back. Against this corpus both versions produce the same fused ranking, which is what you would hope for at 120 documents — the approximate path earns its keep at a scale where the exact scan hurts, not by changing the answer. + +Two round trips instead of one, and the fusion itself is a dictionary lookup over at most `2 * candidateCount` rows: + +```text +title lexical# semantic# score +Deep sky survey 8 4 5 0.03101 +Deep sky survey 1 7 12 0.02881 +Deep sky survey 10 10 9 0.02878 +Deep sky survey 5 9 16 0.02765 +Deep sky survey 3 8 19 0.02736 +Deep sky survey 4 1 - 0.01639 +Observation log 26 - 1 0.01639 +Deep sky survey 9 2 - 0.01613 +Observation log 34 - 2 0.01613 +Deep sky survey 6 3 - 0.01587 +``` + +`Deep sky survey 8` is ranked 4th by keywords and 5th by vectors — first by neither — and wins outright because both retrievers agree on it. + +That ordering is a parameter choice, not a universal truth. With `rrfK = 60` and `candidateCount = 20`, the worst possible two-list score is `2 / (60 + 20) = 0.025` and the best possible one-list score is `1 / (60 + 1) = 0.0164`, so anything both retrievers return outranks anything only one of them found. For the help center that pushes keyword-only false positives down — but it would push down a correct error number just as hard, if the vector side happened to miss it. When exact identifiers matter, lower `rrfK`, widen the candidate lists, or add an explicit boost for exact matches. + +The companion web application in that same repository puts all three strategies on one page. It ships the help center corpus from the opening — 32 articles, a separate set from the 120 documents used for the measurements above: + +![The three retrieval strategies side by side in the sample application](images/demo-three-strategies.png) + +The opening query behaves as described. Semantic search returns *Session expires too quickly* first — a title that shares no words with the query. Keyword search mixes in *Sign in sheet export template* — a reporting article about attendance sheets — and a billing article about declined cards. The fused list puts four authentication articles on top and drops both false friends below them. *Session expires too quickly*, which only the vector side found, lands at 8: the trade-off from the paragraph above, on this sample corpus. + +Clicking a result expands it: + +![The expanded article panel, showing that the vector did not come back with the entity](images/demo-article-detail.png) + +`Came back with the entity: no` is the earlier section made visible — loading the article never fetched its 1,536 floats, and the values in the panel come from a second query that projects the property explicitly. + +## What to Ship + +Following that path end to end, the version worth deploying is smaller than the feature list suggests. + +Store embeddings in a `vector` column and search with `VectorDistance()`. That API is stable, exact, runs on any SQL Server 2025 instance, and is fast enough for tens of thousands of candidate articles. Add a full-text index when exact terms matter, and fuse the two ranked lists on positions in application code. Both halves are non-experimental, and the fusion works with either vector retriever. + +Reach for `VectorSearch()` and a vector index when profiling shows the scan is actually the bottleneck, and only on Azure SQL Database or SQL database in Microsoft Fabric in a region that supports it. Treat that path as preview on both sides. + +## Summary + +EF Core 11 lets you build semantic, lexical, and hybrid search on SQL Server without a separate vector database. Start with exact search, add full-text search when exact terms matter, and use approximate search only when scale justifies its preview constraints. And remember that vector columns are no longer loaded by default when materializing entities. + +## References + +- [What's New in EF Core 11](https://learn.microsoft.com/en-us/ef/core/what-is-new/ef-core-11.0/whatsnew) +- [Vector search in the SQL Server EF Core Provider](https://learn.microsoft.com/en-us/ef/core/providers/sql-server/vector-search) +- [Full-text search in the SQL Server EF Core Provider](https://learn.microsoft.com/en-us/ef/core/providers/sql-server/full-text-search) +- [Vector search and vector indexes in the SQL Database Engine](https://learn.microsoft.com/en-us/sql/sql-server/ai/vectors) +- [`VECTOR_SEARCH` (Transact-SQL)](https://learn.microsoft.com/en-us/sql/t-sql/functions/vector-search-transact-sql) +- [`CREATE VECTOR INDEX` (Transact-SQL)](https://learn.microsoft.com/en-us/sql/t-sql/statements/create-vector-index-transact-sql) +- [Azure SQL Database feature availability by region](https://learn.microsoft.com/en-us/azure/azure-sql/database/region-availability) +- [Microsoft.Extensions.AI](https://learn.microsoft.com/en-us/dotnet/ai/microsoft-extensions-ai) +- [Sample code for this article](https://github.com/maliming/efcore11-vector-hybrid-search) — the web application and the measurement probe +- [Reciprocal Rank Fusion outperforms Condorcet and individual rank learning methods](https://cormack.uwaterloo.ca/cormacksigir09-rrf.pdf) — the original RRF paper diff --git a/docs/en/Community-Articles/2026-09-16-vector-search-and-hybrid-search-in-ef-core-11/cover.png b/docs/en/Community-Articles/2026-09-16-vector-search-and-hybrid-search-in-ef-core-11/cover.png new file mode 100644 index 0000000000..2a6c96bfc4 Binary files /dev/null and b/docs/en/Community-Articles/2026-09-16-vector-search-and-hybrid-search-in-ef-core-11/cover.png differ diff --git a/docs/en/Community-Articles/2026-09-16-vector-search-and-hybrid-search-in-ef-core-11/images/demo-article-detail.png b/docs/en/Community-Articles/2026-09-16-vector-search-and-hybrid-search-in-ef-core-11/images/demo-article-detail.png new file mode 100644 index 0000000000..cc3a7a976a Binary files /dev/null and b/docs/en/Community-Articles/2026-09-16-vector-search-and-hybrid-search-in-ef-core-11/images/demo-article-detail.png differ diff --git a/docs/en/Community-Articles/2026-09-16-vector-search-and-hybrid-search-in-ef-core-11/images/demo-three-strategies.png b/docs/en/Community-Articles/2026-09-16-vector-search-and-hybrid-search-in-ef-core-11/images/demo-three-strategies.png new file mode 100644 index 0000000000..b17602bd81 Binary files /dev/null and b/docs/en/Community-Articles/2026-09-16-vector-search-and-hybrid-search-in-ef-core-11/images/demo-three-strategies.png differ diff --git a/docs/en/Community-Articles/2026-09-16-vector-search-and-hybrid-search-in-ef-core-11/images/exact-vs-approximate.png b/docs/en/Community-Articles/2026-09-16-vector-search-and-hybrid-search-in-ef-core-11/images/exact-vs-approximate.png new file mode 100644 index 0000000000..bd2baf4a80 Binary files /dev/null and b/docs/en/Community-Articles/2026-09-16-vector-search-and-hybrid-search-in-ef-core-11/images/exact-vs-approximate.png differ diff --git a/docs/en/Community-Articles/2026-09-16-vector-search-and-hybrid-search-in-ef-core-11/images/hybrid-search.png b/docs/en/Community-Articles/2026-09-16-vector-search-and-hybrid-search-in-ef-core-11/images/hybrid-search.png new file mode 100644 index 0000000000..25ec98de55 Binary files /dev/null and b/docs/en/Community-Articles/2026-09-16-vector-search-and-hybrid-search-in-ef-core-11/images/hybrid-search.png differ diff --git a/docs/en/Community-Articles/2026-09-17-NET-11-Container-Publishing/2-conflict.jpeg b/docs/en/Community-Articles/2026-09-17-NET-11-Container-Publishing/2-conflict.jpeg new file mode 100644 index 0000000000..b916e5bf34 Binary files /dev/null and b/docs/en/Community-Articles/2026-09-17-NET-11-Container-Publishing/2-conflict.jpeg differ diff --git a/docs/en/Community-Articles/2026-09-17-NET-11-Container-Publishing/2-manifest.jpeg b/docs/en/Community-Articles/2026-09-17-NET-11-Container-Publishing/2-manifest.jpeg new file mode 100644 index 0000000000..4bb03ef0b7 Binary files /dev/null and b/docs/en/Community-Articles/2026-09-17-NET-11-Container-Publishing/2-manifest.jpeg differ diff --git a/docs/en/Community-Articles/2026-09-17-NET-11-Container-Publishing/3-podman.jpeg b/docs/en/Community-Articles/2026-09-17-NET-11-Container-Publishing/3-podman.jpeg new file mode 100644 index 0000000000..fc9b3a7d92 Binary files /dev/null and b/docs/en/Community-Articles/2026-09-17-NET-11-Container-Publishing/3-podman.jpeg differ diff --git a/docs/en/Community-Articles/2026-09-17-NET-11-Container-Publishing/5-checklist.jpeg b/docs/en/Community-Articles/2026-09-17-NET-11-Container-Publishing/5-checklist.jpeg new file mode 100644 index 0000000000..6fadea5427 Binary files /dev/null and b/docs/en/Community-Articles/2026-09-17-NET-11-Container-Publishing/5-checklist.jpeg differ diff --git a/docs/en/Community-Articles/2026-09-17-NET-11-Container-Publishing/Post.md b/docs/en/Community-Articles/2026-09-17-NET-11-Container-Publishing/Post.md new file mode 100644 index 0000000000..2db61d1df7 --- /dev/null +++ b/docs/en/Community-Articles/2026-09-17-NET-11-Container-Publishing/Post.md @@ -0,0 +1,79 @@ +# .NET 11 Container Publishing: Hype, Hands-On Reality, and the DevOps Playbook + +Shipping multi-platform, secure containers without maintaining complex `Dockerfile`s is the holy grail for platform engineering. With .NET 11 (Release Candidate 1), Microsoft heavily markets its built-in SDK container publishing as the solution. But marketing claims and CI/CD realities often clash. + +After running the .NET 11 RC1 SDK through an isolated sandbox environment—testing everything from cross-compilation to rootless runtimes—here is the unvarnished DevOps breakdown of what actually works, what is overhyped, and how you should adapt your pipelines. + +## 1. SDK-Driven Publishing and the Base Image Reality + +The SDK natively understands your `.csproj` and generates an OCI-compliant image without a single Dockerfile command. Running a simple publish command works effortlessly: + +```bash +dotnet publish /t:PublishContainer -p:ContainerRepository=my-registry.local/myapp -p:ContainerImageTag=1.0.0 + +``` + +The process takes roughly 6 to 11 seconds. However, contrary to the belief that the SDK defaults to "microscopic" secure images, the default base image pulled is the standard Debian-based `aspnet:11.0.0-rc.1`, resulting in a ~256MB footprint. + +To achieve a minimal attack surface, you must explicitly opt into Ubuntu Chiseled images. In .NET 11, the correct chiseled tag family corresponds to Ubuntu 26.04 (Resolute) rather than Ubuntu 24.04 (Noble). If you rely on auto-inference during the preview/RC phase, the SDK might incorrectly target `noble-chiseled` and fail, so you must explicitly declare it: + +```xml + +resolute-chiseled + +``` + +While marketing sometimes hints at sub-50MB footprints, sandbox testing shows a standard minimal API built on `resolute-chiseled` clocks in at **128MB uncompressed**—still an excellent 50% reduction with zero package managers or shells included. + +## 2. Multi-Architecture: The Massive Win and the Critical Gotcha + +Transitioning to ARM64 (like AWS Graviton) saves money, but configuring QEMU and Docker Buildx in CI pipelines is notoriously slow. .NET 11 handles this beautifully at the compiler level. + +By passing `-r linux-arm64`, the SDK cross-compiles the Intermediate Language (IL) natively and constructs the ARM64 container layers on an x64 runner without ever invoking QEMU. This is a massive CI performance win. + +**The Pipeline Gotcha:** You cannot rely on the SDK to build a true multi-architecture tag (a single `latest` tag that resolves correctly on both architectures). If you run consecutive publish commands for `linux-x64` and `linux-arm64` pointing to the same registry tag, the second push **completely overwrites** the first manifest. + +![conflict](./2-conflict.jpeg) +--- + +To create a genuine multi-arch manifest list, your CI/CD pipeline still requires a manual step. + +![manifest](./2-manifest.jpeg) +--- + +> **Key insight:** Build and push architecture-specific tags (`latest-amd64`, `latest-arm64`) with the SDK, then use `docker manifest create` or `buildah manifest` at the end of your pipeline to bind them together. + +## 3. Daemonless CI/CD: Seamless Podman Integration + +If your enterprise strictly enforces rootless, daemonless CI/CD agents, .NET 11 is a game changer. Historically, using Podman required brittle `DOCKER_HOST` socket mapping hacks. + +![podman](./3-podman.jpeg) + +In testing, completely removing Docker from the `PATH` and installing only Podman resulted in flawless execution. The SDK automatically detects Podman and pushes directly to its local image store. You can finally adopt rootless Podman on RHEL/Ubuntu GitHub Action runners without modifying your `dotnet publish` commands. + +## 4. Supply-Chain Security: The Reproducibility Illusion + +Software Supply Chain standards like SLSA emphasize reproducible builds—the guarantee that the same source code produces the exact same artifact digest. + +While the .NET 11 compiler is perfectly deterministic (producing byte-for-byte identical DLLs on identical source code), the resulting container image digest (SHA256) **will still change** on every build. This occurs because the container packing step embeds the current wall-clock time (`mtime`) into the headers of the `tar` filesystem layers. Until the SDK provides a robust `SOURCE_DATE_EPOCH` injection mechanism, strict bit-for-bit image digest reproducibility requires external tooling. + +## The DevOps Adoption Checklist + +Before ripping out your `Dockerfile`s for .NET 11, evaluate your pipelines against these verified realities: + +1. **Validate OS Dependencies:** No apt-get allowed. +The SDK cannot install OS-level packages (e.g., `ffmpeg`, `wkhtmltopdf`). If your app relies on them, stick to a `Dockerfile`. + + +2. **Force Chiseled Images:** Update your .csproj. +Add `resolute-chiseled` to halve your image size and eliminate shell-based CVE vectors. + + +3. **Keep Manifest Commands:** Don't trust the overwrite. +Continue using `docker manifest` in your pipeline to aggregate the lightning-fast, QEMU-free `linux-x64` and `linux-arm64` SDK builds into a single tag. + + +4. **Switch to Podman Agents:** Zero-config rootless builds. +Upgrade your self-hosted runners to Podman to immediately benefit from rootless container execution without updating build scripts. + +![5-checklist](./5-checklist.jpeg) \ No newline at end of file diff --git a/docs/en/Community-Articles/2026-09-17-NET-11-Container-Publishing/cover-image.jpeg b/docs/en/Community-Articles/2026-09-17-NET-11-Container-Publishing/cover-image.jpeg new file mode 100644 index 0000000000..8f56cfb27f Binary files /dev/null and b/docs/en/Community-Articles/2026-09-17-NET-11-Container-Publishing/cover-image.jpeg differ diff --git a/docs/en/Community-Articles/2026-09-17-net11-in-practice-fulljoin-async-validation-cache-metrics-tracing-rules/async-validation-pipeline.png b/docs/en/Community-Articles/2026-09-17-net11-in-practice-fulljoin-async-validation-cache-metrics-tracing-rules/async-validation-pipeline.png new file mode 100644 index 0000000000..b2f481c853 Binary files /dev/null and b/docs/en/Community-Articles/2026-09-17-net11-in-practice-fulljoin-async-validation-cache-metrics-tracing-rules/async-validation-pipeline.png differ diff --git a/docs/en/Community-Articles/2026-09-17-net11-in-practice-fulljoin-async-validation-cache-metrics-tracing-rules/join-family.png b/docs/en/Community-Articles/2026-09-17-net11-in-practice-fulljoin-async-validation-cache-metrics-tracing-rules/join-family.png new file mode 100644 index 0000000000..6a55344d89 Binary files /dev/null and b/docs/en/Community-Articles/2026-09-17-net11-in-practice-fulljoin-async-validation-cache-metrics-tracing-rules/join-family.png differ diff --git a/docs/en/Community-Articles/2026-09-17-net11-in-practice-fulljoin-async-validation-cache-metrics-tracing-rules/net-11-in practice-cover.png b/docs/en/Community-Articles/2026-09-17-net11-in-practice-fulljoin-async-validation-cache-metrics-tracing-rules/net-11-in practice-cover.png new file mode 100644 index 0000000000..b0a9d4a9d1 Binary files /dev/null and b/docs/en/Community-Articles/2026-09-17-net11-in-practice-fulljoin-async-validation-cache-metrics-tracing-rules/net-11-in practice-cover.png differ diff --git a/docs/en/Community-Articles/2026-09-17-net11-in-practice-fulljoin-async-validation-cache-metrics-tracing-rules/post.md b/docs/en/Community-Articles/2026-09-17-net11-in-practice-fulljoin-async-validation-cache-metrics-tracing-rules/post.md new file mode 100644 index 0000000000..6618feb22a --- /dev/null +++ b/docs/en/Community-Articles/2026-09-17-net11-in-practice-fulljoin-async-validation-cache-metrics-tracing-rules/post.md @@ -0,0 +1,512 @@ +Every .NET release ships a long list of changes. Most of them matter to library authors or to people chasing the last few percent of throughput. This article is about four changes in .NET 11 that show up in ordinary application code: a LINQ operator you have probably hand-rolled more than once, validation rules that can finally `await`, cache metrics you no longer have to write yourself, and a way to turn distributed tracing on and off from configuration. + +Each section covers the problem, the API, a runnable example with its output, and the caveats I hit while testing. Everything was run on .NET 11 RC1, and the complete sample application is on GitHub: [github.com/ahmetcelik05/dotnet11-features-demo](https://github.com/ahmetcelik05/dotnet11-features-demo). + +> **Where .NET 11 stands today.** .NET 11 RC1 shipped on September 8, 2026 with a go-live license. General availability is planned for November 10, 2026, and .NET 11 is a Standard Term Support (STS) release, supported until November 9, 2028. The APIs below are in RC1, but as you will see in the cache metrics section, details can still move before GA. + +Short on time? The whole article in one table: + +| Feature | What is new in .NET 11 | The catch I found on RC1 | +|---|---|---| +| LINQ joins | `FullJoin`, plus `Join`/`GroupJoin` overloads without a result selector | `GroupJoin` returns `IGrouping`, not a tuple; value-type `default` hides "no match" | +| Async validation | `AsyncValidationAttribute`, `IAsyncValidatableObject`, `Validator.*Async` | Synchronous `Validator` calls on the same model throw | +| Cache metrics | `MemoryCache` publishes an OpenTelemetry meter when `TrackStatistics` is on | The hit/miss tag name is being renamed before GA | +| Tracing rules | `AddTracing` with rules from code or configuration, live reload | Nothing is enabled by default, `Sample` is mandatory, OpenTelemetry is unaffected | + +## The sample application + +The sample is a small minimal API called `OrdersDemo`. It has no UI; you drive it with `curl` and watch the console. Each endpoint exists to demonstrate one feature, and the features also interact: placing an order runs async validation and then produces a traced activity. + +![Sample application architecture](sample-app-architecture.png) + +Each feature lives in its own folder under `Features` and registers itself through `Add...` and `Map...Endpoints` extensions, so `Program.cs` is only a composition root. + +## 1. LINQ `FullJoin` and selector-less `Join`/`GroupJoin` + +### The problem + +.NET 10 added `LeftJoin` and `RightJoin`. A full outer join was still missing, so if you needed "everything from both sides, matched where possible" you wrote a left join, a right join, and a `Concat` or `Union`, or a `GroupJoin`/`SelectMany`/`DefaultIfEmpty` combination in each direction. Most of us have a `FullOuterJoin` extension method somewhere in a `Utils` folder, copied from a Stack Overflow answer. It works, right up until a reconciliation report is wrong. + +A smaller annoyance: `Join` and `GroupJoin` always required a result selector. In most call sites that selector was `(a, b) => (a, b)`, typed for the hundredth time. + +### The API + +.NET 11 adds `FullJoin` and selector-less overloads of `Join` and `GroupJoin`. They exist on `Enumerable`, `Queryable`, and `AsyncEnumerable`. The new overloads take an optional `IEqualityComparer` as a trailing parameter, and the same optional comparer is available on `LeftJoin` and `RightJoin`. + +```csharp +// Full outer join, returning tuples +IEnumerable<(TOuter? Outer, TInner? Inner)> FullJoin( + this IEnumerable outer, IEnumerable inner, + Func outerKeySelector, Func innerKeySelector, + IEqualityComparer? comparer = null); + +// Full outer join with your own projection +IEnumerable FullJoin( + this IEnumerable outer, IEnumerable inner, + Func outerKeySelector, Func innerKeySelector, + Func resultSelector, + IEqualityComparer? comparer = null); +``` + +![Which rows each join returns](join-family.png) + +### Example: reconciling two stock systems + +The reconciliation endpoint compares stock levels reported by a warehouse and by an ERP system. A SKU can exist in either system or both, and when it exists in both the quantities may disagree. Three pair shapes, four statuses, one full outer join, and pattern matching on the tuple expresses all of it directly: + +```csharp +internal sealed class ReconciliationService : IReconciliationService +{ + public IReadOnlyList Reconcile(IEnumerable warehouse, IEnumerable erp) + { + var pairs = warehouse.FullJoin( + erp, + w => w.Sku, + e => e.Sku, + StringComparer.OrdinalIgnoreCase); + + return [.. pairs.Select(ToRow)]; + } + + private static ReconciliationRow ToRow((WarehouseStock? Warehouse, ErpStock? Erp) pair) => pair switch + { + (null, { } erp) => new ReconciliationRow(erp.Sku, ReconciliationStatus.MissingInWarehouse, null, erp.Quantity), + ({ } warehouse, null) => new ReconciliationRow(warehouse.Sku, ReconciliationStatus.MissingInErp, warehouse.Quantity, null), + ({ } warehouse, { } erp) when warehouse.Quantity != erp.Quantity + => new ReconciliationRow(warehouse.Sku, ReconciliationStatus.QuantityMismatch, warehouse.Quantity, erp.Quantity), + ({ } warehouse, { } erp) => new ReconciliationRow(warehouse.Sku, ReconciliationStatus.Ok, warehouse.Quantity, erp.Quantity), + (null, null) => throw new UnreachableException("FullJoin never yields an empty pair."), + }; +} +``` + +Calling `GET /reconciliation` with three warehouse rows (`LAPTOP-15`, `mouse-01`, `CHAIR-ERG`) and three ERP rows (`LAPTOP-15`, `MOUSE-01`, `DESK-STD`) returns four rows: + +```json +[ + { "sku": "LAPTOP-15", "status": "Ok", "warehouseQuantity": 5, "erpQuantity": 5 }, + { "sku": "mouse-01", "status": "QuantityMismatch", "warehouseQuantity": 0, "erpQuantity": 3 }, + { "sku": "CHAIR-ERG", "status": "MissingInErp", "warehouseQuantity": 7, "erpQuantity": null }, + { "sku": "DESK-STD", "status": "MissingInWarehouse", "warehouseQuantity": null, "erpQuantity": 2 } +] +``` + +Note the second row: `mouse-01` and `MOUSE-01` matched only because of the `StringComparer.OrdinalIgnoreCase` argument. Without it they would be two separate "missing" rows, which is exactly what happens in real life when two systems disagree on casing and nobody passes a comparer. + +### What the tests showed about the semantics + +The documentation describes the join operators but not their ordering or null behaviour, so I wrote tests against RC1 to pin down what you can observe today. + +Output order follows the outer sequence, with unmatched inner elements appended at the end: for `outer = [1, 2, 3]` and `inner = [3, 4, 2]`, `FullJoin` yields `(1, 0), (2, 2), (3, 3), (0, 4)`. Treat that as an implementation detail, not a guarantee. Null keys never match each other; a `null` key on either side produces an unmatched row, the same way `NULL = NULL` is false in SQL. + +Look at that `(1, 0)` again. It means "outer 1 had no partner", but `0` is also a perfectly valid inner value, and nothing in the tuple tells you which. When the element type is a struct, use nullable elements or the `resultSelector` overload so you can tell the two apart. + +One more surprise: the selector-less `GroupJoin` does not return tuples. The "What's new" page calls the new overloads "tuple-returning", which is true for `Join`, but `GroupJoin` returns `IEnumerable>` with the outer element as the `Key` and the matching inner elements as the group. + +```csharp +var grouped = customers + .GroupJoin(orders, c => c.Id, o => o.CustomerId) + .Select(group => (group.Key.Name, Count: group.Count())); +``` + +### When to use it + +Use `FullJoin` whenever you need a reconciliation, a diff, or a "who did not show up on the other list" report over two in-memory sequences. Keep the memory profile in mind: the inner sequence is fully materialised into a lookup, so put the smaller sequence on the inner side. Against a database, EF Core 11 translates `Queryable.FullJoin` to `FULL JOIN` on SQL Server. EF Core 11 is still in preview at the time of writing, so check the provider you use before relying on it. + +That covers combining data that is already in memory. The next feature is about the data on its way in: the order request that arrives at `POST /orders` and has to be checked against systems you can only reach asynchronously. + +## 2. Asynchronous validation with DataAnnotations + +### The problem + +`ValidationAttribute.IsValid` is synchronous. Rules that need I/O, such as "is this e-mail registered", "does this VAT number exist in the tax registry", or "is there enough stock", either blocked a thread with `.GetAwaiter().GetResult()` or moved out of the validation layer entirely. Once they move, their error messages no longer flow through `ValidationResult` and `ValidationProblemDetails`, and every consumer of the model has to remember to call them. You know the result: `[Required]` failures arrive as a tidy 400 with a field name, "customer not found" arrives as a 500 from the service layer, and the front-end team asks why. + +### The API + +.NET 11 adds an async path to `System.ComponentModel.DataAnnotations` with three pieces: + +- `AsyncValidationAttribute`, an abstract base class with `IsValidAsync(object?, ValidationContext, CancellationToken)` returning `Task`. +- `IAsyncValidatableObject`, with `ValidateAsync(ValidationContext, CancellationToken)` returning `IAsyncEnumerable`. +- Async counterparts on `Validator`: `ValidateObjectAsync`, `TryValidateObjectAsync`, `ValidatePropertyAsync`, `TryValidatePropertyAsync`, `ValidateValueAsync`, and `TryValidateValueAsync`. + +![The async validation pipeline](async-validation-pipeline.png) + +One design point matters before you write your first rule: the synchronous members are still required. `IsValid(object?, ValidationContext)` is abstract on `AsyncValidationAttribute`, and `IAsyncValidatableObject` inherits `IValidatableObject.Validate`. The framework samples throw from both so that accidental synchronous validation fails loudly instead of silently skipping the rule, and that is the approach I take below. + +### Example: an async attribute and an async object rule + +The order request in the sample uses both mechanisms. The attribute checks that the customer exists in a directory: + +```csharp +[AttributeUsage(AttributeTargets.Property)] +public sealed class RegisteredCustomerAttribute : AsyncValidationAttribute +{ + protected override ValidationResult? IsValid(object? value, ValidationContext validationContext) => + throw new InvalidOperationException( + $"{nameof(RegisteredCustomerAttribute)} only supports asynchronous validation. Use Validator.ValidateObjectAsync."); + + protected override async Task IsValidAsync( + object? value, ValidationContext validationContext, CancellationToken cancellationToken) + { + if (value is not string email || string.IsNullOrWhiteSpace(email)) + { + return ValidationResult.Success; // [Required] owns the empty-value case + } + + var directory = validationContext.GetRequiredService(); + + return await directory.ExistsAsync(email, cancellationToken) + ? ValidationResult.Success + : new ValidationResult($"'{email}' is not a registered customer.", [validationContext.MemberName!]); + } +} +``` + +The model itself checks stock for every line, a rule that spans properties: + +```csharp +public sealed class CreateOrderRequest : IAsyncValidatableObject +{ + [Required, EmailAddress, RegisteredCustomer] + public string CustomerEmail { get; init; } = string.Empty; + + [MinLength(1)] + public IReadOnlyList Lines { get; init; } = []; + + public IEnumerable Validate(ValidationContext validationContext) => + throw new InvalidOperationException($"Validate {nameof(CreateOrderRequest)} with {nameof(ValidateAsync)}."); + + public async IAsyncEnumerable ValidateAsync( + ValidationContext validationContext, + [EnumeratorCancellation] CancellationToken cancellationToken = default) + { + var inventory = validationContext.GetRequiredService(); + + foreach (var line in Lines) + { + var available = await inventory.GetAvailableQuantityAsync(line.Sku, cancellationToken); + if (available < line.Quantity) + { + yield return new ValidationResult( + $"Only {available} unit(s) of '{line.Sku}' are in stock.", [nameof(Lines)]); + } + } + } +} +``` + +Both rules resolve their dependencies from the `ValidationContext`, which means the context has to be created with a service provider. Minimal APIs do that for you; when you call `Validator` yourself, pass one in: + +```csharp +var context = new ValidationContext(request, serviceProvider, items: null); +var results = new List(); + +var isValid = await Validator.TryValidateObjectAsync( + request, context, results, validateAllProperties: true, cancellationToken); +``` + +### Running it through a minimal API + +`builder.Services.AddValidation()` has been available since .NET 10; it makes minimal API endpoints validate their parameters before the handler runs. What is new in .NET 11 is that the same call now runs the async rules as well, concurrently where possible. Posting an unknown customer: + +```bash +curl -X POST http://localhost:5028/orders -H "Content-Type: application/json" \ + -d '{"customerEmail":"nobody@example.com","lines":[{"sku":"MOUSE-01","quantity":2}]}' +``` + +```json +{ + "title": "One or more validation errors occurred.", + "status": 400, + "errors": { "CustomerEmail": ["'nobody@example.com' is not a registered customer."] } +} +``` + +Only the attribute error is reported. That is by design: object-level validation runs after all property rules pass, so the stock check never executed. Post the same order with a registered customer and you get the object-level message instead: + +```json +{ + "title": "One or more validation errors occurred.", + "status": 400, + "errors": { "Lines": ["Only 0 unit(s) of 'MOUSE-01' are in stock."] } +} +``` + +### How the pipeline behaves + +From reading `Validator` and confirming with tests, the async path works like this: + +1. `[Required]` is evaluated first for each property and short-circuits that property on failure. +2. Synchronous attributes on a property run next. Async attributes run only if all synchronous ones pass, and they run concurrently. +3. Type-level attributes follow, then `IAsyncValidatableObject.ValidateAsync`. +4. Pass `null` for the results collection and validation stops at the first failure; pass a collection and it keeps going and collects everything. +5. The cancellation token flows into every async rule. + +### The migration trap + +So what happens when an older code path calls the synchronous `Validator.TryValidateObject` on a model that now carries an async attribute? Does it quietly skip the rule? No. It has no special handling for async attributes at all: it calls your synchronous `IsValid`, and if you followed the framework guidance, that throws: + +``` +System.InvalidOperationException: RegisteredCustomerAttribute only supports asynchronous validation. Use Validator.ValidateObjectAsync. +``` + +On purpose, and rightly so. But it makes adding an async attribute a breaking change for every caller that still validates synchronously, so find those callers before you decorate a shared model. Minimal APIs and Blazor forms use the async path in .NET 11; MVC controllers are not listed in the RC1 notes and the public design notes defer them to follow-up work, so treat MVC as a synchronous caller until the docs say otherwise. + +Validation decides whether a request gets in. The next two features are about seeing what the application does once it is in, starting with the cache that every request touches. + +## 3. Built-in OpenTelemetry metrics for `MemoryCache` + +### The problem + +`IMemoryCache` has had `GetCurrentStatistics()` for a while, but turning it into metrics meant polling it and publishing your own `Meter`. Every team wrote a slightly different decorator, and none of them agreed on instrument names. The decorator then quietly stopped being registered after a refactor, and the "cache hit ratio" panel on the dashboard showed a flat line for three weeks before anyone noticed. + +### The API + +Do you need an extra package or an adapter for this? No. In .NET 11, `MemoryCache` publishes a meter named `Microsoft.Extensions.Caching.Memory.MemoryCache` as soon as you opt in with `TrackStatistics = true`. The new `MemoryCacheOptions.Name` becomes a `dotnet.cache.name` tag so that multiple caches can share a process, and a new constructor overload accepts an `IMeterFactory` for per-instance meters. `MemoryCacheStatistics` gained `TotalEvictions` to back the new eviction counter. + +RC1 publishes these four instruments, captured with a `MeterListener` in the test suite: + +| Instrument | Type | Unit | Tags | +|---|---|---|---| +| `dotnet.cache.requests` | ObservableCounter | `{request}` | `dotnet.cache.request.type` = `hit` / `miss` | +| `dotnet.cache.evictions` | ObservableCounter | `{eviction}` | | +| `dotnet.cache.entries` | ObservableUpDownCounter | `{entry}` | | +| `dotnet.cache.estimated_size` | ObservableGauge | `By` | | + +### Example: a read-through product catalog + +In most applications the opt-in is a one-liner: `services.AddMemoryCache(options => options.TrackStatistics = true)`. In the demo the cache is configured through an `IConfigureOptions` instead, so that the demo-specific settings live next to the feature: + +```csharp +public void Configure(MemoryCacheOptions options) +{ + options.TrackStatistics = true; // opt-in: without this no instruments are published + options.Name = CacheName; // becomes the dotnet.cache.name tag + options.SizeLimit = productCache.Value.SizeLimit; + options.CompactionPercentage = productCache.Value.CompactionPercentage; +} +``` + +```csharp +internal sealed class CachedProductCatalog(IMemoryCache cache, IProductStore store) : IProductCatalog +{ + public Task GetAsync(string sku, CancellationToken cancellationToken) => + cache.GetOrCreateAsync(sku, entry => + { + entry.SetSize(1); // required when MemoryCacheOptions.SizeLimit is set + entry.SetSlidingExpiration(TimeSpan.FromMinutes(5)); + return store.FindAsync(sku, cancellationToken); + }); +} +``` + +To export the meter, add it to your OpenTelemetry metrics pipeline: + +```csharp +services.AddOpenTelemetry() + .WithMetrics(metrics => metrics + .AddMeter("Microsoft.Extensions.Caching.Memory.MemoryCache") + .AddConsoleExporter()); +``` + +After five requests for `LAPTOP-15` and one each for three other SKUs, the console exporter prints: + +``` +Metric Name: dotnet.cache.requests, Description: Total cache requests., Unit: {request}, Metric Type: LongSum +(...) dotnet.cache.name: products dotnet.cache.request.type: hit Value: 4 +(...) dotnet.cache.name: products dotnet.cache.request.type: miss Value: 4 + +Metric Name: dotnet.cache.evictions, Description: Total cache evictions., Unit: {eviction}, Metric Type: LongSum +(...) dotnet.cache.name: products Value: 1 + +Metric Name: dotnet.cache.entries, Description: Current number of cache entries., Unit: {entry}, Metric Type: LongSumNonMonotonic +(...) dotnet.cache.name: products Value: 2 + +Metric Name: dotnet.cache.estimated_size, Description: Estimated size of the cache., Unit: By, Metric Type: LongGauge +(...) dotnet.cache.name: products Value: 2 +``` + +Four misses (one per SKU), four hits, and one eviction because the size limit is three. The hit ratio is `hit / (hit + miss)`, which you can compute in any backend that supports the tag. + +A detail that cost me a few minutes (and a brief, unfair suspicion of the runtime): with the default `CompactionPercentage` of 5 %, a three-entry cache never evicts anything; it just refuses the fourth entry. The demo uses 50 % so the counter moves; real caches are large enough that the default is fine. + +### Caveats + +- **The tag name is changing.** RC1 emits `dotnet.cache.request.type` and unit `By`; the `release/11.0` branch already has `dotnet.cache.request.result` and unit `1`, because `SizeLimit` is an application-defined number, not bytes. Re-check any dashboard or alert that references the tag at GA. +- **`TrackStatistics` is not free.** It adds interlocked increments on every hit and miss. That is cheap, but measure it on a hot cache before enabling it everywhere. +- **All four instruments are observable.** The hot path only increments the counters it already kept for `GetCurrentStatistics()`; values are read when a collector asks. `MeterListener` users therefore have to call `RecordObservableInstruments()`. The same release moved the HTTP `open_connections` and `active_requests` metrics to observable instruments, so this applies to more than the cache. + +Metrics tell you how often the cache is hit. They do not tell you what a single slow order did along the way. For that you need traces, and the last feature is about deciding which traces you actually want, without a redeploy. + +## 4. Declarative `Activity` tracing rules + +### The problem + +`ActivitySource.StartActivity` returns `null` unless some `ActivityListener` has said it is interested in that source. Deciding which sources are interesting has always happened in code: either an `ActivityListener` with a `ShouldListenTo` callback, or OpenTelemetry's `AddSource`. Changing the decision meant a redeploy. If you have ever watched a noisy health-check span flood a trace backend because nobody could turn it off in production, you know the feeling. Logging solved the equivalent problem years ago with `Logging:LogLevel` in `appsettings.json`, and metrics got `MetricsBuilder.EnableMetrics` in .NET 8. Tracing had nothing. + +### The API + +`Microsoft.Extensions.Diagnostics` in .NET 11 adds a tracing builder with the same shape as the metrics one: + +```csharp +services.AddTracing(tracing => +{ + tracing.AddListener("console", listener => { /* ActivityListenerBuilder */ }); + tracing.EnableTracing(sourceName: "OrdersDemo.Orders"); + tracing.DisableTracing(sourceName: "OrdersDemo.Orders", operationName: "HealthCheck"); + tracing.AddConfiguration(configuration.GetSection("Tracing")); +}); +``` + +- `AddListener(name, configure)` registers a named `ActivityListener`. The `ActivityListenerBuilder` exposes `Sample`, `SampleUsingParentId`, `ActivityStarted`, `ActivityStopped`, and `ExceptionRecorder`. +- `EnableTracing` / `DisableTracing` add a `TracingRule`. `sourceName` is an exact name, a prefix, or a pattern with a single `*`; `operationName` and `listenerName` are exact matches; `null` matches everything. +- `AddConfiguration` reads rules from an `IConfiguration` section and re-applies them when the configuration reloads. +- The same release adds `ActivitySourceFactory` for creating sources through DI and unseals `ActivitySource`. + +![How rules, listeners and sources fit together](tracing-rules.png) + +The configuration shape mirrors logging. This is the sample's `appsettings.json`: + +```json +{ + "Tracing": { + "EnabledTracing": { + "OrdersDemo.Orders": { + "Default": true, + "HealthCheck": false + } + } + } +} +``` + +`EnabledTracing` applies to all listeners; `EnabledGlobalTracing` and `EnabledLocalTracing` target only sources created with `new ActivitySource(...)` or through `ActivitySourceFactory`, respectively; any other key under `Tracing` is a listener name with its own nested block. Inside a source, `Default` is the source-level rule, every other key is an operation name, and a bare boolean (`"OrdersDemo.*": true`) is shorthand for `Default`. + +### Example: a console listener driven by configuration + +In the demo there is one named listener, registered with `AddListener`, and the rules come from `AddConfiguration` alone, no code-based rules. The listener itself: + +```csharp +internal static class ConsoleActivityListener +{ + public const string Name = "console"; + + public static void Configure(ActivityListenerBuilder listener) + { + // The rules API makes no sampling decision for you: without Sample, StartActivity returns null. + listener.Sample = static (ref _) => ActivitySamplingResult.AllDataAndRecorded; + listener.ActivityStopped = Print; + } + + private static void Print(Activity activity) + { + // Activity.Tags only yields string-valued tags; TagObjects includes numbers such as order.lines. + var tags = string.Join(' ', activity.TagObjects.Select(tag => $"{tag.Key}={tag.Value}")); + Console.WriteLine($"[trace] {activity.Source.Name}/{activity.OperationName} {activity.Duration.TotalMilliseconds:F1} ms {tags}"); + } +} +``` + +`OrderService` creates its source through `ActivitySourceFactory` and starts two activities, `PlaceOrder` and `HealthCheck`: + +```csharp +private readonly ActivitySource _activitySource = + activitySourceFactory.Create(new ActivitySourceOptions("OrdersDemo.Orders")); + +// in PlaceOrderAsync +using var activity = _activitySource.StartActivity("PlaceOrder"); // enabled by rule + +// in CheckHealthAsync +using var activity = _activitySource.StartActivity("HealthCheck"); // disabled by rule +``` + +Place an order and call the health endpoint. Only the order shows up: + +``` +[trace] OrdersDemo.Orders/PlaceOrder 10.2 ms order.customer=ada@example.com order.lines=1 order.id=ORD-6067 +``` + +Now change `"HealthCheck": false` to `true` in `appsettings.json` while the app is running. The configuration reloads, the listener refreshes its filters, and the next two health calls print: + +``` +[trace] OrdersDemo.Orders/HealthCheck 16.0 ms +[trace] OrdersDemo.Orders/HealthCheck 6.6 ms +``` + +Set it back to `false` and the lines stop. No restart, no redeploy. + +### What I learned by running it + +The documentation for this feature is currently one paragraph and a five-line snippet, so most of the following comes from the source and from tests: + +- **Nothing is enabled by default.** `AddTracing()` without rules enables no source. +- **You must set `Sample`.** A listener without a sampling callback never records anything, and `StartActivity` returns `null` for its sources. The snippet in the release notes omits this, which is why my first attempt produced no output at all. +- **Listeners activate when the host starts.** Rules are wired up during `IHost.StartAsync` (or when `ActivitySourceFactory` is first resolved). Building the service provider is not enough, which matters for tests and for tools that never start a host. +- **Rules cover sources created with `new ActivitySource(...)` too.** Those are "global" scope; factory-created sources are "local". A rule for `Legacy.*` picks up activities from a plain `new ActivitySource("Legacy.Billing")`. +- **Rules resolve like CSS selectors.** The most specific one wins: a listener name beats none, a longer source pattern beats a shorter one, an operation name beats none. Between equally specific rules the last one registered wins; avoid overlapping rules rather than relying on that. + +### Rules and OpenTelemetry + +The question everyone asks first: does `AddTracing` replace OpenTelemetry's `AddSource`? No. OpenTelemetry registers its own `ActivityListener`, and the rules only govern listeners registered through `AddTracing`. I confirmed this with an OpenTelemetry `TracerProvider` and a rule that disables `HealthCheck`: OpenTelemetry still received `HealthCheck`, and the rule-driven listener did not. + +There is one interaction worth knowing about. ASP.NET Core's hosting layer creates a request activity even when no listener samples it, so that parent is unrecorded, and OpenTelemetry's default `ParentBased(AlwaysOn)` sampler follows the parent and drops the child spans. Sampling decisions are combined across listeners with the most permissive winning, so in my first run the rule-driven listener's `AllDataAndRecorded` decision is what got `PlaceOrder` exported, while `HealthCheck` looked as if the rule had suppressed it in OpenTelemetry too. It had not; the sampler had. The demo uses `SetSampler(new AlwaysOnSampler())` to keep the two mechanisms independent; in production, ASP.NET Core instrumentation samples the parent properly. + +So where does this API fit? Use it for listeners you own: a console or file listener for local debugging, an in-process collector, a diagnostic listener you want operators to toggle in a running service. Keep your OpenTelemetry pipeline as it is. + +Four features down. Here is how to run the application and the tests behind them yourself. + +## Running the sample + +The repository pins the SDK in `global.json` (`11.0.100-rc.1.26425.128`); the README shows how to install RC1 into a private folder without making it your machine's default SDK. Then, from the repository root: + +```bash +dotnet test +dotnet run --project src/OrdersDemo # listens on http://localhost:5028 (from launchSettings.json) +``` + +The test project uses xUnit v3 on Microsoft.Testing.Platform, and the run I used for this article looked like this: + +``` +OrdersDemo.Tests.dll (net11.0|x64) passed [+28/x0/?0] (1s 461ms) +Test run summary: Passed! + failed: 0 + skipped: 0 + duration: 1s 896ms +``` + +Every observed behaviour listed in the feature sections above is backed by a test with a matching name. + +## Preview and RC caveats + +- **RC1 is go-live, not GA.** Names and units can still change; the cache tag rename (`request.type` → `request.result`, unit `By` → `1`) is already merged for release/11.0. +- **Async validation in MVC controllers** is not covered by the RC1 documentation; assume synchronous validation there. +- **Tracing rules have minimal documentation.** The behaviours above were verified against RC1 source and tests, not a specification; re-verify against the GA docs. EF Core 11's `FullJoin` translation is likewise still in preview. + +## Adoption checklist + +1. Target `net11.0`, pin the SDK in `global.json` with `rollForward: latestFeature`. +2. Replace hand-written full outer joins with `FullJoin`; test null keys and decide how value types represent "no match". +3. Convert `(a, b) => (a, b)` selectors to the selector-less `Join`/`GroupJoin` overloads; remember `GroupJoin` returns `IGrouping`. +4. Move I/O-bound rules to `AsyncValidationAttribute` or `IAsyncValidatableObject`; decide whether the synchronous members throw or fall back. +5. Find every synchronous caller of those models (`Validator.*`, MVC model binding, custom pipelines) and switch it, or keep async attributes off shared models. +6. Call `AddValidation()` in minimal API projects and pass `HttpContext.RequestAborted` through. +7. Enable `TrackStatistics`, set `MemoryCacheOptions.Name`, add the meter to OpenTelemetry, build a hit-ratio panel; re-check the tag name at GA. +8. If you use `MeterListener`, call `RecordObservableInstruments()` on your collection interval. +9. Move custom `ActivityListener` code to `AddTracing` with a named listener and a `Tracing` section; always set `Sample`; leave OpenTelemetry's `AddSource` alone. +10. Prefer `ActivitySourceFactory` over static `ActivitySource` fields in new code. + +## Closing thoughts + +None of these four features will headline the .NET 11 launch keynote, and that is exactly why they are worth knowing: they are the changes you will use on a Tuesday afternoon, not the ones you will benchmark. Good luck with the upgrade, keep the tests from this article close, and treat every "it obviously works like this" moment with a little suspicion until GA. Hit a surprise I did not cover? The sample repository is the place to open an issue. + +## References + +- [What's new in .NET 11](https://learn.microsoft.com/en-us/dotnet/core/whats-new/dotnet-11/overview) +- [What's new in .NET libraries for .NET 11](https://learn.microsoft.com/en-us/dotnet/core/whats-new/dotnet-11/libraries) (LINQ joins, async validation, cache metrics, tracing configuration) +- [What's new in ASP.NET Core for .NET 11](https://learn.microsoft.com/en-us/aspnet/core/release-notes/aspnetcore-11) (async validation in minimal APIs and Blazor) +- [.NET diagnostics overview](https://learn.microsoft.com/en-us/dotnet/core/diagnostics/) and [Collect a distributed trace](https://learn.microsoft.com/en-us/dotnet/core/diagnostics/distributed-tracing-collection-walkthroughs) +- [Announcing .NET 11 Release Candidate 1](https://devblogs.microsoft.com/dotnet/dotnet-11-rc-1/) +- [dotnet/runtime #100317: Tracing configuration API proposal](https://github.com/dotnet/runtime/issues/100317) and [PR #129380](https://github.com/dotnet/runtime/pull/129380) +- [dotnet/runtime #124140: Metrics for MemoryCache API proposal](https://github.com/dotnet/runtime/issues/124140) and [PR #133151: tag and unit fix](https://github.com/dotnet/runtime/pull/133151) +- [Async validation design notes (dotnet/aspnetcore)](https://gist.github.com/halter73/f4d0974da579fb78d17bd2e6d9f78173) (MVC support deferred) +- [What's new in EF Core 11](https://learn.microsoft.com/en-us/ef/core/what-is-new/ef-core-11.0/whatsnew) (FullJoin translation) diff --git a/docs/en/Community-Articles/2026-09-17-net11-in-practice-fulljoin-async-validation-cache-metrics-tracing-rules/sample-app-architecture.png b/docs/en/Community-Articles/2026-09-17-net11-in-practice-fulljoin-async-validation-cache-metrics-tracing-rules/sample-app-architecture.png new file mode 100644 index 0000000000..1b759465ea Binary files /dev/null and b/docs/en/Community-Articles/2026-09-17-net11-in-practice-fulljoin-async-validation-cache-metrics-tracing-rules/sample-app-architecture.png differ diff --git a/docs/en/Community-Articles/2026-09-17-net11-in-practice-fulljoin-async-validation-cache-metrics-tracing-rules/tracing-rules.png b/docs/en/Community-Articles/2026-09-17-net11-in-practice-fulljoin-async-validation-cache-metrics-tracing-rules/tracing-rules.png new file mode 100644 index 0000000000..b4a4517685 Binary files /dev/null and b/docs/en/Community-Articles/2026-09-17-net11-in-practice-fulljoin-async-validation-cache-metrics-tracing-rules/tracing-rules.png differ diff --git a/docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/ARTICLE.md b/docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/ARTICLE.md new file mode 100644 index 0000000000..c75e7795b5 --- /dev/null +++ b/docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/ARTICLE.md @@ -0,0 +1,516 @@ +# .NET 11 Runtime Async: Cleaner Stack Traces and Faster Async Paths + +## Introduction + +Asynchronous code is everywhere in a modern .NET application. + +An HTTP endpoint awaits an application service. The application service awaits a repository. The repository awaits a database call. Logging, authorization, retries, serialization, and network operations add more asynchronous layers around the same request. + +The C# code can still look simple: + +```csharp +public async Task GetAsync(Guid id) +{ + Order order = await _orderRepository.GetAsync(id); + return ObjectMapper.Map(order); +} +``` + +However, the implementation below `async` and `await` has not been simple. In .NET 10 and earlier versions, the C# compiler normally turns each async method into a generated state machine. This design works well, but it can add infrastructure frames to live call stacks, create intermediate task-related objects, and make production profiling more difficult. + +.NET 11 starts changing that foundation with **Runtime Async V2**. + +The source code and the async programming model do not change. The important change happens below the source code: more of the async transformation moves from the C# compiler into the runtime and the JIT compiler. This gives .NET more information at the moment it optimizes the method. + +For developers, the main results are: + +- Cleaner live async stack traces. +- Better stepping and debugging through async code. +- Opportunities to remove intermediate `Task` objects and allocations. +- Smaller generated IL for eligible async methods. +- Better optimization of common async paths. +- A new lower-overhead foundation for async profiling. + +This article explains what changed, where you can observe the difference, how to measure it, and what you should consider before enabling the preview feature in a real application. + +## The main change: async lowering moves closer to the runtime + +Consider this small method: + +```csharp +static async Task ReadLengthAsync( + Stream stream, + CancellationToken cancellationToken) +{ + var buffer = new byte[4096]; + int bytesRead = await stream.ReadAsync(buffer, cancellationToken); + return bytesRead; +} +``` + +With the classic model, the C# compiler creates a state-machine type. It usually contains: + +- A state number. +- An async method builder. +- Fields for parameters and local values that must survive an incomplete `await`. +- Awaiter fields. +- A generated `MoveNext()` method. + +`MoveNext()` runs the method until an awaited operation is incomplete. It saves the required state and registers itself as the continuation. Later, it runs again and continues from the saved state. + +Runtime and JIT optimizations have made this model much cheaper over many .NET releases. Still, by the time the JIT receives the method, the compiler has already expanded a small source method into a more complex state machine. + +![Classic compiler lowering compared with .NET 11 Runtime Async](assets/runtime-async-architecture.png) + +With Runtime Async, the compiler emits smaller, suspension-aware IL and marks the method as async in metadata. The runtime and JIT then manage more of the transformation. They can use runtime information to decide: + +- Which values are really alive at a suspension point. +- How continuation state should be stored. +- Whether an intermediate `Task` must be materialized. +- Whether a direct async call can use a more efficient calling path. +- How the method should be optimized after it becomes hot. + +The programming model remains the same. `await`, cancellation, exceptions, synchronous completion, and `ConfigureAwait` keep their existing meaning. Microsoft states that behavioral compatibility is an explicit goal; an observable semantic difference should be treated as a bug. + +### Enabling Runtime Async in a .NET 11 project + +Application code must currently opt in: + +```xml + + net11.0 + $(Features);runtime-async=on + +``` + +No new C# syntax is required. You do not need `LangVersion=preview` or `EnablePreviewFeatures` for this switch in a `net11.0` project. + +The .NET 11 runtime libraries are already compiled with Runtime Async enabled. Your own application and library methods use the new lowering only when you enable the feature during compilation. + +## Cleaner live async stack traces + +The clearest developer-experience improvement is visible in a **live stack trace**. + +This means the stack shown by: + +- The debugger Call Stack window. +- `new StackTrace()` while the code is running. +- A profiler that inspects live execution stacks. +- Diagnostic code that captures the current stack. + +### Runnable example + +The complete project is included in `samples/AsyncStackTraceDemo`. Its important part is: + +```csharp +using System.Diagnostics; + +await OuterAsync(); + +static async Task OuterAsync() +{ + await Task.CompletedTask; + await MiddleAsync(); +} + +static async Task MiddleAsync() +{ + await Task.CompletedTask; + await InnerAsync(); +} + +static async Task InnerAsync() +{ + await Task.CompletedTask; + Console.WriteLine(new StackTrace(fNeedFileInfo: true)); +} +``` + +The included script builds three variants: + +1. .NET 10 with compiler-generated async lowering. +2. .NET 11 with compiler-generated async lowering. +3. .NET 11 with Runtime Async enabled. + +On PowerShell: + +```powershell +./scripts/run-samples.ps1 +``` + +On Bash: + +```bash +chmod +x ./scripts/run-samples.sh +./scripts/run-samples.sh +``` + +### Observed output + +The .NET 10 and .NET 11 classic builds both produced 13 live frames. The output included repeated infrastructure frames similar to: + +```text +InnerAsync() +AsyncMethodBuilderCore.Start(...) +InnerAsync() +MiddleAsync() +AsyncMethodBuilderCore.Start(...) +MiddleAsync() +OuterAsync() +AsyncMethodBuilderCore.Start(...) +OuterAsync() +Main() +AsyncMethodBuilderCore.Start(...) +Main() +Main(string[] args) +``` + +The Runtime Async build produced 5 frames: + +```text +InnerAsync() +MiddleAsync() +OuterAsync() +Main() +Main(string[] args) +``` + +![Live stack trace comparison: 13 classic frames and 5 Runtime Async frames](assets/live-stack-comparison.png) + +The exact generated method names can differ between source layout, SDK builds, and Debug or Release configuration. The useful result is the shape of the stack: Runtime Async shows the application call chain directly and removes the repeated async builder infrastructure from this example. + +### Important: this is a live-stack improvement + +Do not describe this feature as a general fix for `exception.StackTrace`. + +Exception stack traces from code such as the following were already cleaned up by the existing async infrastructure: + +```csharp +try +{ + await ProcessAsync(); +} +catch (Exception exception) +{ + Console.WriteLine(exception.StackTrace); +} +``` + +The .NET 11 improvement is most visible while inspecting **live execution**, not after catching an exception. + +## Where the performance opportunities come from + +Runtime Async does not make every async operation faster and it does not remove every allocation. It gives the runtime new opportunities that were difficult to see after the compiler had already created a state machine. + +### 1. Fewer intermediate Task objects + +Consider a common layered call chain: + +```csharp +static async Task A() => await B(); +static async Task B() => await C(); + +static async Task C() +{ + await Task.Yield(); + return 42; +} +``` + +In the classic model, every method has its own transformed state and task-like result. When the pattern is a direct call followed by a direct `await`, Runtime Async can sometimes use a special async calling path and link continuation state instead. + +If the chain completes synchronously, the result can flow through internal calls as a value. If it suspends, the runtime can link continuation records without requiring a separate intermediate `Task` at every eligible edge. + +![How Runtime Async can avoid some intermediate Task objects](assets/task-materialization.png) + +The optimization is not possible when the `Task` is observable as an object. For example: + +```csharp +Task task = GetValueAsync(); +pendingTasks.Add(task); +task.ContinueWith(LogCompletion); +return task; +``` + +Here, the program stores and manually observes the task. The runtime must preserve that behavior and materialize the object. + +### 2. Smaller generated IL and binaries + +The classic transformation creates an entry method, a generated type, state fields, a builder, and `MoveNext()` for each async method. + +Runtime Async leaves a smaller method body for the runtime to transform. In a deliberately async-heavy size test published by Microsoft, ten small async methods produced these assembly sizes: + +| Lowering | Assembly size | +|---|---:| +| Compiler-generated | 10,752 bytes | +| Runtime Async | 5,632 bytes | + +This is not a promise that a complete application will become 48% smaller. The test was intentionally dominated by small async methods. The useful conclusion is that Runtime Async can reduce the per-method IL and metadata cost. + +### 3. Better exception flow through deep async chains + +Classic async state machines normally contain generated exception handling so that an unhandled exception can be stored in the returned task. + +In a deep chain, an exception can be: + +1. Caught by generated code in the inner method. +2. Stored in its task. +3. Read and thrown again by the caller's awaiter. +4. Caught by the caller's generated code. +5. Stored in another task. + +Runtime Async can move through continuation records that have no real user exception handler and fault the observable root task more directly. This can reduce repeated throw, catch, and task-fault work in deep pass-through chains. + +This optimization does not make exceptions a normal or recommended control-flow mechanism. It only makes the runtime-generated path less expensive where possible. + +### 4. Skipping unnecessary ExecutionContext work + +`ExecutionContext` carries ambient state across async boundaries. `AsyncLocal` values are a common example. Tracing and request-correlation systems can also use ambient state. + +.NET 11 can detect when a continuation has no context state to restore and skip an unnecessary capture-and-restore cycle. `Task`, `Task`, `ValueTask`, and `ValueTask` paths can benefit. + +The effect is workload-dependent. A high-throughput library path with little ambient state may benefit more than an ASP.NET Core request path that uses `Activity`, tracing, and several `AsyncLocal` values. + +### 5. JIT improvements for async paths + +.NET 11 also improves several details around Runtime Async: + +- Runtime Async methods participate in tiered compilation, so hot methods can receive Tier 1 optimizations. +- The JIT recognizes common factories such as `Task.CompletedTask`, `Task.FromResult`, and `ValueTask.FromResult`. +- Suspension points can be tail-merged to reduce generated code size. +- Some continuation objects can be cached and reused. +- Direct tail-await paths can avoid unnecessary layers. +- Runtime Async supports ReadyToRun and NativeAOT scenarios. +- ReadyToRun compilation can inline eligible await-less Runtime Async calls. + +These are implementation improvements. Application code should continue to choose `Task` or `ValueTask` based on API semantics and measured needs, not because Runtime Async exists. + +## A reproducible benchmark + +The package includes `benchmarks/AsyncPathBenchmarks`. It compares classic and Runtime Async lowering inside the same .NET 11 process. This isolates the lowering strategy better than comparing a .NET 10 process with a .NET 11 process, where many other runtime changes would also affect the result. + +The benchmark uses a compiler-recognized `RuntimeAsyncMethodGenerationAttribute` to force classic lowering for selected methods. This attribute is experimental and is **not a public .NET API**. Use it only for controlled experiments like this one. + +Run it with: + +```bash +dotnet run \ + --project benchmarks/AsyncPathBenchmarks/AsyncPathBenchmarks.csproj \ + -c Release \ + --filter "*" +``` + +The included job performs 3 warm-up iterations and 10 measurement iterations. For serious performance work, increase the iteration count and run on a quiet, dedicated machine. + +### Results from the included run + +Test environment: + +- Ubuntu 24.04.3 LTS. +- Intel Xeon Platinum 8573C, with 9 logical cores available to the container. +- .NET SDK `11.0.100-rc.1.26425.128`. +- .NET runtime `11.0.0-rc.1.26425.128`. +- BenchmarkDotNet `0.16.0-preview.1`. +- Release configuration and Workstation GC. + +| Method | Mean | Ratio | Allocated | +|---|---:|---:|---:| +| ClassicCompleted | 84.99 ns | 1.00 | 144 B | +| RuntimeCompleted | 15.83 ns | 0.20 | 0 B | +| ClassicYielding | 678.15 ns | 1.00 | 248 B | +| RuntimeYielding | 314.50 ns | 0.46 | 168 B | + +![Benchmark results from the included .NET 11 RC1 run](assets/benchmark-results.png) + +These values are **not a general performance claim**. The benchmark ran in a shared container, could not raise process priority, and the `ClassicCompleted` measurements had high variance. The full BenchmarkDotNet report is included in `results/benchmark-results.md`. + +The results demonstrate how to measure the feature and show clear allocation differences in this small pattern. They do not tell us how much faster an ABP application, API endpoint, or database operation will become. + +Microsoft's own benchmark of the same two-layer pattern also showed lower time and allocation for Runtime Async, but with different absolute numbers. That difference is exactly why you should run the benchmark on your hardware and then measure a realistic application workload. + +### Benchmark hygiene + +Runtime Async is a compile-time feature. When switching the feature on and off in the same project, force a rebuild. Otherwise, an incremental build can leave an assembly from the previous configuration in the output directory. + +The included scripts use `--no-incremental` for this reason. + +For a fair application benchmark: + +- Use Release builds. +- Pin the SDK and runtime versions. +- Record OS, CPU, GC mode, and application configuration. +- Warm up tiered compilation before recording steady-state throughput. +- Measure latency percentiles, CPU, and allocations—not only requests per second. +- Run several independent processes or test rounds. +- Compare the same commit with only the Runtime Async switch changed. +- Test with your real third-party libraries and normal observability configuration. + +## Where should the difference be visible? + +Runtime Async has the best opportunity in code with many small async layers: + +```text +HTTP endpoint + → application service + → authorization helper + → retry or policy layer + → repository + → database or network operation +``` + +Possible observable effects include: + +- Fewer managed allocations per request. +- Lower GC pressure at high request rates. +- Better throughput on async-heavy CPU paths. +- Smaller application or library assemblies. +- Cleaner debugger and profiler stacks. + +The difference may be difficult to see when: + +- Most request time is spent waiting for a slow database or remote API. +- The async call chain is shallow. +- Tasks are stored or otherwise observed as objects. +- Much of the hot path is in older third-party assemblies compiled with classic lowering. +- Tracing, logging, or `AsyncLocal` usage requires ambient context flow. +- The application is limited by database capacity, locks, serialization, or network bandwidth. + +A 100-millisecond database query can easily hide a small runtime improvement in end-to-end request latency. The same improvement may still appear in allocation rate, CPU use, or maximum throughput under load. + +## Investigating async behavior in production + +Production async problems usually appear as one of these symptoms: + +- High latency but low CPU usage. +- Thread-pool queue growth. +- Unexpected allocation or GC pressure. +- Time spent in continuations or framework infrastructure. +- A request that starts on one thread and continues on another. + +The last case is especially important. When an async method suspends, its physical thread stack unwinds. The continuation can later resume on a different thread. + +![Physical thread stacks compared with a logical async call chain](assets/physical-logical-async.png) + +A normal sampling profiler can see the code currently running on Thread 27, but the earlier physical stack from Thread 12 is gone. An async-aware profiler needs runtime events to rebuild the logical chain. + +### Start with counters + +Use counters to decide whether you need a more detailed trace: + +```bash +dotnet tool install --global dotnet-counters +dotnet-counters monitor --process-id +``` + +Watch the signals that match the symptom, such as: + +- CPU usage. +- Allocation rate and GC activity. +- Thread-pool thread count. +- Thread-pool queue length. +- Exception rate. + +Counters are good for detecting a problem, but they normally do not show the full logical async call chain. + +### Collect a short trace + +Install `dotnet-trace`: + +```bash +dotnet tool install --global dotnet-trace +``` + +Collect a short runtime and sampled-thread trace: + +```bash +dotnet-trace collect \ + --process-id \ + --duration 00:00:00:30 \ + --profile dotnet-common,dotnet-sampled-thread-time \ + --output async-investigation.nettrace +``` + +The exact providers should follow the question you are investigating. More events create more data and more overhead. Start narrow, record for a limited time, and reproduce one known problem window. + +Open the trace in a compatible tool such as Visual Studio's performance tools or PerfView. Tool support matters: a runtime can emit new events before every analysis tool presents them in a useful async view. + +### What is new for profiling in .NET 11? + +Traditional Task Parallel Library events can be very verbose in async-heavy applications. .NET 11 adds a new buffered async-profiler event pipeline. Its design uses: + +- Per-thread buffers. +- Compact timestamp and instruction-pointer encoding. +- Batched event flushing. +- A small wrapper frame that helps connect CPU samples to a logical async continuation. + +In the runtime pull request's synthetic measurements, the new stream produced much less trace data and low overhead at realistic event rates. Treat those values as design measurements, not as a guarantee for your service. The event format is internal and can change, and analysis tools must understand it before you receive the full benefit. + +Follow these production rules: + +- Measure trace overhead on a staging environment first. +- Keep collection windows short. +- Avoid collecting unnecessary providers. +- Check for dropped events and increase buffers only when needed. +- Run the tool with the required process permissions. +- Protect traces because they can contain application names, paths, exception messages, and business information. + +### Keep distributed tracing in the picture + +Runtime stacks and CPU traces answer questions about execution cost. `Activity` and OpenTelemetry traces answer a different question: where did the request spend wall-clock time across services, databases, and external calls? + +For a production investigation, use both views when possible: + +- Distributed trace: request latency and service boundaries. +- Runtime trace: CPU, GC, contention, threads, and managed call stacks. +- Application logs: business context and failure details. + +Together, they are more useful than any one source alone. + +## Preview limitations and production readiness + +Runtime Async currently supports async methods returning: + +| Return type or feature | .NET 11 Runtime Async status | +|---|---| +| `Task` | Supported | +| `Task` | Supported | +| `ValueTask` | Supported | +| `ValueTask` | Supported | +| `async void` | Uses classic compiler transformation | +| Async iterators / `IAsyncEnumerable` | Uses classic compiler transformation | +| Custom task-like types and custom builders | Use classic compiler transformation | + +Runtime Async is compatible with existing assemblies. New code can await libraries compiled with the classic model, and classic code can call Runtime Async methods. However, the largest optimization opportunities appear when more of a direct async call chain uses Runtime Async. + +The important readiness facts are: + +- .NET 11 is RC1 at the time of writing, not the final release. +- Runtime Async remains preview and opt-in for application code. +- Microsoft describes the .NET 11 performance goal as broad parity with .NET 10, not a universal speedup. +- Important paths are already equal or faster, but known slower cases still exist. +- Tooling support for new profiling data can arrive at different times. +- Performance results can change between RC1, the final release, and servicing updates. + +For production, do not enable the feature only because a microbenchmark is faster. Test compatibility, performance, diagnostics, startup, publishing, and rollback in the same deployment model you use for the real application. + + +## Conclusion + +Runtime Async is one of the most important runtime changes in .NET 11, even though it does not add new C# syntax. + +It moves more async implementation work into the runtime and JIT, where .NET has better information for optimization. The most immediate improvement is easier debugging through cleaner live stacks. The longer-term opportunity is reducing the hidden cost of composing many small async methods. + +The feature is also a good reminder about performance work: architecture creates an opportunity, but measurement tells us whether that opportunity matters in our application. + +Keep writing clear async code. Use `Task` and `ValueTask` according to their API trade-offs. Then benchmark the application, inspect its traces, and let evidence decide when Runtime Async is ready for your production workload. + +## References + +- [What's new in .NET 11](https://learn.microsoft.com/en-us/dotnet/core/whats-new/dotnet-11/overview) +- [What's new in the .NET 11 runtime](https://learn.microsoft.com/en-us/dotnet/core/whats-new/dotnet-11/runtime) +- [Performance Improvements in .NET 11 — Stephen Toub](https://devblogs.microsoft.com/dotnet/performance-improvements-in-net-11/) +- [High-performance EventSource runtime async profiler — dotnet/runtime PR #127238](https://github.com/dotnet/runtime/pull/127238) +- [dotnet-trace documentation](https://learn.microsoft.com/en-us/dotnet/core/diagnostics/dotnet-trace) +- [dotnet-counters documentation](https://learn.microsoft.com/en-us/dotnet/core/diagnostics/dotnet-counters) +- [dotnet-monitor documentation](https://learn.microsoft.com/en-us/dotnet/core/diagnostics/dotnet-monitor) + diff --git a/docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/ASSET-LICENSE.md b/docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/ASSET-LICENSE.md new file mode 100644 index 0000000000..9967e47bb9 --- /dev/null +++ b/docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/ASSET-LICENSE.md @@ -0,0 +1,7 @@ +# Visual asset license + +All diagrams and charts in this folder were created specifically for this article package. They are licensed under the Creative Commons Attribution 4.0 International license (CC BY 4.0), with attribution to Mansur Besleney. + +License text: https://creativecommons.org/licenses/by/4.0/ + +The benchmark chart uses measurements produced by the runnable benchmark included in this package. It does not reproduce a third-party image. diff --git a/docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/benchmark-results.png b/docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/benchmark-results.png new file mode 100644 index 0000000000..890858b594 Binary files /dev/null and b/docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/benchmark-results.png differ diff --git a/docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/benchmark-results.svg b/docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/benchmark-results.svg new file mode 100644 index 0000000000..7c91f241b8 --- /dev/null +++ b/docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/benchmark-results.svg @@ -0,0 +1,33 @@ + + Runtime Async benchmark results from the included sample + On .NET 11 RC1, the included two-layer benchmark measured classic and Runtime Async completed paths at 84.99 and 15.83 nanoseconds, and yielding paths at 678.15 and 314.50 nanoseconds. Allocations were 144 versus 0 bytes and 248 versus 168 bytes. + + + Included microbenchmark: time and managed allocation + .NET 11 RC1 · Release · two async layers · shared Linux test host + ClassicRuntime Async + + Synchronously completed path — mean timeLower is better · scale: 0–100 ns + Classic84.99 ns + Runtime15.83 ns + 0100 ns + + Synchronously completed path — allocationLower is better · scale: 0–160 B + Classic144 B + Runtime0 B + 0160 B + + Path with Task.Yield — mean timeLower is better · scale: 0–750 ns + Classic678.15 ns + Runtime314.50 ns + 0750 ns + + Path with Task.Yield — allocationLower is better · scale: 0–280 B + Classic248 B + Runtime168 B + 0280 B + Microbenchmark results vary by hardware and runtime build. Re-run the included project on your target environment. + The classic and Runtime Async methods ran in the same .NET 11 process to isolate the lowering strategy. + diff --git a/docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/live-stack-comparison.png b/docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/live-stack-comparison.png new file mode 100644 index 0000000000..dc108e2ac0 Binary files /dev/null and b/docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/live-stack-comparison.png differ diff --git a/docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/live-stack-comparison.svg b/docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/live-stack-comparison.svg new file mode 100644 index 0000000000..614dc3885e --- /dev/null +++ b/docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/live-stack-comparison.svg @@ -0,0 +1,38 @@ + + Live stack trace comparison + Classic lowering displays 13 live stack frames including async infrastructure. Runtime Async displays 5 application frames for the same program. + + + The same code, a much cleaner live stack + Measured with .NET 11 RC1 and new StackTrace(fNeedFileInfo: true) + + + Classic lowering13 frames + Runtime Async5 frames + + InnerAsync() : line 24 + AsyncMethodBuilderCore.Start(...) + InnerAsync() infrastructure entry + MiddleAsync() : line 18 + AsyncMethodBuilderCore.Start(...) + MiddleAsync() infrastructure entry + OuterAsync() : line 12 + AsyncMethodBuilderCore.Start(...) + OuterAsync() infrastructure entry + Main() : line 7 + AsyncMethodBuilderCore.Start(...) + Main() infrastructure entry + Main(string[] args) + + InnerAsync() : line 24 + MiddleAsync() : line 18 + OuterAsync() : line 12 + Main() : line 7 + Main(string[] args) + The application call chain is visible directly. + Useful in debugger call stacks, live diagnostic + logging, and supported profiling tools. + This comparison is about live stacks. Caught exception stack traces were already cleaned up by the existing async infrastructure. + diff --git a/docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/physical-logical-async.png b/docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/physical-logical-async.png new file mode 100644 index 0000000000..50c4a8baf5 Binary files /dev/null and b/docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/physical-logical-async.png differ diff --git a/docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/physical-logical-async.svg b/docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/physical-logical-async.svg new file mode 100644 index 0000000000..99f12ef320 --- /dev/null +++ b/docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/physical-logical-async.svg @@ -0,0 +1,20 @@ + + Physical threads and the logical async call chain + An async operation starts on thread 12, suspends for I/O, and resumes on thread 27. The logical request chain crosses both physical stacks, which is why async-aware profiling is needed. + + + A logical async operation can cross physical threads + A normal CPU stack sees the current thread; an async-aware profiler reconstructs the request story. + Thread 12 + I/O + Thread 27 + Request → service → repositoryPhysical stack exists on Thread 12 + + Socket or database waitThread 12 is free to do other work + + Continuation resumesPhysical stack is now on Thread 27 + + Logical async call chainIt connects work that no longer shares one physical thread stack. + diff --git a/docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/runtime-async-architecture.png b/docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/runtime-async-architecture.png new file mode 100644 index 0000000000..28b020fb29 Binary files /dev/null and b/docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/runtime-async-architecture.png differ diff --git a/docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/runtime-async-architecture.svg b/docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/runtime-async-architecture.svg new file mode 100644 index 0000000000..1353abf8fd --- /dev/null +++ b/docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/runtime-async-architecture.svg @@ -0,0 +1,43 @@ + + Classic async lowering compared with .NET 11 Runtime Async + The classic model creates a compiler-generated state machine before the runtime sees the method. Runtime Async emits compact async-aware IL and lets the runtime and JIT perform the lowering. + + + + + + Who lowers an async method? + The C# syntax stays the same; the implementation responsibility moves. + + + + .NET 10-style compiler lowering + + C# async method + + + C# compiler + Performs the full transformation + + + Generated type + MoveNext() + builder + saved fields + Task boundary + + + + .NET 11 Runtime Async + + The same C# async method + + + C# compiler + Emits compact async-aware IL + + + Runtime + JIT manage suspension + and materialize Tasks only when needed + + Runtime Async is an implementation change—not a new async/await programming model. + diff --git a/docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/task-materialization.png b/docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/task-materialization.png new file mode 100644 index 0000000000..06ec2c8314 Binary files /dev/null and b/docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/task-materialization.png differ diff --git a/docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/task-materialization.svg b/docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/task-materialization.svg new file mode 100644 index 0000000000..ee06fdbce8 --- /dev/null +++ b/docs/en/Community-Articles/2026-09-21-DotNET-11-Runtime-Async-Cleaner-Stack-Traces-and-Faster-Async-Paths/assets/task-materialization.svg @@ -0,0 +1,29 @@ + + Intermediate Task materialization + Classic lowering has observable task-like boundaries at each async layer. Runtime Async can link continuations and create a Task only at an observable boundary, when semantics allow it. + + + Runtime Async can avoid some intermediate Task objects + Example: A() directly awaits B(), and B() directly awaits C(). + Classic lowering + A() + Task A + B() + Task B + C() + Task C + + Each layer has its own transformed state and task-like result. + + Runtime Async, when the boundary is not observed + A() + B() + C() + + Linked continuationNo intermediate Taskis required here + Observable root Task + If code stores, inspects, or manually continues a Task,the Task remains observable and must still exist. + This is an optimization opportunity, not a promise that every asynchronous operation becomes allocation-free. + diff --git a/docs/en/Community-Articles/2026-09-21-system-text-json-in-net11-naming-policies-union-types-ndjson-streaming/anyof_union_openapi.png b/docs/en/Community-Articles/2026-09-21-system-text-json-in-net11-naming-policies-union-types-ndjson-streaming/anyof_union_openapi.png new file mode 100644 index 0000000000..20bc691aab Binary files /dev/null and b/docs/en/Community-Articles/2026-09-21-system-text-json-in-net11-naming-policies-union-types-ndjson-streaming/anyof_union_openapi.png differ diff --git a/docs/en/Community-Articles/2026-09-21-system-text-json-in-net11-naming-policies-union-types-ndjson-streaming/api_contract_flow.png b/docs/en/Community-Articles/2026-09-21-system-text-json-in-net11-naming-policies-union-types-ndjson-streaming/api_contract_flow.png new file mode 100644 index 0000000000..b1bb2deeff Binary files /dev/null and b/docs/en/Community-Articles/2026-09-21-system-text-json-in-net11-naming-policies-union-types-ndjson-streaming/api_contract_flow.png differ diff --git a/docs/en/Community-Articles/2026-09-21-system-text-json-in-net11-naming-policies-union-types-ndjson-streaming/article-cover-image.jpeg b/docs/en/Community-Articles/2026-09-21-system-text-json-in-net11-naming-policies-union-types-ndjson-streaming/article-cover-image.jpeg new file mode 100644 index 0000000000..30aec3d600 Binary files /dev/null and b/docs/en/Community-Articles/2026-09-21-system-text-json-in-net11-naming-policies-union-types-ndjson-streaming/article-cover-image.jpeg differ diff --git a/docs/en/Community-Articles/2026-09-21-system-text-json-in-net11-naming-policies-union-types-ndjson-streaming/ndjson_screenshot.png b/docs/en/Community-Articles/2026-09-21-system-text-json-in-net11-naming-policies-union-types-ndjson-streaming/ndjson_screenshot.png new file mode 100644 index 0000000000..c3f549f35d Binary files /dev/null and b/docs/en/Community-Articles/2026-09-21-system-text-json-in-net11-naming-policies-union-types-ndjson-streaming/ndjson_screenshot.png differ diff --git a/docs/en/Community-Articles/2026-09-21-system-text-json-in-net11-naming-policies-union-types-ndjson-streaming/ndjson_stream.png b/docs/en/Community-Articles/2026-09-21-system-text-json-in-net11-naming-policies-union-types-ndjson-streaming/ndjson_stream.png new file mode 100644 index 0000000000..37c033c1f6 Binary files /dev/null and b/docs/en/Community-Articles/2026-09-21-system-text-json-in-net11-naming-policies-union-types-ndjson-streaming/ndjson_stream.png differ diff --git a/docs/en/Community-Articles/2026-09-21-system-text-json-in-net11-naming-policies-union-types-ndjson-streaming/post.md b/docs/en/Community-Articles/2026-09-21-system-text-json-in-net11-naming-policies-union-types-ndjson-streaming/post.md new file mode 100644 index 0000000000..36b6a51be9 --- /dev/null +++ b/docs/en/Community-Articles/2026-09-21-system-text-json-in-net11-naming-policies-union-types-ndjson-streaming/post.md @@ -0,0 +1,1022 @@ +`System.Text.Json` is getting several useful improvements in .NET 11 that go beyond simple serialization. + +Three changes are particularly relevant for API developers: + +- more flexible naming-policy customization, +- serialization support for C# union types, +- and NDJSON output for asynchronous streams. + +At first glance, these may look like unrelated serializer features. In practice, they affect three important parts of an API contract: + +```text +Naming policies → property names +Union types → possible value shapes +NDJSON → how values are delivered +``` + +That has direct consequences for ASP.NET Core APIs, TypeScript frontends, generated clients, large-result endpoints, and AI streaming scenarios. + +In this article, we'll look at each feature, build a small API around them, and discuss when NDJSON is a better fit than a conventional JSON array. + +.NET 11 includes other `System.Text.Json` work as well, but features such as `GetTypeInfo`, type-level `JsonIgnore`, and closed-hierarchy inference are outside the scope of this article except where they clarify the union guidance. + +--- + +## .NET 11 Status First + +At the time of writing, .NET 11 is at **Release Candidate 1**. Microsoft released `.NET 11.0.0-rc.1` on September 8, 2026, and the .NET release metadata lists the channel in the **Go-Live** support phase. + +An important RC1 change is that **C# 15 is now the default language version for projects targeting .NET 11**. Union types were stabilized for C# 15 in RC1, so a `net11.0` project no longer needs: + +```xml +preview +``` + +This matters because some .NET 11 library documentation still contains older wording that calls C# unions a preview feature. For RC1 language status, the [C# in .NET 11 RC1 release notes](https://github.com/dotnet/core/blob/main/release-notes/11.0/preview/rc1/csharp.md) are the more specific source. + +RC1 is still pre-GA, however. Before a final production rollout, re-check the .NET 11 release notes, known issues, and serializer behavior against the final SDK. + +--- + +## Naming Policies Become More Flexible + +`System.Text.Json` already supports built-in naming conventions such as camelCase, snake_case, and kebab-case. + +.NET 11 adds: + +```csharp +JsonNamingPolicy.PascalCase +``` + +and introduces `JsonNamingPolicyAttribute`, which allows a naming policy to be applied to an individual property or field. + +Per-member name overrides were already possible with `[JsonPropertyName("someName")]`. The .NET 11 addition is different: instead of hard-coding one literal JSON name, a member can opt into a naming **policy**, so the transformation remains policy-driven. + +For example: + +```csharp +using System.Text.Json; +using System.Text.Json.Serialization; + +var options = new JsonSerializerOptions +{ + PropertyNamingPolicy = JsonNamingPolicy.PascalCase +}; + +var response = new EventResponse +{ + EventName = "UserRegistered", + CreatedAtUtc = + new DateTimeOffset(2026, 9, 18, 8, 30, 0, TimeSpan.Zero) +}; + +Console.WriteLine( + JsonSerializer.Serialize(response, options)); + +public sealed class EventResponse +{ + [JsonNamingPolicy(JsonKnownNamingPolicy.CamelCase)] + public string EventName { get; init; } = ""; + + public DateTimeOffset CreatedAtUtc { get; init; } +} +``` + +Actual compact output: + +```json +{"eventName":"UserRegistered","CreatedAtUtc":"2026-09-18T08:30:00+00:00"} +``` + +The serializer uses PascalCase globally, but `EventName` is explicitly kept in camelCase. + +### Why does this matter for APIs? + +Because JSON naming is part of the wire contract. + +These responses contain the same data: + +```json +{"userId":12} +``` + +```json +{"UserId":12} +``` + +but they are not necessarily compatible from a client's perspective. + +A TypeScript application might have: + +```ts +interface User { + userId: number; +} +``` + +Changing the server to return `UserId` can break client mappings, generated SDKs, runtime validation, or tests without changing the underlying C# property at all. + +So naming-policy changes should be treated as contract changes. + +In ASP.NET Core, a global policy can be configured like this: + +```csharp +builder.Services.ConfigureHttpJsonOptions(options => +{ + options.SerializerOptions.PropertyNamingPolicy = + JsonNamingPolicy.PascalCase; +}); +``` + +The point of .NET 11 is not that PascalCase is suddenly preferable for web APIs. The useful part is having finer control when an API needs exceptions to its global convention. + +![C# model to JSON contract and frontend client flow](api_contract_flow.png) + +*Figure: An illustrative contract-flow example showing how a server-side naming decision becomes part of the JSON and frontend contract. The runnable sample below intentionally uses PascalCase globally to demonstrate the new .NET 11 policy.* + +--- + +## C# Union Types Meet System.Text.Json + +Another important .NET 11 improvement is serialization support for C# union types. + +A union represents a value that can be one of a fixed set of cases. + +For example: + +```csharp +public record OrderCreated( + int OrderId, + string Status); + +public record ValidationFailure( + string ErrorCode, + string Message); + +public union CreateOrderResult( + OrderCreated, + ValidationFailure); +``` + +A `CreateOrderResult` can now contain either: + +```csharp +CreateOrderResult result = + new OrderCreated(125, "created"); +``` + +or: + +```csharp +CreateOrderResult result = + new ValidationFailure( + "INVALID_QUANTITY", + "Quantity must be greater than zero."); +``` + +Pattern matching can then handle the known cases explicitly: + +```csharp +string message = result switch +{ + OrderCreated order => + $"Order {order.OrderId} created.", + + ValidationFailure failure => + failure.Message +}; +``` + +The compiler knows which cases belong to the union instead of treating the value as an arbitrary `object`. + +--- + +### Serializing a Union + +.NET 11's `System.Text.Json` recognizes C# unions through the new `JsonTypeInfoKind.Union` contract kind and can serialize the active case directly. The feature works with both reflection-based serialization and source generation. + +For example: + +```csharp +CreateOrderResult result = + new OrderCreated(125, "created"); + +string json = + JsonSerializer.Serialize(result); + +Console.WriteLine(json); +``` + +Actual compact output: + +```json +{"OrderId":125,"Status":"created"} +``` + +The validation case produces: + +```json +{"ErrorCode":"INVALID_QUANTITY","Message":"Quantity must be greater than zero."} +``` + +There is no artificial union wrapper or discriminator in the JSON. The active case becomes the actual representation. + +That maps to a TypeScript union using the same wire-property casing: + +```ts +type CreateOrderResult = + | { + OrderId: number; + Status: string; + } + | { + ErrorCode: string; + Message: string; + }; +``` + +Because the serialized union has no discriminator, the client narrows by shape, for example: + +```ts +function handle(result: CreateOrderResult) { + if ("OrderId" in result) { + console.log(result.Status); + } else { + console.error(result.Message); + } +} +``` + +That is valid TypeScript, but an explicit discriminator can be easier to evolve when you control a brand-new polymorphic object contract. + +--- + +### A Note on Union Deserialization + +Serialization and deserialization are not identical concerns. When a union contains two object-shaped cases, `System.Text.Json` may not be able to determine the active case from the JSON token alone. + +For structurally distinct objects, .NET 11 provides `JsonUnionTypeStructuralClassifier`: + +```csharp +[JsonUnion( + TypeClassifier = + typeof(JsonUnionTypeStructuralClassifier))] +public union CreateOrderResult( + OrderCreated, + ValidationFailure); +``` + +In this sample, `OrderCreated` and `ValidationFailure` expose different root-level properties, so the classifier can distinguish them. The behavior is verified in the **Running and Testing the Sample** section below. If cases are still ambiguous, an explicit custom classifier may be required. + +--- + +### OpenAPI and Generated Clients + +ASP.NET Core's OpenAPI support represents a C# union as an `anyOf` schema with one entry per case type. + +Conceptually: + +```yaml +CreateOrderResult: + anyOf: + - $ref: "#/components/schemas/OrderCreated" + - $ref: "#/components/schemas/ValidationFailure" +``` + +A client generator can then potentially produce: + +```ts +type CreateOrderResult = + OrderCreated | ValidationFailure; +``` + +That is much better than exposing the response as an untyped `object`, but generated clients should still be tested because generators can differ in how they model `anyOf`. Also remember that union serialization itself does not add a discriminator, so generated frontend code may still need shape-based narrowing. + +![Scalar OpenAPI view of the CreateOrderResult union](anyof_union_openapi.png) + +*Figure: Scalar represents `CreateOrderResult` as an OpenAPI `anyOf` schema with `OrderCreated` and `ValidationFailure` alternatives.* + +--- + +## Putting Everything Together in ASP.NET Core + +The following Minimal API demonstrates the naming-policy configuration, a union response, OpenAPI/Scalar setup, and an NDJSON streaming endpoint. + +### Project file + +```xml + + + + net11.0 + enable + enable + + + + + + + + +``` + +### `Program.cs` + +```csharp +using System.Runtime.CompilerServices; +using System.Text.Json; +using System.Text.Json.Serialization; +using Microsoft.AspNetCore.Http.Json; +using Microsoft.Extensions.Options; +using Scalar.AspNetCore; + +var builder = WebApplication.CreateBuilder(args); + +builder.Services.AddOpenApi(); + +builder.Services.ConfigureHttpJsonOptions(options => +{ + options.SerializerOptions.PropertyNamingPolicy = + JsonNamingPolicy.PascalCase; +}); + +var app = builder.Build(); + +if (app.Environment.IsDevelopment()) +{ + app.MapOpenApi(); + app.MapScalarApiReference(); +} + +app.MapGet("/api/contracts/naming", () => + new NamingResponse + { + EventName = "UserRegistered", + CreatedAtUtc = DateTimeOffset.UtcNow + }); + +app.MapPost("/api/orders", ( + CreateOrderRequest request) => +{ + CreateOrderResult result = + request.Quantity <= 0 + ? new ValidationFailure( + "INVALID_QUANTITY", + "Quantity must be greater than zero.") + : new OrderCreated( + 125, + "created"); + + return TypedResults.Ok(result); +}); + +app.MapGet("/api/events/stream", async ( + HttpContext context, + IOptions jsonOptions, + CancellationToken cancellationToken) => +{ + context.Response.ContentType = + "application/x-ndjson; charset=utf-8"; + + await JsonSerializer.SerializeAsyncEnumerable( + context.Response.BodyWriter, + GenerateEvents(cancellationToken), + topLevelValues: true, + options: jsonOptions.Value.SerializerOptions, + cancellationToken: cancellationToken); +}); + +app.Run(); + +static async IAsyncEnumerable GenerateEvents( + [EnumeratorCancellation] + CancellationToken cancellationToken) +{ + for (var i = 1; i <= 5; i++) + { + await Task.Delay(1000, cancellationToken); + + yield return new StreamEvent( + i, + $"Chunk {i}", + DateTimeOffset.UtcNow); + } +} + +public sealed class NamingResponse +{ + [JsonNamingPolicy(JsonKnownNamingPolicy.CamelCase)] + public string EventName { get; init; } = ""; + + public DateTimeOffset CreatedAtUtc { get; init; } +} + +public record CreateOrderRequest( + int ProductId, + int Quantity); + +public record OrderCreated( + int OrderId, + string Status); + +public record ValidationFailure( + string ErrorCode, + string Message); + +public union CreateOrderResult( + OrderCreated, + ValidationFailure); + +public record StreamEvent( + int Id, + string Text, + DateTimeOffset Timestamp); +``` + +A successful request: + +```http +POST /api/orders +Content-Type: application/json + +{"ProductId":17,"Quantity":2} +``` + +returns: + +```json +{"OrderId":125,"Status":"created"} +``` + +while an invalid quantity produces the other union shape: + +```json +{"ErrorCode":"INVALID_QUANTITY","Message":"Quantity must be greater than zero."} +``` + +This sample deliberately returns both domain outcomes under HTTP `200 OK` so that one endpoint can demonstrate a single union response and the generated `anyOf` schema. That is a serializer/OpenAPI demonstration, not a general HTTP error-handling recommendation. In a production API, validation failures are commonly mapped to an appropriate `4xx` response. + +--- + +## NDJSON: Streaming JSON Records + +The third major improvement is around asynchronous JSON output. + +The read side of this model already existed before .NET 11: `JsonSerializer.DeserializeAsyncEnumerable(..., topLevelValues: true)` can consume a sequence of whitespace-separated top-level JSON values (available in .NET 9). .NET 11 completes the story on the **write** side by adding top-level-value output to `SerializeAsyncEnumerable` and direct `PipeWriter` support. + +A conventional JSON array looks like this: + +```json +[{"Id":1,"Text":"Chunk 1"},{"Id":2,"Text":"Chunk 2"},{"Id":3,"Text":"Chunk 3"}] +``` + +NDJSON — Newline Delimited JSON — looks like this: + +```text +{"Id":1,"Text":"Chunk 1"} +{"Id":2,"Text":"Chunk 2"} +{"Id":3,"Text":"Chunk 3"} +``` + +Each line is an independent JSON value. + +.NET 11 extends `JsonSerializer.SerializeAsyncEnumerable` with two useful capabilities: + +- writing directly to a `PipeWriter`, +- and a `topLevelValues` option for NDJSON-style output. + +The key call from the sample is: + +```csharp +await JsonSerializer.SerializeAsyncEnumerable( + context.Response.BodyWriter, + GenerateEvents(cancellationToken), + topLevelValues: true, + options: jsonOptions.Value.SerializerOptions, + cancellationToken: cancellationToken); +``` + +A .NET client can consume the same record-oriented format with: + +```csharp +await foreach (var item in JsonSerializer.DeserializeAsyncEnumerable( + responseStream, + topLevelValues: true)) +{ + Console.WriteLine(item); +} +``` + +When relying on line-based framing, verify any serializer formatting changes you make, especially indentation, against the actual wire output expected by your clients. + +On Windows, run: + +```powershell +curl.exe -N http://localhost:5050/api/events/stream +``` + +The wire output is similar to: + +```text +{"Id":1,"Text":"Chunk 1","Timestamp":"..."} +{"Id":2,"Text":"Chunk 2","Timestamp":"..."} +{"Id":3,"Text":"Chunk 3","Timestamp":"..."} +``` + +NDJSON runtime response shown in Scalar + +*Figure: Scalar's Try It view shows the runtime response returned with `application/x-ndjson`. Scalar may pretty-print the values for display; the terminal capture below shows the actual newline-delimited wire format.* + +NDJSON records arriving incrementally in Windows Terminal + +*Figure: Streaming the NDJSON endpoint with `curl.exe -N`. Each JSON record arrives independently as it becomes available.* + +--- + +## JSON Array vs. NDJSON + +A normal JSON array is still the better default when a response is conceptually one document. NDJSON becomes more interesting when individual records are useful before the operation has completely finished. + +One important distinction is that **streaming is not unique to NDJSON**. ASP.NET Core has been able to serialize `IAsyncEnumerable` with `System.Text.Json` without first buffering the full sequence since .NET 6. The server-side memory benefit comes mainly from streaming the source and avoiding materialization such as `ToListAsync()`. NDJSON's main difference is its record-oriented framing, which lets clients parse and process complete records incrementally. + +| Scenario | JSON array | NDJSON | +|---|---|---| +| Small CRUD or paginated response | Natural fit | Usually unnecessary | +| Client wants `response.json()` | Natural fit | Poor fit | +| Large streamed result | Can also stream with `IAsyncEnumerable` | Easy per-record framing and parsing | +| Log/event stream | Possible, but awkward to frame incrementally | Natural fit | +| Incremental search results | Possible | Natural fit | +| ETL/data pipeline | Works | Often convenient | +| Browser AI stream | Possible | Good generic JSON-record format; SSE may be more convenient | +| One atomic document required | Natural fit | Poor fit | + +A useful rule of thumb is: + +> **If the response is conceptually one document, use normal JSON. If it is a sequence of independent records that should be processed as they arrive, NDJSON may be the better model.** + +--- + +## Consuming NDJSON from the Frontend + +There is one important frontend consequence. + +This will not work: + +```ts +const response = await fetch("/api/events/stream"); +const data = await response.json(); +``` + +NDJSON is not one complete JSON document. + +Instead, the browser needs to consume the response body as a stream: + +```ts +type StreamEvent = { + Id: number; + Text: string; + Timestamp: string; +}; + +async function consumeEvents() { + const response = + await fetch("/api/events/stream"); + + if (!response.ok || !response.body) { + throw new Error( + `Streaming request failed: ${response.status}` + ); + } + + const reader = response.body.getReader(); + const decoder = new TextDecoder(); + + let buffer = ""; + + while (true) { + const { value, done } = + await reader.read(); + + if (done) { + break; + } + + buffer += decoder.decode( + value, + { stream: true }); + + const lines = buffer.split("\n"); + buffer = lines.pop() ?? ""; + + for (const line of lines) { + if (!line.trim()) { + continue; + } + + const item = + JSON.parse(line) as StreamEvent; + + console.log(item); + } + } + + buffer += decoder.decode(); + + if (buffer.trim()) { + const item = + JSON.parse(buffer) as StreamEvent; + + console.log(item); + } +} +``` + +The buffer is important because network chunks do not necessarily align with NDJSON records. + +For example, the browser might receive: + +```text +{"Id":1,"Text":"Chu +``` + +and then: + +```text +nk 1"}\n{"Id":2, +``` + +So each `reader.read()` result cannot safely be passed directly to `JSON.parse()`. + +--- + +## Large Results and AI Streaming + +Large-result scenarios are where the distinction between **streaming** and **format** becomes especially important. + +Consider: + +```csharp +var rows = + await db.Transactions + .ToListAsync(); + +return Results.Ok(rows); +``` + +If the query returns one million rows, the application materializes the result before serialization. + +A streaming pipeline instead looks like this: + +```text +Database + │ + ▼ +IAsyncEnumerable + │ + ▼ +Serializer + │ + ▼ +Network +``` + +The important point is that the **data source must stream too**. Calling: + +```csharp +var rows = await query.ToListAsync(); +``` + +before writing either a JSON array or NDJSON removes much of the server-side memory benefit. + +NDJSON is useful here because the client can parse each complete record independently. A streamed JSON array can also avoid full server-side buffering, but many clients still treat the array as one document and wait for the full payload before calling a normal JSON parser. + +There is also an operational trade-off: a truly streamed EF Core query can keep its data reader, database connection, and related upstream resources active while a slow client is still consuming the response. For very large exports, measure this behavior under realistic client speeds and consider whether paging or a background export job is a better fit. + +--- + +### AI Streaming + +AI responses are another natural streaming scenario. + +An AI agent may produce more than just text: + +```text +TextDelta +ToolStarted +ToolResult +Citation +Completed +Error +``` + +An application-level event envelope could look like this: + +```text +{"type":"text","delta":"Hello "} +{"type":"text","delta":"world"} +{"type":"tool-started","name":"search"} +{"type":"tool-result","count":4} +{"type":"completed","finishReason":"stop"} +``` + +The `type` field above is **application-defined**. C# union serialization does not automatically add a discriminator. + +Union types and NDJSON can still complement each other: + +> **Union types can describe which event shapes are valid in code.** + +> **NDJSON can describe how independent event records are delivered over time.** + +If the JSON contract itself needs an explicit discriminator, model that discriminator deliberately rather than assuming it will appear because the server-side type is a union. + +For browser-first server-to-client streaming, SSE may also be worth considering depending on the client requirements. + +--- + +## Error Handling Is Different Once Streaming Starts + +Suppose a server has already sent: + +```text +HTTP 200 OK + +{"Id":1} +{"Id":2} +``` + +and then the database fails. + +The HTTP response has already started, so the server cannot replace the response with: + +```http +500 Internal Server Error +``` + +A streaming API therefore needs an explicit strategy for mid-stream errors. + +For an event-oriented protocol, that might be: + +```text +{"type":"data","value":{"id":1}} +{"type":"error","code":"DB_FAILURE"} +``` + +It can also be useful to define a final completion event: + +```text +{"type":"data","value":{"id":1}} +{"type":"completed"} +``` + +If the connection closes without `completed`, the client can treat the stream as interrupted rather than successfully finished. + +These `type` fields are part of the application's streaming protocol; they are not inserted automatically by union serialization. + +--- + +## Performance and Cancellation + +NDJSON does not automatically mean “faster”, and it does not automatically use less server memory than a streamed JSON array. + +The main benefits of NDJSON are usually: + +- incremental client parsing, +- simple record boundaries, +- and the ability to process already-completed records before the full response finishes. + +Memory behavior depends more on whether the producer and serializer stream or buffer the data. Every record still has serialization and parsing overhead, and flushing extremely small records can reduce throughput. + +The response may also be buffered by infrastructure such as ASP.NET Core middleware, compression, reverse proxies, CDNs, or the client itself. + +> **NDJSON defines the format. Streaming, flushing, and buffering define the transport behavior.** + +That distinction should be tested in a production-like environment. + +Cancellation matters too. + +When a browser closes the connection or a user presses **Stop generating**, the request cancellation token should ideally propagate through the entire pipeline: + +```text +Client disconnect + │ + ▼ +RequestAborted + │ + ▼ +IAsyncEnumerable + │ + ├── DB query stops + ├── AI request stops + └── downstream calls stop +``` + +This can be especially important for AI workloads where unnecessary generation has a real cost. + +--- + +## Compatibility Considerations + +All three features can change a public API contract. Renaming `userId` to `UserId` may break generated clients or frontend mappings, and widening a value from one JSON shape to several possible union shapes changes what consumers must handle. Because union serialization is discriminator-free by default, clients may also need shape-based narrowing unless the API defines its own discriminator. + +Switching an endpoint from `application/json` to `application/x-ndjson` is an even more visible change because clients can no longer rely on `response.json()` and must consume the body incrementally. For existing APIs, prefer additive changes over silent contract replacements. Keeping `GET /api/orders` for the conventional JSON response and introducing `GET /api/orders/stream` for NDJSON, for example, makes the migration explicit and allows existing consumers to continue working unchanged. + +--- + +## RC1 and Production-Readiness Notes + +These features do not all carry the same kind of production risk. + +### Naming policies + +The naming APIs are straightforward, but the wire contract is compatibility-sensitive. Treat casing changes exactly like other public-schema changes and contract-test them. + +### NDJSON + +NDJSON itself is established, but production behavior depends on the complete delivery path: client parsing, buffering, compression, proxy behavior, cancellation, mid-stream errors, load testing, and observability. + +### C# unions + +C# union syntax is **stable in C# 15 as of .NET 11 RC1** and does not require `LangVersion=preview` for `net11.0`. + +The more important production consideration is deserialization classification. Object-shaped cases can require structural or custom classification. Structural classification has a scanning cost and couples classification to property shape, so contract evolution should be tested carefully. + + +There is also a documentation inconsistency at the time of writing: the .NET 11 libraries page still contains older wording that calls unions a preview language feature, while the RC1 C# release notes explicitly state that unions were stabilized. For RC1 language status, use the RC1 C# release notes. + +.NET 11 RC1 is a Go-Live release, but it is not yet GA. Re-check the final release notes and known issues before the final production rollout. + +--- + +## Running and Testing the Sample + +The screenshots and runtime examples in this article were produced with the locally verified **.NET SDK `11.0.100-rc.1.26425.128`**. + +The project uses `Microsoft.AspNetCore.OpenApi` `11.0.0-rc.1.26425.128` and `Scalar.AspNetCore` `2.17.4`. + +To reproduce the setup: + +```powershell +dotnet new web -n Json11Demo +cd Json11Demo + +dotnet add package Microsoft.AspNetCore.OpenApi --version 11.0.0-rc.1.26425.128 +dotnet add package Scalar.AspNetCore --version 2.17.4 +``` + +Replace the generated project file and `Program.cs` with the versions shown above, then verify the installed SDK and build the project: + +```powershell +dotnet --version +dotnet build +dotnet run --urls http://localhost:5050 +``` + +The local `dotnet --version` output was `11.0.100-rc.1.26425.128`, matching the SDK build listed in the .NET 11 RC1 release notes. The project built successfully and the API was then started on `http://localhost:5050`. + +The successful order request used during testing was: + +```powershell +Invoke-RestMethod ` + -Uri "http://localhost:5050/api/orders" ` + -Method Post ` + -ContentType "application/json" ` + -Body '{"ProductId":17,"Quantity":2}' +``` + +PowerShell displayed: + +```text +OrderId Status +------- ------ +125 created +``` + +The validation branch was also tested with `Quantity` set to `0`: + +```powershell +Invoke-RestMethod ` + -Uri "http://localhost:5050/api/orders" ` + -Method Post ` + -ContentType "application/json" ` + -Body '{"ProductId":17,"Quantity":0}' +``` + +PowerShell displayed: + +```text +ErrorCode Message +--------- ------- +INVALID_QUANTITY Quantity must be greater than zero. +``` + +The NDJSON endpoint was tested with: + +```powershell +curl.exe -N http://localhost:5050/api/events/stream +``` + +and produced records incrementally: + +```text +{"Id":1,"Text":"Chunk 1","Timestamp":"..."} +{"Id":2,"Text":"Chunk 2","Timestamp":"..."} +{"Id":3,"Text":"Chunk 3","Timestamp":"..."} +``` + +The generated OpenAPI document was also inspected in Scalar at: + +```text +http://localhost:5050/scalar/v1 +``` + +where `CreateOrderResult` appeared as an `anyOf` choice between `OrderCreated` and `ValidationFailure`. + +A separate `net11.0` console check was used to verify union deserialization. The same JSON object was deserialized first into an object-object union without a classifier, and then into the same union shape with `JsonUnionTypeStructuralClassifier`. + +Input: + +```json +{"OrderId":125,"Status":"created"} +``` + +Observed output: + +```text +Default: JsonException: JSON value type 'Object' is ambiguous for union type 'DefaultResult' because multiple case types can use this value type. Specify a custom type classifier to support deserialization. Path: $ | LineNumber: 0 | BytePositionInLine: 1. +Structural: OrderCreated +``` + +This confirms the distinction discussed earlier: serialization of the active case is straightforward, but deserializing two object-shaped cases requires classification. For these structurally distinct cases, `JsonUnionTypeStructuralClassifier` successfully selected `OrderCreated`. + + +--- + +## Final Thoughts + +The most useful way to look at these `System.Text.Json` improvements is not as three unrelated serializer features. + +They affect three different parts of an API contract: + +```text +Naming policy → name +Union type → shape +NDJSON → delivery +``` + +For normal CRUD and paginated endpoints, conventional JSON remains the simpler choice. + +For large or long-running responses, the first architectural decision is whether the source and serializer should stream at all. NDJSON then becomes useful when the client benefits from independent, line-delimited records that can be parsed as they arrive. + +Union types make fixed alternative shapes explicit in C#, while the naming-policy improvements provide more control over compatibility-sensitive JSON property names. The important production caveat is that serialization and deserialization are not the same problem: writing the active union case is simple, while reading ambiguous shapes may require classification. + +Together, these .NET 11 changes give API developers more explicit control over how contracts are named, shaped, and delivered. + +--- + +## Adoption Checklist + +Before adopting these features: + +- [ ] Treat JSON property casing as part of the public contract. +- [ ] Contract-test naming-policy changes and per-member overrides. +- [ ] Keep frontend types aligned with the actual wire casing. +- [ ] Inspect generated OpenAPI `anyOf` schemas for union responses. +- [ ] Test union deserialization separately from serialization. +- [ ] Add structural or custom classification when union cases are ambiguous. +- [ ] Consider a discriminator-based closed hierarchy for new related object contracts you fully control. +- [ ] Use NDJSON when independent records should be processed incrementally. +- [ ] Remember that streamed JSON arrays can also avoid full server-side buffering. +- [ ] Make sure the underlying data source streams instead of materializing with `ToListAsync()`. +- [ ] Test slow-client behavior and upstream resource lifetime for large streamed queries. +- [ ] Use an incremental frontend parser instead of `response.json()` for NDJSON. +- [ ] Handle records that span multiple network chunks and flush any final decoder buffer. +- [ ] Propagate request cancellation to downstream work. +- [ ] Define mid-stream error and completion semantics. +- [ ] Test proxy, compression, flushing, and buffering behavior. +- [ ] Compare NDJSON with SSE for browser-focused AI streaming. +- [ ] Re-check .NET 11 release notes and known issues before moving from RC to GA. + + +## References + +- [.NET 11.0.0 RC1 release notes](https://github.com/dotnet/core/blob/main/release-notes/11.0/preview/rc1/11.0.0-rc.1.md) +- [C# in .NET 11 RC1 release notes](https://github.com/dotnet/core/blob/main/release-notes/11.0/preview/rc1/csharp.md) +- [What's new in .NET libraries for .NET 11](https://learn.microsoft.com/en-us/dotnet/core/whats-new/dotnet-11/libraries) +- [Use C# unions and closed hierarchies in ASP.NET Core](https://devblogs.microsoft.com/dotnet/unions-and-closed-hierarchies-in-aspnetcore/) +- [System.Text.Json overview](https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/overview) +- [Generate OpenAPI documents in ASP.NET Core](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/openapi/aspnetcore-openapi) +- [MVC doesn't buffer IAsyncEnumerable types when using System.Text.Json](https://learn.microsoft.com/en-us/aspnet/core/breaking-changes/6/iasyncenumerable-not-buffered-by-mvc) +- [Efficient querying in EF Core — buffering and streaming](https://learn.microsoft.com/en-us/ef/core/performance/efficient-querying) diff --git a/docs/en/Community-Articles/2026-09-22-blazor-net11-virtualize-anchormode-csp/POST.md b/docs/en/Community-Articles/2026-09-22-blazor-net11-virtualize-anchormode-csp/POST.md new file mode 100644 index 0000000000..1eae62291d --- /dev/null +++ b/docs/en/Community-Articles/2026-09-22-blazor-net11-virtualize-anchormode-csp/POST.md @@ -0,0 +1,924 @@ +# Building High-Performance Blazor Lists in .NET 11: Virtualize, AnchorMode, and Strict CSP + +> **Release status.** Everything in this article was built and tested on **.NET 11 RC1** (SDK `11.0.100-rc.1.26425.128`, runtime `11.0.0-rc.1.26425.128`, released September 8, 2026). RC1 has a go-live license, but it isn't the final release. APIs, generated markup, defaults, and browser behavior can still change before .NET 11 GA, which is planned for .NET Conf in November 2026. Rerun the sample's tests against each new SDK before you ship. + +.NET 11 makes `Virtualize` a viable choice for dynamic feeds, chats, logs, and variable-height collections. Before, it was mostly a component for predictable, uniform lists. It also works under a strict Content Security Policy for the first time. This article covers the changes behind that. It shows them in a runnable sample app, and it reports what I measured in Chrome, Firefox, and WebKit, including the rough edges that RC1 still has. + +**TL;DR** + +- **Variable heights:** `Virtualize` now measures rendered items and keeps a running average item height. `ItemSize` is only the starting estimate. +- **Scroll anchoring:** When something above the viewport changes height, what you're reading now normally stays put. Lists built from `div`s use the browser's native CSS scroll anchoring. `` layouts, and browsers without `overflow-anchor`, use a `ResizeObserver`-based fallback. +- **`AnchorMode`:** A new parameter of the `[Flags]` enum `VirtualizeAnchorMode`. `Start`, the default, shows new items when you're at the top. `End` follows new items when you're at the bottom. `None` does neither. Away from the edges, every mode keeps the content you're reading in place when items are inserted. +- **Scroll APIs:** `InitialItemIndex` and `ScrollToItemAsync` finally let you open a list at a given item and jump to any item. +- **Overscan:** The `OverscanCount` default went from **3 to 15**. That means more DOM, and bigger `ItemsProvider` requests. +- **CSP:** Spacer heights now travel in `data-blazor-virtualize-*` attributes and are applied through CSSOM, so `style-src 'self'` no longer breaks virtualization. On .NET 10, the same policy collapsed a 100,000-item list to a 1,227 px scroll range. +- **RC1 caveats I measured:** + - `
` rows that grow right after scrolling are only partly compensated. + - The first render after `InitialItemIndex` can move the content by 53–82 px. + - `AnchorMode.End` sometimes stops 29–77 px short of the bottom after an append. In Playwright's WebKit build that happened in 10 of 30 checks; in Chrome and Firefox, in 1–2 of 30. + - In Playwright's WebKit build, a `Start` list jumps when items are appended at the very end. + - The docs' `AnchorMode="Start"` shorthand doesn't compile. + + Details and workarounds are below. + + +## Large lists are not just a rendering problem + +Picture an operations dashboard that shows 100,000 events. New events arrive every second and descriptions vary in length. Users have to be able to inspect older entries without being yanked back to the newest one every time something happens. + +A naive `@foreach` over those events runs into trouble on several fronts at once: + +- **DOM size.** In the sample, 100,000 simple three-cell rows produced 400,078 DOM elements. Layout, style recalculation, and memory all grow with that number, and richer rows are worse. +- **Render cost.** Blazor has to diff and describe every row. On **Blazor Server**, that description is a render batch sent over SignalR. On **Blazor WebAssembly**, it runs on the browser's main thread. +- **Prerendered HTML.** With prerendering, which the Blazor Web App template has on by default, every row is also rendered into the initial HTML document. The `foreach` version of the sample's 100,000-item list produced a **28.6 MB** HTML response, compared with **11.7 KB** for the virtualized version. The `foreach` page also took almost two minutes to become interactive ([section 12](#performance-what-i-measured)). +- **Constant change.** Feeds, chats, and log viewers change while people read them. Prepending an item or expanding a card above the viewport moves the content under the reader's eyes. + +Three separate ideas are at play here. Real apps usually need all three, but they solve different problems: + +| Concept | What it solves | Blazor feature | +|---|---|---| +| **Virtualization** | Only render what's (nearly) visible | `Virtualize` | +| **Incremental loading** | Only *fetch* what's (nearly) visible | `ItemsProvider` + `ItemsProviderRequest` | +| **Scroll anchoring** | Keep what the user is reading still while data changes | .NET 11 anchoring + `AnchorMode` | + +## What `Virtualize` actually does + +`Virtualize` renders a *window* of items inside a scroll container. It stands in for everything outside that window with two spacer elements. + +![Anatomy of a virtualized list: a top spacer, overscan items, the visible items, more overscan, and a bottom spacer inside a fixed-height scroll container](images/diagrams/virtualize-anatomy.png) + +*Figure 1. The two spacers reserve the height of the items that aren't rendered. An `IntersectionObserver` watches the spacers and tells .NET when one of them scrolls into view.* + +Here's how it works: + +1. It finds the closest scrollable ancestor. In RC1, that's the first ancestor whose `overflow-y` is not `visible`, `hidden`, or `clip`. If there's none, it uses the document itself. +2. It renders the visible items plus `OverscanCount` extra items before and after them. +3. It renders a spacer before and after the window. Each spacer's height is *number of items it replaces* × *average item height*. +4. An `IntersectionObserver` (50 px root margin) watches both spacers. When one becomes visible, JavaScript reports the sizes to .NET, which computes a new window and renders it. + +This `foreach`: + +```razor +
+ @foreach (var item in items) + { + + } +
+``` + +becomes this: + +```razor +
+ + + +
+``` + +`Virtualize` doesn't require the whole collection to be in memory: + +- **`Items`** takes an in-memory `ICollection`. The component slices it directly. +- **`ItemsProvider`** takes a delegate. It receives an `ItemsProviderRequest` (`StartIndex`, `Count`, `CancellationToken`) and returns an `ItemsProviderResult` (the slice plus `TotalItemCount`). Only the requested range needs to be loaded from the backend. + +**Prerendering emits (almost) no items.** During static prerendering, `Virtualize` normally emits only its spacers. Real items appear once the component becomes interactive, which is why the virtualized HTML above was only 11.7 KB. + +- With `Items`, the prerendered trailing spacer is item count × `ItemSize`. +- With an `ItemsProvider`, the provider isn't called during prerendering, so both spacers are 0 px. The sample's `/feed` and `/grid` pages prerender `data-blazor-virtualize-reserved-height="0"` twice. +- One exception in RC1: with in-memory `Items` and `InitialItemIndex` greater than 0, the window moves to the target before the first render. Up to `2 × OverscanCount + 1` items around it are then prerendered. The sample's `/chat` page prerenders messages #99,985–#100,000. + +If you need all items in the initial HTML, for SEO or for no-JS clients, virtualization isn't the right tool. See [section 20](#when-not-to-use-virtualize). + +## What changed in .NET 11 + +| | .NET 10 | .NET 11 RC1 | Introduced in | +|---|---|---|---| +| Variable-height items | Assumed uniform height (`ItemSize`) | Running average of measured heights | Preview 3 | +| Default `OverscanCount` | 3 | **15** (QuickGrid stays at 3) | Preview 3 | +| Content stability when items above resize | Native scroll anchoring disabled, so content jumped | Native CSS anchoring or `ResizeObserver` compensation | Preview 4 | +| Edge pinning | Hand-written JS | `AnchorMode` (`None`, `Start`, `End`, combinable) | Preview 4 (renamed in Preview 7) | +| Prepend/append detection for providers | — | `ItemComparer` (defaults to `EqualityComparer.Default`) | Preview 4 / Preview 7 | +| Open at / jump to an item | Hand-written JS | `InitialItemIndex`, `ScrollToItemAsync` | Preview 6 (renamed in Preview 7) | +| Strict `style-src 'self'` | Spacers render `style="height:…"`, which the policy blocks | Spacer sizes rendered as `data-*` attributes and applied via CSSOM | Preview 6 | + +To avoid relying only on the docs, I dumped the public surface from the RC1 shared framework with reflection, using a small file-based C# app. Abridged output, with `TItem` shown generically: + +```text +Assembly: Microsoft.AspNetCore.Components.Web 11.0.0-rc.1.26425.128 +[Parameter] VirtualizeAnchorMode AnchorMode = Start +[Parameter] Int32 InitialItemIndex = 0 +[Parameter] IEqualityComparer`1 ItemComparer = (EqualityComparer.Default) +[Parameter] Single ItemSize = 50 +[Parameter] Int32 MaxItemCount = 100 +[Parameter] Int32 OverscanCount = 15 +[Parameter] String SpacerElement = div +method Task ScrollToItemAsync(Int32 itemIndex, CancellationToken cancellationToken = default) +enum VirtualizeAnchorMode [Flags] None = 0, Start = 1, End = 2 +``` + +> **Reading older preview blog posts?** Preview 7 renamed three APIs: `VirtualizeAnchorMode.Beginning` → `Start`, `InitialIndex` → `InitialItemIndex`, and `ScrollToIndexAsync` → `ScrollToItemAsync`. Code from Preview 4–6 posts won't compile on RC1 until you apply those renames. + +### Variable-height items + +Earlier versions assumed that every item had the height given by `ItemSize`. In .NET 11, `ItemSize` is only the **initial estimate**. Once items render, the JavaScript side measures the total height of everything rendered between the two spacers, using a DOM `Range`. It sends that total to .NET along with the spacer and container sizes. .NET adds it to a running total and uses `totalMeasuredHeight / measuredItemCount` for every spacer calculation after that. Measurements are only taken when no placeholders are on screen, so placeholder heights don't distort the average. + +You can see this in the sample. The activity feed starts with `ItemSize="96"` and 100,000 items, so the first scroll range is 100,000 × 96 ≈ **9.6 million px**. After the first measurements it settles at about **8.4 million px**, an average of about 84 px per card. + +Two consequences: + +- `Virtualize` doesn't know the exact height of each item. It estimates the unrendered ones from the average. When you jump by dragging the scrollbar far into an unmeasured region, the first position is an estimate and may be corrected slightly. +- A better `ItemSize` still helps, because it makes the first render and the first scroll range closer to reality. + +### 3.2 Hybrid scroll anchoring + +In .NET 10, `Virtualize` turned off the browser's native scroll anchoring, because spacer resizes could otherwise start a feedback loop. As a result, content jumped whenever an item above the viewport changed height. .NET 11 uses one of two paths instead: + +![Decision flow: tables and browsers without overflow-anchor use manual ResizeObserver compensation; other lists use native CSS scroll anchoring](images/diagrams/scroll-anchoring-paths.png) + +*Figure 2. The path is chosen by feature detection (`CSS.supports('overflow-anchor', 'auto')`) and by whether the spacers' parent is a table section. RC1 does no user-agent sniffing.* + +You can see the choice in the DOM: + +- In the sample's `div`-based feed, the scroll container keeps `overflow-anchor: auto` and only the spacers get `overflow-anchor: none`. +- In the `
` grid, the container itself gets `overflow-anchor: none` and the manual path takes over. + +Chrome, Firefox, and Playwright's WebKit build all behaved this way, and all three report `overflow-anchor` support. Real Safari is a different story: according to MDN's compatibility data it supports `overflow-anchor` only from **Safari 27**. On older Safari and iOS versions, even `div` lists take the manual path. Playwright's WebKit build doesn't exercise that path. + +### The `OverscanCount` default changed from 3 to 15 + +More overscan means fewer blank moments during fast scrolling and more items to average heights over. It also means: + +- **More DOM.** The sample's feed renders 37–38 cards at the top of a 100,000-item list, compared with about 7 visible ones. +- **Bigger `ItemsProvider` requests.** With 15 items before and after the visible range, a request asks for roughly `visible + 30` items instead of `visible + 6`. +- **No breaking-change notice.** The change isn't listed on the .NET 11 or ASP.NET Core 11 breaking-changes pages, so check for it yourself when you upgrade. + +`QuickGrid` deliberately keeps `OverscanCount = 3`, because grid rows are heavier. See [section 13](#choosing-itemsize-and-overscancount) for how to choose. + +## The sample application: LiveStream + +The sample is a Blazor Web App (Interactive Server) that renders a deterministic dataset of 100,000 synthetic events. Every scenario in this article is a page in it. The sample isn't published with this article. The code blocks below are excerpts from it, and the layout shows where each excerpt lives. + +![LiveStream home page showing scenario cards, the runtime version 11.0.0-rc.1, and the strict Content-Security-Policy](images/01-home.png) + +```text +LiveStream/ +├── global.json # pins the .NET 11 RC1 SDK +├── src/LiveStream/ +│ ├── Components/ +│ │ ├── Pages/ActivityFeed.razor # ItemsProvider + AnchorMode.Start +│ │ ├── Pages/LiveChat.razor # Items + AnchorMode.End + InitialItemIndex +│ │ ├── Pages/DataGrid.razor #
+ ScrollToItemAsync +│ │ ├── Pages/Labs/AnchorLab.razor +│ │ ├── Pages/Labs/PerfLab.razor +│ │ └── Stream/ # ActivityCard, ChatMessage, StatsBar, ReadyMarker +│ ├── Models/StreamItem.cs +│ ├── Services/SyntheticDataset.cs # shared, immutable 100k items +│ ├── Services/ActivityFeedStore.cs # per-circuit view + ItemsProvider +│ ├── Security/ContentSecurityPolicy.cs +│ └── wwwroot/js/ # csp-monitor.js, stream-interop.js +├── baseline/CspBaseline.Net10/ # same CSP on .NET 10, for comparison +├── tests/LiveStream.Tests/ # xUnit + WebApplicationFactory +├── tools/ApiSurface.cs # dumps the Virtualize API (section 3) +└── e2e/ # Playwright tests, measurement scripts, results/ +``` + +Technical choices: + +- **Interactive Server** keeps the sample easy to run. The virtualization code is the same on WebAssembly. [Section 17](#browser-and-layout-caveats) covers the differences. +- **`net11.0`**, with the SDK pinned in `global.json`. +- **100,000 records**, with messages ranging from one to six lines. About 18% have an expandable diagnostics block. +- **150–400 ms simulated latency** in the feed's provider, with cancellation. +- **A strict CSP header on every page:** `style-src 'self'` and a per-request nonce for the one inline script (the import map). A badge in the corner counts violations live. + +To try the ideas yourself, start from the Blazor Web App template on the .NET 11 SDK: + +```bash +dotnet new blazor --interactivity Server --all-interactive -o LiveStream +cd LiveStream +dotnet run +``` + +Then add the pieces from the excerpts: the model and provider ([next section](#the-data-model-and-the-itemsprovider)), the feed and chat pages, and the CSP middleware ([Content Security Policy](#content-security-policy-why-virtualization-used-to-break)). + +## The data model and the `ItemsProvider` + +The model is a record: + +```csharp +public sealed record StreamItem( + long Id, + string Author, + string Message, + string? Details, + DateTimeOffset CreatedAt, + StreamItemKind Kind) +{ + /// + /// Identity by key. Virtualize uses ItemComparer to tell whether items were prepended + /// or appended between ItemsProvider calls. The default (record value equality) compares + /// every field, so an edited item would look like a different item; the Id doesn't change. + /// + public static IEqualityComparer ById { get; } = + EqualityComparer.Create((a, b) => a?.Id == b?.Id, item => item.Id.GetHashCode()); +} +``` + +Why a comparer, when records already have value equality? When data comes from an `ItemsProvider` and the total count grows, `Virtualize` compares the first item it rendered before with the first item of the new result. A mismatch means "items were inserted above". Record equality works until that first rendered item is *edited* in a refresh where the count also grew, which happens constantly in a live feed. The old and new versions then compare unequal, and an edit looks like a prepend. A key-based comparer avoids that. + +The RC1 SDK agrees. Building the sample without a comparer produced a new analyzer warning: + +```text +warning BL0011: Virtualize uses 'ItemsProvider' without 'ItemComparer'. +Set ItemComparer to an IEqualityComparer that identifies items by a unique key. +``` + +(With in-memory `Items`, `Virtualize` ignores `ItemComparer` and uses `EqualityComparer.Default`.) + +The provider is the store method that `Virtualize` calls: + +```csharp +private async ValueTask> GetAsync(ItemsProviderRequest request, bool newestFirst) +{ + Interlocked.Increment(ref _providerCalls); + LastRequest = (request.StartIndex, request.Count); + + try + { + var (min, max) = Latency; + if (max > 0) + { + // Simulated network + database time. Virtualize cancels this token + // when the user scrolls on before the response arrives. + await Task.Delay(Random.Shared.Next(min, max + 1), request.CancellationToken); + } + } + catch (OperationCanceledException) + { + Interlocked.Increment(ref _canceledCalls); + throw; + } + + return GetRange(request.StartIndex, request.Count, newestFirst); +} +``` + +- **`request.StartIndex`** is the index of the first item to return. +- **`request.Count`** covers the visible range plus overscan on both sides. It's larger in .NET 11 because of the new default. +- **`request.CancellationToken`** is canceled when a newer request replaces this one. In the browser test, scrolling quickly through the feed produced canceled provider calls in all three engines. Pass the token all the way down to your database or HTTP call. +- **`TotalItemCount`** (the second constructor argument of the result) sets the spacer sizes. It has to be accurate and cheap. + +> **Offset pagination gets expensive.** `Skip(n).Take(m)` is fine for a demo. Deep offsets can be slow in relational databases, and running `COUNT(*)` on every request adds up. For production feeds, consider keyset (cursor) pagination behind a layer that maps virtual indexes to stable cursors, and cache the total count. + +One design detail in the sample is worth copying. The 100,000 base records are a **shared, immutable singleton**. Each circuit keeps only its own new events in a small list, so adding an item costs O(1) and a new circuit costs a few hundred bytes instead of a copy of the dataset. + +## Scenario 1: an activity feed with `AnchorMode.Start` + +New activity arrives at the **top** of the feed. It's newest first, and index 0 is the newest event. + +```razor +
+ + + + + + + + +

No activity has been recorded yet.

+
+
+
+``` + +`provider` is assigned once in `OnInitialized` (`provider = Store.GetNewestFirstAsync;`), so every render passes the same delegate instance. New events, whether from the simulated live stream or the "+5 events" button, aren't pushed to the UI one at a time. They go into a queue, and a 250 ms `PeriodicTimer` flushes them in batches: + +```csharp +private async Task FlushAsync() +{ + List batch = []; + while (pending.TryDequeue(out var item)) + { + batch.Add(item); + } + + if (batch.Count == 0 || virtualize is null) + { + return; + } + + Store.Add(batch); + + if (!atTop) + { + unseen += batch.Count; + announcement = $"{unseen} new events above."; + } + + // ItemsProvider data changed outside of Virtualize: ask it to re-request the visible range. + await virtualize.RefreshDataAsync(); + StateHasChanged(); +} +``` + +`atTop` comes from a small JS helper, shown in the next section, that reports when the user reaches or leaves the top edge. It uses the same definition as `AnchorMode.Start` in RC1: `scrollTop < 1`. A looser threshold would create a gap. The page would think the user was at the top and skip the pill, while `Virtualize` would already be keeping the new events out of view. + +![Activity feed after five live events: newest first, variable-height cards, a stats bar with 100,005 total events and 38 cards in the DOM, and the green CSP badge](images/02-activity-feed.png) + +### Expected UI behavior, and what I measured + +| Situation | Expected | Measured (Chrome, Firefox, WebKit) | +|---|---|---| +| At the top, 5 events arrive | The view stays at the top and shows the new events | `scrollTop` stays 0; the first visible card is the newest | +| Reading older events, 5 events arrive | What you're reading doesn't move; an "↑ 5 new events" pill appears | Same first visible card, offset changed by ≤ 1 px | +| A card *above* the viewport expands | Visible content stays put | 0 px shift (wheel scrolling, 6/6 runs per engine) | +| DOM size | Only a window of the 100,000 events | 37–38 cards rendered | +| Fast scrolling with 150–400 ms latency | Stale requests are canceled | Canceled provider calls > 0 in every run of the test | + +![Activity feed while scrolled down: an "↑ 5 new events" pill floats above the list while the visible cards stay in place](images/03-activity-feed-new-events.png) + +![Animated: new events appear at the top; while reading older events, new events don't move the view; clicking the pill jumps to the newest](images/feed-anchor-start.gif) + +*The pill calls `ScrollToItemAsync(0)`. The GIF is a screen recording of the sample in Chrome.* + +## Scenario 2: a chat or log viewer with `AnchorMode.End` + +In a chat or log viewer, new items arrive at the **bottom**, and the list should open there too: + +```razor +
+ + + +
+``` + +- `Items` is a `List`. With in-memory `Items`, `Virtualize` re-reads the collection on every render, so appending is just `messages.Add(...)` followed by `StateHasChanged()`. You don't need `RefreshDataAsync`. +- `InitialItemIndex="@(messages.Count - 1)"` opens the list at the latest message. It's applied once, on the first interactive render. +- `AnchorMode.End` follows new messages **only while the user is at the bottom**. In RC1, "at the bottom" means less than 2 px away. + +The core UX rule for chat UIs is to follow new messages only while the user is already following the live edge. `AnchorMode.End` implements that rule. The sample adds the other half: an unread counter and a way back to the bottom. A tiny JS module reports when the user leaves or reaches an edge, using the same thresholds as `Virtualize` (1 px for the top, 2 px for the bottom). It calls .NET only when that state flips, not on every scroll event: + +```js +export function watchEdge(element, dotNetRef, edge, threshold) { + let atEdge = null; + let frame = 0; + + const check = () => { + frame = 0; + const distance = edge === 'end' + ? element.scrollHeight - element.clientHeight - element.scrollTop + : element.scrollTop; + const now = distance < threshold; + if (now !== atEdge) { + atEdge = now; + dotNetRef.invokeMethodAsync('OnEdgeChanged', now); + } + }; + // … a scroll listener and a ResizeObserver schedule check() once per animation frame +} +``` + +```razor +@if (unread > 0) +{ + +} +``` + +![Live chat after scrolling up: the view stays on older messages and a "↓ 20 new messages" pill is shown at the bottom](images/04-live-chat-unread.png) + +### Expected UI behavior, and what I measured + +| Situation | Expected | Measured | +|---|---|---| +| Page opens | At the bottom, message #100,000 visible | ✔ all engines (`InitialItemIndex`) | +| At the bottom, a message arrives | Scrolls to show it | With the sample's guard: ✔ 30/30 follow checks per engine. `AnchorMode.End` alone: Chrome 29/30, Firefox 28/30, **WebKit 20/30** (see below) | +| Scrolled up, 20 messages arrive | View stays put; "↓ 20 new messages" pill | ✔ all engines, `scrollTop` unchanged | +| User returns to the bottom | Following resumes | ✔ all engines | + +![Animated: at the bottom new messages are followed; after scrolling up, new messages don't pull the view down; clicking the pill returns to the live edge and following resumes](images/chat-anchor-end.gif) + +### An RC1 caveat: End-follow sometimes stops short + +I ran the chat tests 10 times per engine with the sample's safety net turned off. Each run contains three checks that depend on `AnchorMode.End` following an append: a new message, a message sent from the composer, and a new message after returning to the bottom. They passed **29/30 in Chrome, 28/30 in Firefox, and 20/30 in Playwright's WebKit**. In every failure, the list ended **29–77 px short** of the bottom 600 ms after the append (Chrome 72 px, Firefox 61 px, WebKit 29–77 px), so the new message was only partly visible. Outside the test suite the miss was rare: in isolated WebKit runs. + +The sample therefore adds a small, explicit safety net. It only acts if the page's edge watcher considered the user to be at the live edge (less than 2 px, the same as `AnchorMode.End`) when the message arrived, *and* the list then ended up between 1 and 120 px short of the bottom: + +```js +export function stickToBottom(element, tolerance) { + requestAnimationFrame(() => { + const distance = element.scrollHeight - element.clientHeight - element.scrollTop; + if (distance > 1 && distance <= tolerance) { + element.scrollTop = element.scrollHeight; + } + }); +} +``` + +With the guard on (the sample's default), the same 10× run passed **all 40 chat tests, including 30/30 follow checks, in every engine**. The guard-off numbers above were measured with the guard disabled, to observe `AnchorMode.End` on its own. An End-anchoring fix is already merged for RC2 ([dotnet/aspnetcore#69388](https://github.com/dotnet/aspnetcore/pull/69388)). It changes exactly the condition that decides when to pin, so retest before you keep or remove a workaround like this. Playwright's WebKit on Windows is also not Safari on macOS or iOS, so test on real devices too. + +## Understanding every `AnchorMode`, measured + +The docs describe the modes in terms of scroll position. To find out what they actually do, the sample's **AnchorMode lab** (`/lab/anchor`) prepends or appends 5 items at the top, middle, and bottom of a 2,000-item variable-height list. It runs every mode with both `Items` and `ItemsProvider`, in Chrome, Firefox, and WebKit. + +![A 3×3 grid showing None, Start, and End for three situations: at the top with items prepended, reading the middle, and at the bottom with items appended](images/diagrams/anchor-modes.png) + +| Where the user is | What arrives | `None` | `Start` (default) | `End` | `Start \| End` | +|---|---|---|---|---|---| +| At the top | 5 items prepended | Keeps place | **Shows the new items** | Keeps place | **Shows the new items** | +| At the top | 5 items appended | Keeps place | Keeps place | Keeps place | Keeps place | +| In the middle | 5 items prepended | Keeps place | Keeps place | Keeps place | Keeps place | +| In the middle | 5 items appended | Keeps place | Keeps place | Keeps place | Keeps place | +| At the bottom | 5 items prepended | Keeps place | Keeps place | Keeps place | Keeps place | +| At the bottom | 5 items appended | Keeps place | Keeps place ⚠️ | **Follows the new items** | **Follows the new items** | + +*"Keeps place" means the item that was first visible before the change was still the first visible item afterward. The matrix records which item that was, not its pixel offset; sections 6 and 10 report pixel shifts. `Items` and `ItemsProvider` fell into the same category in every cell. 46 of the 48 scenarios gave the same result in Chrome, Firefox, and WebKit (144 measurements in total). The ⚠️ cell covers both exceptions, which were WebKit with `Start`, for `Items` and for `ItemsProvider`.* + +Three conclusions: + +1. **Keeping your place is the default everywhere.** `AnchorMode` doesn't turn anchoring on or off. It decides what happens **at the edges**: `Start` shows new items when you're at the very top (`scrollTop < 1`), and `End` follows new items when you're at the very bottom (within 2 px). +2. **`None` keeps the *content* still, not the `scrollTop` number.** The docs say `None` keeps "the current scroll position". With `None`, though, prepending 5 items at the top *increased* `scrollTop` by about 400 px, so that the same item stayed in view. If you want new items at the top to become visible, that's `Start`. +3. **Between the edges, all four modes behave the same.** + +**⚠️ WebKit and infinite lists.** In Playwright's WebKit build, appending items while the user was at the very end of a `Start` list (the default) moved the visible content. It moved **214 px** with `Items` and **366–486 px** with `ItemsProvider`, in 3 of 3 runs. With `AnchorMode.None` it moved **0 px**, and Chrome and Firefox moved 0 px in both modes. That's exactly the classic infinite-scroll pattern: reach the end, and more items load. If a list only ever grows at the end and doesn't need top pinning, **set `AnchorMode="VirtualizeAnchorMode.None"`** and test on real Safari. + +![The AnchorMode lab page with the four mode buttons and prepend/append buttons](images/08-anchor-lab.png) + +### Gotcha: the docs' Razor shorthand doesn't compile + +The release notes and the virtualization docs show this: + +```razor + @* from the docs *@ +``` + +On RC1, that fails with `CS0103: The name 'Start' does not exist in the current context`. Razor treats non-string component parameters as C# expressions, so write the enum out in full: + +```razor + + +``` + +### Other details worth knowing + +- **Upgraded lists get `Start` automatically.** It's the default because it matches how lists behaved before. If a list shouldn't pin to anything, such as a sortable grid or an infinite list that grows at the end, set `None` explicitly. +- **`AnchorMode` can change at runtime.** `Virtualize` sends the new value to JavaScript after the next render. +- **Keyboard:** Pressing End in the scroll container turns on bottom-following even when `End` isn't set, and Home clears it. `ScrollToItemAsync` also clears it. +- **Deletions above the viewport are not anchored.** Inserts and height changes are, but removing items above the reader still moves content. That's an open backlog request ([dotnet/aspnetcore#66509](https://github.com/dotnet/aspnetcore/issues/66509)). +- **`Start | End` is allowed,** but the design discussion admits there's no known real use case for it. + +## Refreshing virtualized data without thrashing + +With an `ItemsProvider`, `Virtualize` can't know that your data changed. Call `RefreshDataAsync()`. When the change comes from outside Blazor's event pipeline, such as a timer, a SignalR client, or a message-bus handler, marshal it onto the renderer first. The handler below is illustrative. The sample does the same thing with its `PumpAsync` loop, which calls `InvokeAsync(FlushAsync)` (section 6): + +```csharp +// Called from a timer, a SignalR client, or a message-bus handler, not from a Blazor event. +private Task OnEventsArrivedAsync(IReadOnlyList batch) => InvokeAsync(async () => +{ + Store.Add(batch); + + if (virtualize is not null) + { + await virtualize.RefreshDataAsync(); // re-requests the current window + } + + StateHasChanged(); // RefreshDataAsync doesn't render by itself +}); +``` + +Rules that matter in practice: + +- **Get back onto the renderer's synchronization context** with `InvokeAsync`, as above. `RefreshDataAsync` must run there too. +- **Call `StateHasChanged()` afterwards** when the refresh doesn't come from a Blazor event handler. `RefreshDataAsync` fetches, but it doesn't render. +- **Batch.** In RC1, `RefreshDataAsync()` also **resets the running average item height**, so every refresh starts measuring from scratch. Refreshing on every message of a busy stream means more provider calls, more renders, *and* less accurate spacer estimates. The sample drains its queue with a 250 ms `PeriodicTimer`, so the list refreshes at most four times per second, however fast events arrive. +- **Clean up.** Implement `IAsyncDisposable`: cancel timers and loops, dispose `DotNetObjectReference`s and JS module references, and catch `JSDisconnectedException` when the circuit is already gone. The RC1 SDK nudges you here too, with a new analyzer warning: *BL0016: JS interop call 'InvokeAsync' is not guarded with a try/catch block*. +- **Pass the cancellation token through.** When a newer request supersedes an older one, the older token is canceled. Ignoring it just wastes backend work. + +## Variable heights and expansion + +Every card in the sample's feed has a different height, and about 18% can expand a diagnostics block. Three rules make that work well: + +1. **Keep per-item UI state in the parent, not in the item component.** `Virtualize` disposes item components that scroll out of the window. An `Expanded` field inside `ActivityCard` would be lost as soon as the card scrolled away. The sample keeps a `HashSet` of expanded IDs in the page and passes `Expanded` down as a parameter. +2. **Give each item one root element, and no vertical margins.** Heights are measured from the rendered content between the spacers, and collapsing margins between siblings make that fragile. Use padding and borders inside the item instead. +3. **Reserve space for content that loads later.** An image without `width` and `height` (or `aspect-ratio`) changes the row height after it loads. Anchoring compensates, but it's better not to cause the shift in the first place. + +### How stable is it? Measurements + +In this test I scrolled with real mouse-wheel input, then expanded an item rendered just *above* the viewport, and recorded how far the first visible item moved. Six runs per cell: + +| Layout (anchoring path) | Chrome | Firefox | WebKit | +|---|---|---|---| +| `div` feed (native CSS anchoring) | **0 px** ×6 | **0 px** ×6 | **0 px** ×6 | +| `
` grid (manual `ResizeObserver`) | 41–42 px ×4, 222 px ×1, 0 px ×1 | 41–42 px ×4, 0 px ×2 | 0–1 px ×5, 42 px ×1 | +| `
` grid, after ordinary renders first | ≤ 1 px ×6 | 0 px ×6 | ≤ 1 px ×6 | + +What's behind the table numbers: + +- **Tables have a gap in RC1.** On the manual path, rows are added to the `ResizeObserver` after ordinary renders but *not* after scroll-triggered renders. A row that changes height right after a scroll can be observed for the first time with its new height already applied, so there's nothing to compensate against. When I triggered ordinary renders first (expanding and collapsing another row), the shift was **≤ 1 px in 6/6 runs in every engine**. Right after scrolling, Chrome and Firefox usually shifted by one row line (41–42 px; 16 of 24 runs), and Chrome occasionally by about 220 px (2 of 12 runs). WebKit shifted 42 px in 1 of 12 runs and ≤ 1 px otherwise. +- **Programmatic jumps are harder than wheel scrolling.** I also set `scrollTop` directly, let the list settle, and then expanded an item above the viewport. In Chrome and WebKit, the `div` feed didn't move in any run. Firefox moved it 168 px in 1 of 7 runs, and 132–186 px in 3 of 7 runs in an earlier session. The grid moved 41–132 px in Chrome, 0–42 px in Firefox, and 0 px in WebKit. If your app scrolls programmatically and then changes content above the viewport, test that combination. + +## Data grids: tables, jumping to rows, and QuickGrid + +The sample's grid virtualizes `` elements inside ``. The visible column header lives in a separate table *outside* the scroll container: + +```razor +@* The visible header sits outside the scroll container. A sticky inside it would cover the + row that InitialItemIndex / ScrollToItemAsync align to the container's top edge. *@ +
+
……
+ + +
+ + … + … @* column headers for assistive technology *@ + + + + … + + + +
+
+ +``` + +```css +/* Same and table-layout: fixed in both tables; scrollbar-gutter keeps the columns aligned. */ +.grid-header { flex: none; overflow-y: hidden; scrollbar-gutter: stable; } +.grid-frame .grid-viewport { flex: 1 1 0; scrollbar-gutter: stable; } +.event-grid { width: 100%; table-layout: fixed; } +``` + +```csharp +private async Task JumpAsync() +{ + if (virtualize is not null && jumpTo is int row) + { + await virtualize.ScrollToItemAsync(row - 1); + } +} +``` + +![Event log grid after "Go to row 75000": row 75,000 at the top, directly below the column header, and row 75,001 expanded with its diagnostics](images/05-data-grid.png) + +- **`SpacerElement="tr"`** keeps the markup valid. `Virtualize` gives the spacer rows `display: table-row` itself. +- **`AnchorMode.None`** is set explicitly, because a grid that users sort and filter shouldn't pin to an edge. +- **`ScrollToItemAsync`** ("Go to row") and **`InitialItemIndex`** (`/grid?row=500`) put the requested row at the top of the viewport in every engine. Keep in mind: + - `ScrollToItemAsync` scrolls instantly (no smooth scrolling). It aligns the item with the **top edge of the scroll container** and cancels any earlier call that's still running (the last call wins). + - A sticky `` *inside* the scroll container would cover exactly that row. That's why the sample keeps the header outside the container, as shown above. + - It throws `InvalidOperationException` if called before the first interactive render. Use `InitialItemIndex` for the starting position. + - The index is a **position in the list**, not a database identity. If your provider's ordering isn't stable, the jump can land on a different record. +- **An RC1 issue with `InitialItemIndex`:** When the grid opened with `?row=75000`, the *next* ordinary render (expanding a visible row) moved the rows by **82 px in Chrome, −53 px in Firefox, and 63 px in WebKit**, in 3/3 runs each, while `scrollTop` stayed the same. The top spacer is recomputed once positioning ends. After `ScrollToItemAsync` the same action moved them 0 px. RC2 freezes the spacer item size during initial positioning ([dotnet/aspnetcore#69170](https://github.com/dotnet/aspnetcore/pull/69170)). +- **Size `ItemSize` for the real rows.** The grid's rows average about 62 px (38.6–122 px), because messages wrap. The sample keeps the short columns on one line (`white-space: nowrap`) so that only the message column wraps. +- **`` layouts use the manual compensation path.** See the measurements in [section 10](#variable-heights-and-expansion). + +**QuickGrid** forwards `InitialItemIndex` and `ScrollToItemAsync` in .NET 11. Its `AnchorMode` and `ItemComparer` parameters are marked `[Experimental("ASP0030")]` in RC1, and that attribute has already been removed for RC2. It keeps `OverscanCount = 3`. Two QuickGrid issues filed against RC1 are still open: Start anchoring drifts after prepends in Server render modes, and the grid sends duplicate provider requests ([#69380](https://github.com/dotnet/aspnetcore/issues/69380), [#69381](https://github.com/dotnet/aspnetcore/issues/69381)). If you rely on QuickGrid anchoring, test it specifically. + +## Performance: what I measured + +I didn't want illustrative numbers here, so the sample's **Perf lab** (`/lab/perf`) renders the same row markup in three ways: a plain `foreach`, `Virtualize` with `Items`, and `Virtualize` with an `ItemsProvider`. A Playwright script measured each variant three times in fresh Chrome contexts and took the median. + +![Dot plots on log scales: foreach with 100,000 items takes 112 s to become interactive, creates 400,078 DOM elements and sends 112 MB over the WebSocket; Virtualize takes about 125 ms, 256 elements and 34 KB](images/perf-foreach-vs-virtualize.png) + +| Variant (100,000 items unless noted) | HTML | First row painted | Interactive | DOM elements | Rows rendered | JS heap | WebSocket until interactive | +|---|---|---|---|---|---|---|---| +| `foreach`, 10,000 items | 2.9 MB | 77 ms | 2.8 s | 40,078 | 10,000 | 21.2 MB | 5.6 MB | +| `foreach` | 28.6 MB | 248 ms | **112.4 s** | 400,078 | 100,000 | 189.5 MB | 111.9 MB | +| `Virtualize` `Items`, fixed heights, overscan 15 | 11.7 KB | 106 ms | **125 ms** | 288 | 52 | 2.7 MB | 39 KB | +| `Virtualize` `Items`, variable heights, overscan 15 | 11.7 KB | 109 ms | **128 ms** | 256 | 44 | 2.7 MB | 34 KB | +| `Virtualize` `ItemsProvider`, variable heights, overscan 15 | 11.7 KB | 108 ms | **125 ms** | 256 | 44 | 2.7 MB | 34 KB | + +*Published Release build, Production environment, Blazor Server on localhost. Chrome 153 on an AMD Ryzen 9 5900HX. Median of 3 fresh browser contexts per variant. "Interactive" is the time from navigation until the first interactive render batch was applied. JS heap is in MiB; HTML and WebSocket sizes use decimal units (1 MB = 1,000,000 bytes).* + +What the numbers say: + +- **Prerendering hides the problem for a moment.** The `foreach` page painted its first row after 248 ms, because the rows are in the HTML. It then took **112 seconds** to become interactive. The circuit had to send 112 MB of render batches for 100,000 rows, and the browser recorded 92 seconds of long tasks on the main thread. Even at 10,000 items it took 2.8 s. +- **With `Virtualize`, the rendered window sets the cost, not the list length.** For 100,000 items it took about 125 ms to become interactive, with 256–288 DOM elements, 2.7 MB of JS heap, and 34–39 KB over the WebSocket. +- **`Items` and `ItemsProvider` cost the same on the UI side.** The difference is on the server: `Items` needs the collection in memory, while a provider fetches only the window. + +### The overscan trade-off + +![Bar charts: overscan 3 renders 20–28 rows but leaves the viewport blank in 52–55 of 60 samples during a fast fling; overscan 15 renders 44–52 rows, with 3 blank samples for fixed heights and 39 for variable heights; overscan 30 renders 74 rows and 32 blank samples](images/perf-overscan.png) + +To stress each configuration, the harness "flings" the list: 60 mouse-wheel events of 600 px each in about 2.4 seconds (≈ 15,000 px/s). After each event it checks whether the center of the viewport shows a row or an empty spacer. + +- **Fixed heights:** Moving from overscan 3 to 15 cut blank samples from **55 to 3 out of 60**, at the cost of 52 instead of 28 rendered rows. +- **Variable heights:** Overscan helps less here: 52, 39, and 32 blank samples for overscan 3, 15, and 30. Every window change must be measured and rendered, and the running average is still converging while you fling through unmeasured regions. +- **Server traffic while scrolling** was 0.6–1.2 MB per fling on Blazor Server. That's the render batches for each new window, and it grows with overscan and row complexity. + +Treat these numbers as a *relative* comparison, taken on one machine with the server on localhost. Over a real network, Blazor Server adds a round trip to every window change, which makes overscan more valuable. On WebAssembly there's no round trip, but rendering competes with everything else on the main thread. + +The main message: **`Virtualize` limits how much UI you render. It doesn't make your data access faster.** If your provider runs an expensive `COUNT(*)` on every request, slows down at deep offsets, returns far more columns than the row needs, or ignores the cancellation token, virtualization won't hide that. + +## Choosing `ItemSize` and `OverscanCount` + +**`ItemSize`** + +- It's the starting estimate. `Virtualize` uses it before any measurements exist and for the first scroll range. +- Set it close to your real average item height. Measure it in the browser, as the sample did for its grid (about 62 px). A value that's far off makes the first layout and scrollbar noticeably wrong until measurements arrive. +- Variable-height support doesn't make it irrelevant. Changing `ItemSize` at runtime resets the measured average. + +**`OverscanCount`** + +| Lower (e.g. 3) | Higher (e.g. 15–30) | +|---|---| +| Fewer DOM nodes and components | Fewer blank moments during fast scrolling | +| Smaller render batches and provider requests | More items to average variable heights over | +| More risk of placeholders or empty space when scrolling fast | More DOM, more component instances, bigger batches | + +Start with the .NET 11 default of 15, then profile with your real row template on the slowest devices you support. Heavy rows, such as grids with many cells or rich cards, may justify going back down. `QuickGrid` stays at 3 for exactly that reason. `MaxItemCount` (default 100) still caps how many items are rendered, plus 2 × `OverscanCount`. Don't set it lower than what a tall window can show. + +## Content Security Policy: why virtualization used to break + +A strict policy like the following blocks inline `style` attributes: + +```http +Content-Security-Policy: default-src 'self'; style-src 'self' +``` + +That applies both to attributes in the server-rendered markup and to attributes set with `element.setAttribute('style', …)`. Browsers report them as **`style-src-attr`** violations. Nonces don't help, because they never apply to attributes, and `'unsafe-hashes'` doesn't scale to values that change on every scroll. + +Up to .NET 10, `Virtualize` rendered its spacers like this (captured from the sample's .NET 10.0.10 baseline): + +```html + + +``` + +With the same strict policy as the .NET 11 app, the baseline logged **5 `style-src-attr` violations**, with samples such as `height: 9600000px; flex-shrink: 0;`. They came from both the prerendered HTML and `blazor.web.js`. Worse, the list **collapsed**. The spacers had no height, so a 100,000-item list had a scroll range of **1,227 px**, and about 15 rows were all anyone could reach. Chrome, Firefox, and WebKit gave identical results. + +![Side by side: the .NET 10 baseline with a red "5 violations" badge, and the .NET 11 feed with a green "0 violations" badge under the same policy](images/09-csp-side-by-side.png) + +![Animated: trying to scroll the .NET 10 list goes nowhere; under the same policy, the .NET 11 list keeps scrolling with 0 violations](images/csp-net10-vs-net11.gif) + +### What .NET 11 does instead + +![.NET 10 renders a style attribute that CSP blocks; .NET 11 renders numbers in data attributes that a MutationObserver applies through CSSOM](images/diagrams/csp-before-after.png) + +In .NET 11, the C# side renders **numbers**, not styles: + +```html + + + +``` + +- `data-blazor-virtualize-reserved-height` holds the height as a unitless number, for both spacers and default placeholders. +- `data-blazor-virtualize-loop-breaker-transform` holds a vertical offset for the trailing spacer, when one is needed. +- A `MutationObserver` in `blazor.web.js` watches those two attributes on the spacers. It parses each value, accepts only finite numbers, and applies it through the CSS Object Model, with `element.style.setProperty('height', …)` or `translateY(…)`. + +Browsers don't apply `style-src` to properties set through an element's `style` object. MDN documents this, and the web-platform-tests confirm it for current Chrome, Firefox, and Safari. If you explain this to your security team, be precise: **the CSP specification doesn't formally exempt CSSOM**. It even describes gating some CSSOM setters on `'unsafe-eval'`. The guarantee is how browsers actually behave, and that's what the framework relies on. + +> **Don't test for "no `style` attribute in the DOM".** After hydration, the .NET 11 spacers *do* show a `style` attribute in DevTools: +> +> ```html +> +> ``` +> +> That's the serialization of the properties set through CSSOM, and it's allowed. The .NET 10 spacers show a `style` attribute too, but there it's inert, because the browser refused it. Instead, check for **violations**, and check that the **computed height equals the reserved height**. + +### Sending a strict CSP from a Blazor Web App + +Send the policy as an **HTTP response header**, not a `` tag. Only a header supports `frame-ancestors`, `report-to`, and `Content-Security-Policy-Report-Only`. The sample generates a nonce per request, because the Blazor Web App's `` is an inline ` + ```` ### External/CDN file Support diff --git a/docs/en/framework/ui/mvc-razor-pages/overall.md b/docs/en/framework/ui/mvc-razor-pages/overall.md index b029fda57c..5e0fc41435 100644 --- a/docs/en/framework/ui/mvc-razor-pages/overall.md +++ b/docs/en/framework/ui/mvc-razor-pages/overall.md @@ -57,14 +57,11 @@ There are a set of standard JavaScript/CSS libraries that comes pre-installed an - [JQuery Validation](https://jqueryvalidation.org/) for client side & [unobtrusive](https://github.com/aspnet/jquery-validation-unobtrusive) validation - [FontAwesome](https://fontawesome.com/) as the fundamental CSS font library. - [SweetAlert](https://sweetalert.js.org/) to show fancy alert message and confirmation dialogs. -- [Toastr](https://github.com/CodeSeven/toastr) to show toast notifications. - [Lodash](https://lodash.com/) as a utility library. - [Luxon](https://moment.github.io/luxon/) for date/time operations. -- [JQuery Form](https://github.com/jquery-form/form) for AJAX forms. - [bootstrap-datepicker](https://github.com/uxsolutions/bootstrap-datepicker) to show date pickers. - [Select2](https://select2.org/) for better select/combo boxes. -- [Timeago](http://timeago.yarp.com/) to show automatically updating fuzzy timestamps. -- [malihu-custom-scrollbar-plugin](https://github.com/malihu/malihu-custom-scrollbar-plugin) for custom scrollbars. +- [timeago.js](https://timeago.org/) to show automatically updating fuzzy timestamps. You can use these libraries directly in your applications, without needing to manually import your page. @@ -140,7 +137,7 @@ ABP provides a flexible and modular Bundling & Minification system to create bun - + ``` diff --git a/docs/en/framework/ui/mvc-razor-pages/theming.md b/docs/en/framework/ui/mvc-razor-pages/theming.md index 138b52e3d2..dafbfcb2d3 100644 --- a/docs/en/framework/ui/mvc-razor-pages/theming.md +++ b/docs/en/framework/ui/mvc-razor-pages/theming.md @@ -44,14 +44,11 @@ All the themes must depend on the [@abp/aspnetcore.mvc.ui.theme.shared](https:// * [JQuery Validation](https://github.com/jquery-validation/jquery-validation) for client side & [unobtrusive](https://github.com/aspnet/jquery-validation-unobtrusive) validation * [FontAwesome](https://fontawesome.com/) as the fundamental CSS font library. * [SweetAlert](https://sweetalert.js.org/) to show fancy alert message and confirmation dialogs. -* [Toastr](https://github.com/CodeSeven/toastr) to show toast notifications. * [Lodash](https://lodash.com/) as a utility library. * [Luxon](https://moment.github.io/luxon/) for date/time operations. -* [JQuery Form](https://github.com/jquery-form/form) for AJAX forms. * [bootstrap-datepicker](https://github.com/uxsolutions/bootstrap-datepicker) to show date pickers. * [Select2](https://select2.org/) for better select/combo boxes. -* [Timeago](http://timeago.yarp.com/) to show automatically updating fuzzy timestamps. -* [malihu-custom-scrollbar-plugin](https://github.com/malihu/malihu-custom-scrollbar-plugin) for custom scrollbars. +* [timeago.js](https://timeago.org/) to show automatically updating fuzzy timestamps. These libraries are selected as the base libraries and available to the applications and modules. @@ -60,7 +57,7 @@ These libraries are selected as the base libraries and available to the applicat There are some abstractions in the ABP to make your code independent from some of these libraries too. Examples; * [Tag Helpers](tag-helpers) makes it easy to generate the Bootstrap UIs. -* JavaScript [Message](javascript-api/message.md) and [Notification](javascript-api/notify.md) APIs provides abstractions to use the Sweetalert and Toastr. +* JavaScript [Message](javascript-api/message.md) and [Notification](javascript-api/notify.md) APIs provide abstractions to use the SweetAlert and the built-in toast implementations. * [Forms & Validation](forms-validation.md) system automatically handles the validation, so you mostly don't directly type any validation code. ### The Standard Layouts diff --git a/docs/en/get-started/microservice.md b/docs/en/get-started/microservice.md index ec2d4eb513..41d61647f2 100644 --- a/docs/en/get-started/microservice.md +++ b/docs/en/get-started/microservice.md @@ -110,11 +110,11 @@ In this step, you can choose which languages your application will support. * Click Add Custom Language if you want to add a language that is not listed. -Click the Next button to see *.NET Aspire* configuration selection: +Click the Next button to see *Aspire* configuration selection: ![abp-studio-new-solution-dialog-aspire-configuration](images/abp-studio-new-solution-dialog-aspire-configuration-microservice.png) -In this step, you can enable or disable the .NET Aspire integration for your solution. If you enable it, the solution will be pre-configured to work with .NET Aspire for easier microservice development and deployment. See the [Aspire Integration](../solution-templates/microservice/aspire-integration.md) document for more information about this feature. +In this step, you can enable or disable the Aspire integration for your solution. If you enable it, the solution will be pre-configured to work with Aspire for easier microservice development and deployment. See the [Aspire Integration](../solution-templates/microservice/aspire-integration.md) document for more information about this feature. Click the Next button to see *Additional Options* selection: diff --git a/docs/en/low-code/data-modeling.md b/docs/en/low-code/data-modeling.md index 8c3de52d6e..2da112a27a 100644 --- a/docs/en/low-code/data-modeling.md +++ b/docs/en/low-code/data-modeling.md @@ -104,7 +104,7 @@ A foreign key defines the schema direction. A page relationship defines how reco } ``` -`access` can be `none`, `view`, or `edit`. The generated modes build the related page or form from the source entity; the explicit modes reuse named page and form descriptors. +`access` can be `view` or `edit`; omit the relationship entirely when the foreign key should stay lookup-only. `relatedPageMode`, `createFormMode`, and `editFormMode` are required. The generated modes build the related page or form from the source entity; the explicit modes reuse named page and form descriptors, and `inherit` reuses the related page's own forms. See [Foreign Access](foreign-access.md) for the runtime APIs and UI behavior used by these relationships. diff --git a/docs/en/low-code/fluent-api.md b/docs/en/low-code/fluent-api.md index 73aa64a534..e28b12e5db 100644 --- a/docs/en/low-code/fluent-api.md +++ b/docs/en/low-code/fluent-api.md @@ -64,7 +64,7 @@ public class Product : DynamicEntityBase public ProductStatus Status { get; set; } - [DynamicForeignKey("Catalog.Categories.Category", "Name", ForeignAccess.View)] + [DynamicForeignKey("Catalog.Categories.Category", "Name")] public Guid? CategoryId { get; set; } [DynamicPropertyFileOptions( @@ -322,17 +322,12 @@ public class Product : DynamicEntityBase [DynamicPropertyDefaultValue("0")] public decimal Price { get; set; } - [DynamicForeignKey( - "Catalog.Categories.Category", - "Name", - ForeignAccess.View - )] + [DynamicForeignKey("Catalog.Categories.Category", "Name")] public Guid? CategoryId { get; set; } [DynamicForeignKey( "Catalog.Products.Product", "Name", - ForeignAccess.View, DependsOnPropertyName = nameof(CategoryId), DependsOnFilterPropertyName = "CategoryId" )] @@ -528,7 +523,7 @@ The `Configure(...)` callback gives you an `EntityDescriptor`. | `AsImage(long? maxSizeBytes = null, int? maxWidth = null, int? maxHeight = null, string? resizeMode = null, params string[] allowedContentTypes)` | Sets `Type = Image` and image constraints | | `WithDefaultValue(string? defaultValue)` | Sets `DefaultValue` | | `WithEnumType(string enumType)` | Sets `Type = Enum` and `EnumType` | -| `WithForeignKey(string entityName, string? displayPropertyName = null, ForeignAccess access = ForeignAccess.None, string? dependsOnPropertyName = null, string? dependsOnFilterPropertyName = null)` | Configures the relation in one call | +| `WithForeignKey(string entityName, string? displayPropertyName = null, string? dependsOnPropertyName = null, string? dependsOnFilterPropertyName = null)` | Configures the relation in one call. Reverse access is configured on page `relationships`, see [Foreign Access](foreign-access.md) | | `AsServerOnly(bool serverOnly = true)` | Sets `ServerOnly` | | `AsRequired(bool isRequired = true)` | Sets `IsRequired` | @@ -565,7 +560,7 @@ AbpDynamicEntityConfig.EntityConfigurations.Configure( .WithEnumType("Catalog.Products.ProductStatus"); entity.AddOrGetProperty("CategoryId") - .WithForeignKey("Catalog.Categories.Category", "Name", ForeignAccess.View); + .WithForeignKey("Catalog.Categories.Category", "Name"); entity.AddOrGetProperty("HeroImage") .AsImage( diff --git a/docs/en/low-code/foreign-access.md b/docs/en/low-code/foreign-access.md index 44b04e9584..08af10ea7e 100644 --- a/docs/en/low-code/foreign-access.md +++ b/docs/en/low-code/foreign-access.md @@ -13,100 +13,121 @@ Use the [Low-Code Designer](designer.md) to review relation metadata visually. T Foreign Access controls how related **dynamic entities** can be accessed through foreign key relationships. It determines whether users can view or manage related data directly from the **target entity's** UI. -The foreign key defines the schema relation and default reverse-access level. A page can additionally define a page-specific relationship that selects generated or named related pages/forms and separate authorization. See [Data Modeling and Page Behavior](data-modeling.md#reverse-relationships). +The foreign key defines only the schema relation. Reverse access is configured per page: the target entity's page defines a `relationships[]` entry that selects the access level, generated or named related pages/forms, and optional separate authorization. See [Data Modeling and Page Behavior](data-modeling.md#reverse-relationships). > **Important:** Foreign Access only works between **dynamic entities**. It does not apply to [reference entities](reference-entities.md) because they are read-only and don't have UI pages. ## Access Levels -The `ForeignAccess` enum defines three levels: +The `ForeignAccess` enum defines three levels. A page relationship uses `View` or `Edit`; a foreign key without a page relationship behaves like `None`. | Level | Value | Description | |-------|-------|-------------| -| `None` | 0 | No access from the target entity side. The relationship exists only for lookups. | -| `View` | 1 | Read-only access. Users can view related records from the target entity's action menu. | -| `Edit` | 2 | Full CRUD access. Users can create, update, and delete related records from the target entity's action menu. | +| `None` | 0 | No access from the target entity side. The relationship exists only for lookups. This is the behavior of a foreign key that no page relationship references. | +| `View` | 1 | Read-only access. Users can view related records from the target entity's page. | +| `Edit` | 2 | Full CRUD access. Users can create, update, and delete related records from the target entity's page. | -## Configuring with Attributes +## Defining the Foreign Key -Use the third parameter of `[DynamicForeignKey]`: +The foreign key only declares the schema direction. With attributes: ````csharp [DynamicEntity] public class Order { - [DynamicForeignKey("MyApp.Customers.Customer", "Name", ForeignAccess.Edit)] + [DynamicForeignKey("MyApp.Customers.Customer", "Name")] public Guid CustomerId { get; set; } } ```` -## Configuring with Fluent API +With the Fluent API: ````csharp AbpDynamicEntityConfig.EntityConfigurations.Configure( "MyApp.Orders.Order", entity => { - var customerIdProperty = entity.AddOrGetProperty("CustomerId"); - customerIdProperty.ForeignKey = new ForeignKeyDescriptor - { - EntityName = "MyApp.Customers.Customer", - DisplayPropertyName = "Name", - Access = ForeignAccess.Edit - }; + entity.AddOrGetProperty("CustomerId") + .WithForeignKey("MyApp.Customers.Customer", "Name"); } ); ```` -## Configuring in JSON Descriptors - -Set the `access` field on a foreign key property: +In JSON descriptors: ```json { "name": "CustomerId", "foreignKey": { "entityName": "LowCodeDemo.Customers.Customer", - "displayPropertyName": "Name", - "access": "edit" + "displayPropertyName": "Name" } } ``` -### Examples from the Demo Application +## Configuring Access in Page Descriptors -**Edit access** — Orders can be managed from the Customer page: +Reverse access is defined on the **target entity's page** with a `relationships[]` entry. `sourceEntityName` and `sourcePropertyName` identify the foreign key that points back to the page entity: ```json { - "name": "LowCodeDemo.Orders.Order", - "properties": [ + "name": "customers", + "title": "Customers", + "type": "dataGrid", + "entityName": "LowCodeDemo.Customers.Customer", + "relationships": [ { - "name": "CustomerId", - "foreignKey": { - "entityName": "LowCodeDemo.Customers.Customer", - "access": "edit" - } + "id": "orders-customer", + "sourceEntityName": "LowCodeDemo.Orders.Order", + "sourcePropertyName": "CustomerId", + "access": "edit", + "relatedPageMode": "page", + "relatedPageName": "orders", + "createFormMode": "generated", + "editFormMode": "generated" } ] } ``` -**View access** — Visited countries are viewable from the Country page: +| Field | Description | +|-------|-------------| +| `id` | Stable identifier unique within the page; used by relationship permissions and routes | +| `access` | `view` or `edit` | +| `relatedPageMode` | `generated` builds the related list from the source entity; `page` reuses `relatedPageName` | +| `createFormMode` / `editFormMode` | `generated`, `inherit` (reuse the related page's forms), or `form` with `createFormName` / `editFormName` | +| `useSeparatePermission` | Resolve view/create/update/delete for this relationship separately from the host page | +| `permissionConfig` | Optional permission overrides used with `useSeparatePermission` | + +### Examples from the Demo Application + +**Edit access** — Orders can be managed from the Customer page (`pages/customers.json`): ```json { - "name": "LowCodeDemo.Customers.VisitedCountry", - "parent": "LowCodeDemo.Customers.Customer", - "properties": [ - { - "name": "CountryId", - "foreignKey": { - "entityName": "LowCodeDemo.Countries.Country", - "access": "view" - } - } - ] + "id": "orders-customer", + "sourceEntityName": "LowCodeDemo.Orders.Order", + "sourcePropertyName": "CustomerId", + "access": "edit", + "relatedPageMode": "page", + "relatedPageName": "orders", + "createFormMode": "generated", + "editFormMode": "generated" +} +``` + +**View access** — Warehouses managed by a customer are viewable from the Customer page: + +```json +{ + "id": "warehouses-manager-customer", + "sourceEntityName": "LowCodeDemo.Inventory.Warehouse", + "sourcePropertyName": "ManagerCustomerId", + "access": "view", + "relatedPageMode": "page", + "relatedPageName": "warehouses", + "createFormMode": "generated", + "editFormMode": "generated" } ``` @@ -138,14 +159,14 @@ A generated page relationship can set `useSeparatePermission: true`. In that mod ## How It Works -The `ForeignAccessRelation` class stores the relationship metadata: +The `PageRelationshipDescriptor` on the target entity's page stores the relationship metadata: -* **Source entity** — the dynamic entity with the foreign key (e.g., `Order`) -* **Target entity** — the dynamic entity being referenced (e.g., `Customer`) -* **Foreign key property** — the property name (e.g., `CustomerId`) -* **Access level** — `None`, `View`, or `Edit` +* **Source entity** — the dynamic entity with the foreign key (e.g., `Order`), from `sourceEntityName` +* **Target entity** — the dynamic entity being referenced (e.g., `Customer`), the page `entityName` +* **Foreign key property** — the property name (e.g., `CustomerId`), from `sourcePropertyName` +* **Access level** — `View` or `Edit` -The `DynamicEntityAppService` checks these relations when building entity actions and filtering data. +`DynamicForeignAccessService` resolves these relationships when building entity actions and filtering related data. > **Terminology:** In foreign access context, "target entity" refers to the entity whose UI shows the action menu (the entity being pointed to by the foreign key). This is different from "reference entity" which specifically means an existing C# entity registered for read-only access. diff --git a/docs/en/low-code/model-json.md b/docs/en/low-code/model-json.md index 5773c905c1..6340195208 100644 --- a/docs/en/low-code/model-json.md +++ b/docs/en/low-code/model-json.md @@ -1,7 +1,7 @@ ```json //[doc-seo] { - "Description": "Define ABP Low-Code descriptor metadata and descriptor schemas for dynamic entities, pages, forms, filters, permissions, script endpoints, event handlers, background jobs, and workers." + "Description": "Define ABP Low-Code descriptor metadata and descriptor schemas for apps, dynamic entities, pages, forms, filters, permissions, script endpoints, event handlers, background jobs, and workers." } ``` @@ -40,10 +40,11 @@ Keep the whole `_Dynamic` folder and the generated initializer in source control Layout conventions: -* `entities/` and `enums/` usually follow namespace-like folders such as `entities/Acme/Catalog/Product.json`. +* `entities/`, `enums/`, and `permissions/` usually follow namespace-like folders such as `entities/Acme/Catalog/Product.json`. * `pageGroups/` usually stays flat as `pageGroups/{groupName}.json`. -* `pages/` stays flat as `pages/{pageName}.json`, even when the page belongs to a page group or is a dashboard. +* `pages/` stays flat as `pages/{pageName}.json` for the default app, even when the page belongs to a page group or is a dashboard. * Dashboard pages live in `pages/`; there is no separate dashboard descriptor folder. +* `apps/` holds one file per [app](#apps), for example `apps/crm.json`. Descriptors that belong to a non-default app get one extra app-level folder directly under their category and then follow the same layout rules: `entities/crm/Acme/Crm/Contact.json`, `pages/crm/contacts.json`, `forms/crm/contact-form.json`. * The runtime scans the directory tree directly. Do not add a combined index file next to `model/`. ## Example Files and Validation @@ -83,15 +84,16 @@ The schema files live in the ABP repository under `schemas/low-code`. Use the br The schema manifest is published at: ```text -https://raw.githubusercontent.com/abpframework/abp/rel-10.5/schemas/low-code/manifest.json +https://raw.githubusercontent.com/abpframework/abp/rel-10.8/schemas/low-code/manifest.json ``` -For another version, replace `rel-10.5` with the matching ABP branch or tag. +For another version, replace `rel-10.8` with the matching ABP branch or tag. The runtime writes the same `rel-{major}.{minor}` branch into the `$schema` reference of generated descriptor files. The manifest maps each descriptor collection to its descriptor schema: | Descriptor collection | Descriptor schema | |-----------------------|-------------------| +| `apps` | `definitions/app-descriptor.schema.json` | | `enums` | `definitions/enum-descriptor.schema.json` | | `entities` | `definitions/entity-descriptor.schema.json` | | `endpoints` | `definitions/endpoint-descriptor.schema.json` | @@ -109,7 +111,7 @@ Use the descriptor schema directly when a descriptor is stored as its own JSON f ```json { - "$schema": "https://raw.githubusercontent.com/abpframework/abp/rel-10.5/schemas/low-code/definitions/entity-descriptor.schema.json", + "$schema": "https://raw.githubusercontent.com/abpframework/abp/rel-10.8/schemas/low-code/definitions/entity-descriptor.schema.json", "name": "Acme.Catalog.Product", "displayName": "Products", "properties": [] @@ -126,6 +128,7 @@ When descriptor metadata is viewed as an aggregate document, the logical section ```json { + "apps": [], "enums": [], "entities": [], "endpoints": [], @@ -141,6 +144,7 @@ When descriptor metadata is viewed as an aggregate document, the logical section | Section | Description | |---------|-------------| +| `apps` | Named app scopes that partition the model; descriptors reference them through `app` | | `enums` | Reusable enum definitions | | `entities` | Dynamic entities, properties, relations, attachments, validations, and interceptors | | `endpoints` | JavaScript-backed custom HTTP endpoints | @@ -152,6 +156,47 @@ When descriptor metadata is viewed as an aggregate document, the logical section | `forms` | Named form definitions referenced by pages | | `permissions` | Custom permission definitions referenced by pages and endpoints | +Every descriptor also accepts these common fields: + +| Field | Description | +|-------|-------------| +| `app` | Name of the owning [app](#apps). Omit for the default app | +| `metadata` | Free-form string key/value annotations for tooling and documentation. Values must be strings or `null` | +| `extendsLowerLayer` | When `true`, the descriptor extends a descriptor with the same name from a lower model layer (for example code-first attributes) instead of defining a new one; only the overridden fields are required | + +## Apps + +Apps split one low-code model into independently named scopes. The default app is implicit: descriptors without an `app` field belong to it. Create an app descriptor only when a group of entities, pages, forms, and scripts should be isolated under its own name. + +```json +{ + "name": "crm", + "displayName": "CRM", + "description": "Customer relationship management app.", + "isArchived": false +} +``` + +| Field | Description | +|-------|-------------| +| `name` | Required lowercase kebab-case identifier (maximum 64 characters), for example `crm` or `field-service`. `default` is reserved for the implicit default app | +| `displayName` | Required user-facing title (maximum 128 characters) | +| `description` | Optional description | +| `isArchived` | Hides the app from active app lists without deleting its descriptors | + +Descriptors reference the app by name: + +```json +{ + "name": "Acme.Crm.Contact", + "app": "crm", + "displayName": "Contacts", + "properties": [] +} +``` + +App-scoped entities are addressed at runtime as `:`, app-scoped endpoints can publish beneath `/api/low-code/apps//endpoints` with `routeScope: "app"`, and permission children inherit the parent `app` when they do not set their own. + ## Enums Define enums before properties that reference them: @@ -161,17 +206,20 @@ Define enums before properties that reference them: "enums": [ { "name": "Acme.Catalog.ProductStatus", + "displayName": "Product Status", "values": [ { "name": "Draft", "value": 0 }, - { "name": "Active", "value": 1 }, + { "name": "Active", "value": 1, "presentation": "badge", "color": "#16A34A" }, { "name": "Paused", "value": 2 }, - { "name": "Completed", "value": 3 } + { "name": "Completed", "value": 3, "presentation": "iconOnly", "icon": { "kind": "class", "value": "fa-solid fa-check" } } ] } ] } ``` +Enum values accept optional `displayName`, `presentation` (`text`, `badge`, or `iconOnly`), `color`, and `icon` display metadata. See [Data Modeling and Page Behavior](data-modeling.md#enum-and-boolean-presentation) for page-level overrides. + Use the enum from a property with `type: "enum"` and `enumType`: ```json @@ -202,6 +250,8 @@ Entities describe the persisted data model. UI is not configured with legacy pro |-------|-------------| | `name` | Required stable full entity name, for example `Acme.Catalog.Product` | | `displayName` | Default plural/screen label | +| `description` | Optional designer documentation text | +| `order` | Optional designer/list sort order | | `displayProperty` | Property shown in lookups and foreign key display values | | `parent` | Parent entity name for child/detail entities | | `attachments` | Record-level attachment settings | @@ -240,10 +290,14 @@ Entities describe the persisted data model. UI is not configured with legacy pro | `isMappedToDbField` | Whether a dynamic scalar property uses a dedicated physical column instead of dynamic data storage | | `decimalPlaces` | Decimal scale for `decimal` and `money` properties | | `currencySymbol` | Optional UI currency symbol for `money` properties | -| `collection` | Primitive collection settings: optional `maxCount` and `uniqueItems` | +| `collection` | Primitive collection settings: optional `maxCount` and required `uniqueItems` | +| `formula` | Virtual calculated value: `expression` and `resultType` | +| `rollup` | Virtual aggregate over related records: `sourceEntityName`, `foreignKeyPropertyName`, `operation`, and optional `valuePropertyName` | | `foreignKey` | Lookup relation metadata | | `validators` | Backend/UI validation rules | +`collection`, `formula`, `rollup`, and `foreignKey` are mutually exclusive on one property. Formula and rollup properties are read-only and never persisted; the runtime forces `isMappedToDbField`, `allowSetByClients`, `isRequired`, and `isUnique` to `false` for them. + `isMappedToDbField: true` creates a dedicated scalar column. Other dynamic scalar properties use the configured dynamic data mapping, which is JSON storage by default and can be configured as individual columns. Primitive collections use normalized collection tables. See [Data Modeling and Page Behavior](data-modeling.md) for storage, collections, related fields, presentations, and backend filters. For virtual calculated fields and related-record aggregates, see [Calculated and Rollup Properties](formula-properties.md). The [Low-Code Expression Language](expression-language.md) reference documents the scalar syntax used by calculated properties and formula backfills. @@ -310,13 +364,12 @@ Use entity `attachments` when each record can have multiple arbitrary files: "type": "guid", "foreignKey": { "entityName": "Volo.Abp.Identity.IdentityUser", - "displayPropertyName": "UserName", - "access": "none" + "displayPropertyName": "UserName" } } ``` -`entityName` can point to another dynamic entity or a registered [reference entity](reference-entities.md). `access` controls [Foreign Access](foreign-access.md) behavior for dynamic entity relations. +`entityName` can point to another dynamic entity or a registered [reference entity](reference-entities.md). Use `dependsOn` (`propertyName` and `filterPropertyName`) for cascading lookups. Reverse access from the referenced entity side is not configured on the foreign key; define a page `relationships[]` entry on the target entity's page instead. See [Foreign Access](foreign-access.md). ### Validators @@ -377,12 +430,23 @@ Page export settings: | Field | Default | Purpose | |-------|---------|---------| -| `defaultFileExportMode` | `0` | Default spreadsheet output for file/image fields. `0` = file name, `1` = metadata columns, `2` = temporary download-link columns | +| `defaultFileExportMode` | `0` | Default spreadsheet output for file/image fields. `0` = file name, `1` = metadata columns, `2` = temporary download-link columns, `3` = file name with download link | | `allowFileBundleExport` | `true` | Allows **Files (.zip)** export for exportable file/image columns on the page | `importEnabled` controls whether the React runtime exposes guided Excel/CSV import for the page. See [Data Import](data-import.md) for mapping and merge behavior. -Page column and filter `propertyName` values may follow foreign keys, for example `CustomerId.CountryId.Name`. Related paths are limited by the configured query depth and return only the requested projection. Page columns can also define enum and boolean presentation metadata. See [Data Modeling and Page Behavior](data-modeling.md). +Other page-level fields: + +| Field | Purpose | +|-------|---------| +| `showInMenu` | Set `false` for pages reached only through relationships, `saveSuccessPageName`, or direct links | +| `galleryImagePresentation` | `coverLightbox` or `inlineSlider` for gallery pages; `inlineSlider` suits image collection properties | +| `enumPresentations` | Page-level overrides of enum value label, presentation, color, and icon | +| `relationships` | Reverse relationships (related records that point back to the page record). See [Data Modeling and Page Behavior](data-modeling.md#reverse-relationships) | +| `backendFilter` | Server-enforced filter expression. See [Filters](#filters) | +| `interceptors` | Page-scoped Create/Update/Delete interceptors with an `entityExecutionOrder` of `entityFirst`, `pageFirst`, or `skipEntity`. See [Interceptors](interceptors.md) | + +Page column and filter `propertyName` values may follow foreign keys, for example `CustomerId.CountryId.Name`. Related paths are limited by the configured query depth and return only the requested projection. Page columns can also define boolean presentation metadata with `booleanPresentation` and `booleanValues`. See [Data Modeling and Page Behavior](data-modeling.md). ZIP file bundle export only includes selected page columns that are file or image fields and are exportable. The ZIP contains `manifest.csv` plus files under `files/{recordId}/{fieldName}/{safeFileName}`. @@ -456,14 +520,14 @@ Filters are page-owned. Use `control: "auto"` unless you need a specific control |---------------|-------------------| | `string` | `contains`, `equal`, `notEqual`, `startsWith`, `endsWith`, `notContains`, `hasValue` | | `int`, `long`, `decimal`, `money` | `between`, `equal`, `notEqual`, `greaterThan`, `greaterThanOrEqual`, `lessThan`, `lessThanOrEqual`, `hasValue` | -| `date`, `dateTime`, `time` | `between`, `equal`, `greaterThan`, `greaterThanOrEqual`, `lessThan`, `lessThanOrEqual`, `hasValue` | +| `date`, `dateTime`, `time` | `between`, `equal`, `greaterThan`, `greaterThanOrEqual`, `lessThan`, `lessThanOrEqual`, `hasValue`, and the relative-date operators `today`, `beforeToday`, `thisWeek`, `lastWeek`, `thisMonth`, `lastMonth`, `thisYear`, `lastYear` | | `boolean` | `All / Yes / No` value selector | | `enum`, lookup, `guid` | `equal`, `notEqual`, `in`, `notIn`, `hasValue` | | `file`, `image` | `hasValue` with `All / Yes / No` | -`hasValue` is a UI alias. At runtime, `Yes` maps to `IsNotNull`, `No` maps to `IsNull`, and `All` does not add a filter. +`hasValue` is a UI alias. At runtime, `Yes` maps to `IsNotNull`, `No` maps to `IsNull`, and `All` does not add a filter. Relative-date operators need no value; the server resolves the range at query time. -Use a page `backendFilter` when a condition must always be applied by the server. The recursive expression supports `and`/`or` groups and static, JavaScript, or registered-provider values. Backend filters are combined with the filters above and are not removable client state. See [Data Modeling and Page Behavior](data-modeling.md#backend-filters). +Use a page `backendFilter` when a condition must always be applied by the server. The root is a single condition or a group with `items`; inside a group the first item has no `logic` and every following item sets `logic` to `and` or `or`. Each condition names a `propertyName`, an explicit `operator`, and exactly one value source: a static `value`, a registered `valueProvider`, or a `javaScript` expression. `isNull`/`isNotNull` take no value source and `hasValue` takes a static boolean `value`; `default` and the relative-date operators are not available in backend filters. Backend filters are combined with the filters above and are not removable client state. See [Data Modeling and Page Behavior](data-modeling.md#backend-filters). ## Permissions @@ -510,6 +574,7 @@ See [Interceptors](interceptors.md) and [Scripting API](scripting-api.md). { "name": "GetProductStats", "route": "/api/custom/products/stats", + "routeScope": "global", "method": "GET", "requireAuthentication": true, "useResourceAuthorization": false, @@ -520,7 +585,7 @@ See [Interceptors](interceptors.md) and [Scripting API](scripting-api.md). } ``` -See [Custom Endpoints](custom-endpoints.md). +`routeScope` defaults to `global`, which publishes `route` unchanged. Endpoints that belong to an [app](#apps) can set `routeScope: "app"` to publish beneath `/api/low-code/apps//endpoints`. See [Custom Endpoints](custom-endpoints.md). ### Event Handlers, Jobs, and Workers diff --git a/docs/en/modules/docs.md b/docs/en/modules/docs.md index a0a9b4b137..77c4cbef54 100644 --- a/docs/en/modules/docs.md +++ b/docs/en/modules/docs.md @@ -332,9 +332,11 @@ Configure(options => The default index name is `abp_documents`. Use `UseBasicAuthentication(username, password)` instead of `UseApiKeyAuthentication` when the Elasticsearch server uses basic authentication. +The module uses the `Elastic.Clients.Elasticsearch` 8.x client, which works with Elasticsearch 8.x and 9.x servers. Elasticsearch 7.x servers are not supported. + The module creates the index during application initialization when it does not exist. Creating, updating or deleting a cached document updates the index. The administration UI can reindex one project or all projects from the documents already stored in the Docs database. -`DefaultElasticClientProvider` creates the Elasticsearch client from these settings. Replace `IElasticClientProvider` in the [dependency injection](../framework/fundamentals/dependency-injection.md) system when the client needs additional configuration. +`DefaultElasticClientProvider` creates the `ElasticsearchClient` from these settings. Replace `IElasticClientProvider` in the [dependency injection](../framework/fundamentals/dependency-injection.md) system when the client needs additional configuration. ## Document Caching @@ -481,6 +483,21 @@ Configure(options => `HtmlLayout` and `HtmlStyle` customize the generated content. `BaseUrl` is used to resolve relative images for local sources. `IndexPagePath` inserts an additional document at the beginning of the archive without adding it to the PDF outline. `CalculatePdfFileName`, `CalculatePdfFileTitle`, `HtmlContentNormalizer` and `DocumentContentNormalizer` provide additional extension points. +`PdfSharpHtmlToPdfRenderer` is the default `IHtmlToPdfRenderer` implementation. It renders the HTML with HtmlRenderer.PdfSharp, starts every document on a new page and adds the PDF outline and the links between documents. It supports CSS 2 level styles, so `HtmlStyle` should not depend on flexbox or grid layouts. Replace `IHtmlToPdfRenderer` to use a different rendering engine. + +GIF and WebP images are converted to PNG with [SkiaSharp](https://github.com/mono/SkiaSharp), and an animated GIF shows its first frame. SVG images are rendered as links. On Linux, add the `SkiaSharp.NativeAssets.Linux.NoDependencies` package to your host project; otherwise these images are not rendered and a warning is logged. Do not use `SkiaSharp.NativeAssets.Linux` for this, because it loads fontconfig and can crash the process on servers where fontconfig is installed. + +HtmlRenderer.PdfSharp sets PDFsharp's global font resolver the first time it renders. An application that sets its own PDFsharp font resolver can not use the default renderer, so replace `IHtmlToPdfRenderer` in that case. + +The renderer uses the fonts installed on the server. The default `HtmlStyle` uses Arial and falls back to Liberation Sans or DejaVu Sans, so install one of these font packages on Linux servers or containers. The renderer does not fall back to another font for a single missing character. For Chinese, Japanese or Korean documents, install a TrueType (`.ttf`) font that contains both Latin and these characters, and put it first in the `font-family` of `HtmlStyle`. Font collections (`.ttc`) are not loaded. + +```csharp +Configure(options => +{ + options.HtmlStyle += "body { font-family: 'Arial Unicode MS', Arial, sans-serif; }"; +}); +``` + `Docs.Admin.Projects.ManagePdfFiles` allows administrators to generate, list and delete archives. Generation creates a ZIP file that contains the rendered PDF documents. Users need `Docs.Common.PdfDownload` to download it, and the public UI displays the download action only when that permission is granted and an archive exists for the selected project, version and language. PDF generation failures are written to the application logs. The background job does not rethrow failures to the job system, including errors already handled by the generator. A failed run does not make a new archive available, and the background-job system does not automatically retry it as a failed job. Check the host logs and manually start generation again after fixing the error. diff --git a/docs/en/package-version-changes.md b/docs/en/package-version-changes.md index 5ad52f5ab8..974ed20453 100644 --- a/docs/en/package-version-changes.md +++ b/docs/en/package-version-changes.md @@ -7,6 +7,28 @@ # Package Version Changes +## 10.8.0-rc.1 + +**Added:** + +| Package | Version | PR | +|---------|---------|-----| +| Elastic.Clients.Elasticsearch | 8.19.27 | #26216 | +| HtmlAgilityPack | 1.12.3 | #26216 | +| HtmlRenderer.PdfSharp | 1.6.1 | #26216 | +| PDFsharp | 6.2.4 | #26216 | + +**Removed:** + +| Package | Version | PR | +|---------|---------|-----| +| NEST | 7.17.5 | #26216 | +| Polly | 8.6.3 | #26169 | +| Polly.Extensions.Http | 3.0.0 | #26169 | +| itext.bouncy-castle-adapter | 9.3.0 | #26216 | +| itext7 | 9.3.0 | #26216 | +| itext7.pdfhtml | 6.2.1 | #26216 | + ## 10.7.0-rc.4 | Package | Old Version | New Version | PR | diff --git a/docs/en/release-info/migration-guides/abp-11-0.md b/docs/en/release-info/migration-guides/abp-11-0.md new file mode 100644 index 0000000000..41448ca444 --- /dev/null +++ b/docs/en/release-info/migration-guides/abp-11-0.md @@ -0,0 +1,122 @@ +```json +//[doc-seo] +{ + "Description": "Upgrade your ABP solutions from v10.x to v11.0 with this migration guide covering important behavior and integration changes." +} +``` + +# ABP Version 11.0 Migration Guide + +This document is a guide for upgrading ABP v10.x solutions to ABP v11.0. There are some changes in this version that may affect your applications. Please read them carefully and apply the necessary changes to your application. + +> **Package Version Changes:** Before upgrading, review the [Package Version Changes](../../package-version-changes.md) document to see version changes on dependent NuGet and NPM packages and align your project with ABP's internal package versions. + +## Open-Source (Framework) + +This version contains the following changes on the open-source side: + +### Polly Is No Longer Referenced + +**Who is affected** + +- Applications that use Polly in their own code without referencing the `Polly` package themselves, and get it through one of the ABP packages below. + +**What changed** + +- ABP retries its own HTTP requests and file operations with `Volo.Abp.Threading.RetryHelper`, so these packages no longer reference `Polly`: + +| Package | Removed reference | +|---------|-------------------| +| Volo.Abp.BlobStoring.FileSystem | Polly | +| Volo.Abp.FeatureManagement.Domain | Polly | +| Volo.Abp.PermissionManagement.Domain | Polly | +| Volo.Abp.SettingManagement.Domain | Polly | + +- The number of attempts, the delays between them and the failures that are retried are unchanged in all of them. +- No ABP API takes or returns a Polly type, so nothing else changes for an application that does not use Polly itself. + +**What to do** + +Reference the package in the projects that use it. `abp update` rewrites `Volo.*` references only, so it does not add this one. ABP referenced Polly 8.6.3 up to v10.7, so that version keeps the behavior you had: + +```xml + +``` + +`RetryHelper` is an alternative if you use Polly only to retry a failing call: + +```csharp +using var response = await RetryHelper.ExecuteAsync( + async cancellationToken => await httpClient.GetAsync(url, cancellationToken), + new RetryOptions + { + MaxRetryCount = 3, + ShouldRetryOnResult = response => !response.IsSuccessStatusCode + }); + +response.EnsureSuccessStatusCode(); +``` + +### Docs Module Renders PDF Files with HtmlRenderer.PdfSharp + +**Who is affected** + +- Applications that use the PDF export of the Docs module and customize, replace or derive from `ITextHtmlToPdfRenderer`, for example to provide fonts through `GetFontProviderAsync`. +- Applications that set their own `HtmlStyle` in `DocsProjectPdfGeneratorOptions`, or export Chinese, Japanese or Korean documents. +- Applications that use iText in their own code without referencing it themselves, and get it through `Volo.Docs.Domain`. + +**What changed** + +- `Volo.Docs.Domain` no longer references the iText packages (`itext7`, `itext7.pdfhtml` and `itext.bouncy-castle-adapter`), which are licensed under AGPL. `ITextHtmlToPdfRenderer` and `HtmlIdTagWorkerFactory` are removed. +- `PdfSharpHtmlToPdfRenderer` is the new default `IHtmlToPdfRenderer`. It uses [HtmlRenderer.PdfSharp](https://www.nuget.org/packages/HtmlRenderer.PdfSharp) (BSD-3-Clause) and [PDFsharp](https://www.nuget.org/packages/PDFsharp) (MIT). It supports CSS 2 level styles, uses the fonts installed on the server and does not fall back to another font for a single missing character. GIF and WebP images are converted to PNG with SkiaSharp, and SVG images are rendered as links. +- The default `HtmlStyle` no longer sets `width: 100%` on table cells, wraps long lines in code blocks, and adds the Liberation and DejaVu fonts as fallbacks for Linux servers. + +**What to do** + +- Move your `ITextHtmlToPdfRenderer` customizations to `PdfSharpHtmlToPdfRenderer`, or implement `IHtmlToPdfRenderer` yourself to keep using another engine. `PdfSharpHtmlToPdfRenderer` uses HtmlRenderer types in its virtual methods, and `Volo.Docs.Domain` does not expose them to your project, so add a `HtmlRenderer.PdfSharp` package reference to the project that derives from it. +- Install fonts on Linux servers and containers, for example the `fonts-dejavu-core` or `fonts-liberation` package. Otherwise the text is rendered with HtmlRenderer's built-in fallback font. +- Add the `SkiaSharp.NativeAssets.Linux.NoDependencies` package to your host project on Linux, so GIF and WebP images can be converted. The `SkiaSharp.NativeAssets.Linux` package loads fontconfig and can crash the process on servers where fontconfig is installed. +- If your application sets its own PDFsharp font resolver (`GlobalFontSettings.FontResolver`), replace `IHtmlToPdfRenderer`. HtmlRenderer.PdfSharp sets its own global font resolver, and PDFsharp does not allow changing it once it is used. +- For Chinese, Japanese or Korean documents, install a TrueType (`.ttf`) font that contains both Latin and these characters and put it first in the `font-family` of `HtmlStyle`, as explained in the [Docs module](../../modules/docs.md#generating-pdf-files) document. Font collections (`.ttc`) are not loaded. +- If you replace `HtmlStyle`, do not rely on flexbox or grid layouts, and generate a PDF to check your tables and code blocks. +- Reference the iText packages in the projects that use them. + +### Docs Module Uses the New Elasticsearch Client + +**Who is affected** + +- Applications that enable the full-text search of the Docs module with an Elasticsearch 7.x server. +- Applications that implement `IElasticClientProvider`, derive from `DefaultElasticClientProvider` or `ElasticDocumentFullSearch`, or call `DocsElasticSearchOptions.Authenticate`. +- Applications that use NEST in their own code without referencing it themselves, and get it through `Volo.Docs.Domain`. + +**What changed** + +- `Volo.Docs.Domain` uses `Elastic.Clients.Elasticsearch` 8.x instead of `NEST` 7.17.5, which is deprecated. The new client works with Elasticsearch 8.x and 9.x servers. +- `IElasticClientProvider.GetClient()` returns `ElasticsearchClient` instead of `IElasticClient`. +- `DocsElasticSearchOptions.Authenticate` takes and returns `ElasticsearchClientSettings` instead of `ConnectionSettings`. `UseBasicAuthentication` and `UseApiKeyAuthentication` are unchanged. +- `ElasticDocumentFullSearch.HandleError` takes `ElasticsearchResponse` instead of `IElasticsearchResponse`. +- The index name, the index mapping and the stored documents are unchanged, so an index created by a previous version keeps working. + +**What to do** + +- Upgrade Elasticsearch 7.x servers to 8.x or later. +- Update your implementations and derived classes to the new types. See [Migration guide: From NEST v7 to .NET Client v8](https://www.elastic.co/guide/en/elasticsearch/client/net-api/8.19/migration-guide.html) for the query API changes. +- Reference the `NEST` package in the projects that use it. + +## Pro + +This version contains the following changes on the PRO side: + +### Polly Is No Longer Referenced + +**Who is affected** + +- Applications that use Polly in their own code without referencing the `Polly` package themselves, and get it through `Volo.Abp.LanguageManagement.Domain` or `Volo.Abp.TextTemplateManagement.Domain`. + +**What changed** + +- Both packages retry with `Volo.Abp.Threading.RetryHelper` instead of Polly and no longer reference it. The number of attempts, the delays between them and the failures that are retried are unchanged. + +**What to do** + +Reference the `Polly` package in the projects that use it, as described in the open-source section above. diff --git a/docs/en/release-info/migration-guides/index.md b/docs/en/release-info/migration-guides/index.md index 772a7b09f1..3965c6c9a2 100644 --- a/docs/en/release-info/migration-guides/index.md +++ b/docs/en/release-info/migration-guides/index.md @@ -9,6 +9,7 @@ The following documents explain how to migrate your existing ABP applications. We write migration documents only if you need to take an action while upgrading your solution. Otherwise, you can easily upgrade your solution using the [abp update command](../upgrading.md). +- [10.x to 11.0](abp-11-0.md) - [10.6 to 10.7](abp-10-7.md) - [10.5 to 10.6](abp-10-6.md) - [10.4 to 10.5](abp-10-5.md) diff --git a/docs/en/solution-templates/microservice/aspire-integration.md b/docs/en/solution-templates/microservice/aspire-integration.md index 2da2706b34..33f9c80a23 100644 --- a/docs/en/solution-templates/microservice/aspire-integration.md +++ b/docs/en/solution-templates/microservice/aspire-integration.md @@ -1,11 +1,11 @@ ```json //[doc-seo] { - "Description": "Learn how to integrate .NET Aspire into your ABP-based solution for streamlined development, orchestration, and observability of distributed applications." + "Description": "Learn how to integrate Aspire into your ABP-based solution for streamlined development, orchestration, and observability of distributed applications." } ``` -# .NET Aspire Integration +# Aspire Integration ````json //[doc-nav] @@ -19,7 +19,7 @@ > You must have an ABP Business or a higher license to be able to create a microservice solution. -## .NET Aspire Overview +## Aspire Overview [Aspire](https://aspire.dev/get-started/what-is-aspire/) streamlines building, running, debugging, and deploying distributed apps. Picture your app as a set of services, databases, and frontends—when they’re deployed, they all work together seamlessly, but every time you develop them they need to be individually started and connected. With Aspire, you get a unified toolchain that eliminates complex configs and makes local debugging effortless. Instantly launch and debug your entire app with a single command. Ready to deploy? Aspire lets you publish anywhere—Kubernetes, the cloud, or your own servers. It’s also fully extensible, so you can integrate your favorite tools and services with ease. It provides: @@ -31,7 +31,7 @@ ## ABP Integration -When you enable .NET Aspire in an ABP microservice solution, you get a fully integrated development experience where: +When you enable Aspire in an ABP microservice solution, you get a fully integrated development experience where: - All microservices, gateways, and applications are orchestrated through a single entry point (AppHost). - Infrastructure containers (databases, Redis, RabbitMQ, Elasticsearch, etc.) are managed as code. @@ -41,8 +41,8 @@ When you enable .NET Aspire in an ABP microservice solution, you get a fully int When creating a new microservice solution via ABP Studio: -1. In the solution creation wizard, look for the **".NET Aspire Integration"** step. -2. Toggle the option to **enable .NET Aspire**. +1. In the solution creation wizard, look for the **"Aspire Integration"** step. +2. Toggle the option to **enable Aspire**. 3. Complete the wizard—Aspire projects will be generated along with your solution. ![Enable Aspire in ABP Studio](images/aspire-configuration.png) @@ -55,7 +55,7 @@ When Aspire is enabled, two additional projects are added to your solution: ### AppHost (Orchestrator) -[`AppHost`](https://aspire.dev/get-started/app-host/) is the .NET Aspire orchestrator project that declares all resources (services, databases, containers, applications) and their dependencies in C# code. All services, gateways, and applications in the solution have their project references added to `AppHost`. +[`AppHost`](https://aspire.dev/get-started/app-host/) is the Aspire orchestrator project that declares all resources (services, databases, containers, applications) and their dependencies in C# code. All services, gateways, and applications in the solution have their project references added to `AppHost`. **Why is it added?** @@ -367,6 +367,6 @@ To run your resource in **Solution Runner** profiles(Default or Aspire), add it ## Deploying the Application -.NET Aspire supports deployment to Azure Container Apps, Kubernetes, and other cloud platforms. For detailed deployment guidance, see the official documentation: [.NET Aspire Deployment](https://aspire.dev/deployment/overview/) +Aspire supports deployment to Azure Container Apps, Kubernetes, and other cloud platforms. For detailed deployment guidance, see the official documentation: [Aspire Deployment](https://aspire.dev/deployment/overview/) -To learn more about .NET Aspire, visit: https://aspire.dev/get-started/what-is-aspire/ +To learn more about Aspire, visit: https://aspire.dev/get-started/what-is-aspire/ diff --git a/docs/en/studio/release-notes.md b/docs/en/studio/release-notes.md index b7ffd2a81d..1f22f8fd86 100644 --- a/docs/en/studio/release-notes.md +++ b/docs/en/studio/release-notes.md @@ -289,7 +289,7 @@ This document contains **brief release notes** for each ABP Studio release. Rele * Added `AI Management` option to Startup Templates (app-nolayers, app). * Added support for new `SLNX` solution file format. * Enhanced modularity step in solution creation process. -* Fixed Swagger authorization issues when projects run via .NET Aspire. +* Fixed Swagger authorization issues when projects run via Aspire. * Fixed browser notification overlay problems. * Added missing `Unit of Work` namespace in solution templates. * Fixed JSON file formatting issues. @@ -382,7 +382,7 @@ This document contains **brief release notes** for each ABP Studio release. Rele ## 1.3.0 (2025-09-22) * Upgraded template dependencies for ABP Framework and LeptonX. (targeting ABP `9.3.4`) -* **Added .NET Aspire Integration** to ABP Studio and Microservice Startup Template. +* **Added Aspire Integration** to ABP Studio and Microservice Startup Template. * **Introduced AI Support Assistant** for enhanced development experience. * Added new package option: **C# Console Application (With ABP)**. * Enhanced Solution Runner with double-click browse functionality. diff --git a/framework/Volo.Abp.slnx b/framework/Volo.Abp.slnx index 73686e5dbe..133fd89eed 100644 --- a/framework/Volo.Abp.slnx +++ b/framework/Volo.Abp.slnx @@ -121,6 +121,7 @@ + @@ -229,6 +230,7 @@ + diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy/Volo/Abp/AspNetCore/Mvc/UI/MultiTenancy/Localization/ko.json b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy/Volo/Abp/AspNetCore/Mvc/UI/MultiTenancy/Localization/ko.json new file mode 100644 index 0000000000..e004a8cff1 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy/Volo/Abp/AspNetCore/Mvc/UI/MultiTenancy/Localization/ko.json @@ -0,0 +1,13 @@ +{ + "culture": "ko", + "texts": { + "GivenTenantIsNotExist": "지정된 테넌트가 존재하지 않습니다: {0}", + "GivenTenantIsNotAvailable": "지정된 테넌트를 사용할 수 없습니다: {0}", + "Tenant": "테넌트", + "Switch": "전환", + "Name": "이름", + "SwitchTenantHint": "호스트 측으로 전환하려면 이름 필드를 비워 두세요.", + "SwitchTenant": "테넌트 전환", + "NotSelected": "선택되지 않음" + } +} diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/AbpAspNetCoreMvcUiPackagesModule.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/AbpAspNetCoreMvcUiPackagesModule.cs index 7ba8105d43..0c4bab0b04 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/AbpAspNetCoreMvcUiPackagesModule.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/AbpAspNetCoreMvcUiPackagesModule.cs @@ -2,7 +2,6 @@ using Volo.Abp.AspNetCore.Mvc.UI.Packages.BootstrapDatepicker; using Volo.Abp.AspNetCore.Mvc.UI.Packages.JQueryValidation; using Volo.Abp.AspNetCore.Mvc.UI.Packages.Moment; -using Volo.Abp.AspNetCore.Mvc.UI.Packages.Timeago; using Volo.Abp.Localization; using Volo.Abp.Modularity; @@ -38,11 +37,6 @@ public class AbpAspNetCoreMvcUiPackagesModule : AbpModule new NameValue("zh-Hant", "zh-tw"), new NameValue("de-DE", "de")); - //Timeago - options.AddLanguageFilesMapOrUpdate(TimeagoScriptContributor.PackageName, - new NameValue("zh-Hans", "zh-CN"), - new NameValue("zh-Hant", "zh-TW")); - //JQueryValidation options.AddLanguageFilesMapOrUpdate(JQueryValidationScriptContributor.PackageName, new NameValue("zh-Hans", "zh"), diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/BootstrapDatepicker/BootstrapDatepickerScriptContributor.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/BootstrapDatepicker/BootstrapDatepickerScriptContributor.cs index dac2c051aa..eef9f3478e 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/BootstrapDatepicker/BootstrapDatepickerScriptContributor.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/BootstrapDatepicker/BootstrapDatepickerScriptContributor.cs @@ -14,7 +14,7 @@ public class BootstrapDatepickerScriptContributor : BundleContributor public override void ConfigureBundle(BundleConfigurationContext context) { - context.Files.AddIfNotContains("/libs/bootstrap-datepicker/bootstrap-datepicker.min.js"); + context.Files.AddIfNotContains("/libs/bootstrap-datepicker/bootstrap-datepicker.js"); } public override void ConfigureDynamicResources(BundleConfigurationContext context) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/MalihuCustomScrollbar/MalihuCustomScrollbarPluginScriptBundleContributor.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/MalihuCustomScrollbar/MalihuCustomScrollbarPluginScriptBundleContributor.cs deleted file mode 100644 index 30639e1583..0000000000 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/MalihuCustomScrollbar/MalihuCustomScrollbarPluginScriptBundleContributor.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Collections.Generic; -using Volo.Abp.AspNetCore.Mvc.UI.Bundling; - -namespace Volo.Abp.AspNetCore.Mvc.UI.Packages.MalihuCustomScrollbar; - -public class MalihuCustomScrollbarPluginScriptBundleContributor : BundleContributor -{ - public override void ConfigureBundle(BundleConfigurationContext context) - { - context.Files.AddIfNotContains("/libs/malihu-custom-scrollbar-plugin/jquery.mCustomScrollbar.concat.min.js"); - } -} diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/MalihuCustomScrollbar/MalihuCustomScrollbarPluginStyleBundleContributor.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/MalihuCustomScrollbar/MalihuCustomScrollbarPluginStyleBundleContributor.cs deleted file mode 100644 index d24ccb9f77..0000000000 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/MalihuCustomScrollbar/MalihuCustomScrollbarPluginStyleBundleContributor.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Collections.Generic; -using Volo.Abp.AspNetCore.Mvc.UI.Bundling; - -namespace Volo.Abp.AspNetCore.Mvc.UI.Packages.MalihuCustomScrollbar; - -public class MalihuCustomScrollbarPluginStyleBundleContributor : BundleContributor -{ - public override void ConfigureBundle(BundleConfigurationContext context) - { - context.Files.AddIfNotContains("/libs/malihu-custom-scrollbar-plugin/jquery.mCustomScrollbar.css"); - } -} diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/OwlCarousel/OwlCarouselScriptContributor.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/OwlCarousel/OwlCarouselScriptContributor.cs deleted file mode 100644 index 41172a9539..0000000000 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/OwlCarousel/OwlCarouselScriptContributor.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Collections.Generic; -using Volo.Abp.AspNetCore.Mvc.UI.Bundling; -using Volo.Abp.AspNetCore.Mvc.UI.Packages.JQuery; -using Volo.Abp.Modularity; - -namespace Volo.Abp.AspNetCore.Mvc.UI.Packages.OwlCarousel; - -[DependsOn(typeof(JQueryScriptContributor))] -public class OwlCarouselScriptContributor : BundleContributor -{ - public override void ConfigureBundle(BundleConfigurationContext context) - { - context.Files.AddIfNotContains("/libs/owl.carousel/owl.carousel.min.js"); - } -} diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/OwlCarousel/OwlCarouselStyleContributor.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/OwlCarousel/OwlCarouselStyleContributor.cs deleted file mode 100644 index b0a5ce8014..0000000000 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/OwlCarousel/OwlCarouselStyleContributor.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Collections.Generic; -using Volo.Abp.AspNetCore.Mvc.UI.Bundling; - -namespace Volo.Abp.AspNetCore.Mvc.UI.Packages.OwlCarousel; - -public class OwlCarouselStyleContributor : BundleContributor -{ - public override void ConfigureBundle(BundleConfigurationContext context) - { - //TODO: Theming! - context.Files.AddIfNotContains("/libs/owl.carousel/assets/owl.carousel.min.css"); - context.Files.AddIfNotContains("/libs/owl.carousel/assets/owl.theme.default.min.css"); - context.Files.AddIfNotContains("/libs/owl.carousel/assets/owl.theme.green.min.css"); - } -} diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/Swiper/SwiperScriptContributor.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/Swiper/SwiperScriptContributor.cs new file mode 100644 index 0000000000..2ead1c6ced --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/Swiper/SwiperScriptContributor.cs @@ -0,0 +1,12 @@ +using System.Collections.Generic; +using Volo.Abp.AspNetCore.Mvc.UI.Bundling; + +namespace Volo.Abp.AspNetCore.Mvc.UI.Packages.Swiper; + +public class SwiperScriptContributor : BundleContributor +{ + public override void ConfigureBundle(BundleConfigurationContext context) + { + context.Files.AddIfNotContains("/libs/swiper/swiper-bundle.min.js"); + } +} diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/Swiper/SwiperStyleContributor.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/Swiper/SwiperStyleContributor.cs new file mode 100644 index 0000000000..6fd744dcb7 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/Swiper/SwiperStyleContributor.cs @@ -0,0 +1,12 @@ +using System.Collections.Generic; +using Volo.Abp.AspNetCore.Mvc.UI.Bundling; + +namespace Volo.Abp.AspNetCore.Mvc.UI.Packages.Swiper; + +public class SwiperStyleContributor : BundleContributor +{ + public override void ConfigureBundle(BundleConfigurationContext context) + { + context.Files.AddIfNotContains("/libs/swiper/swiper-bundle.min.css"); + } +} diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/Timeago/TimeagoScriptContributor.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/Timeago/TimeagoScriptContributor.cs index 3b09dd1022..94fbd9a3b9 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/Timeago/TimeagoScriptContributor.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/Timeago/TimeagoScriptContributor.cs @@ -1,8 +1,6 @@ using System.Collections.Generic; -using Microsoft.Extensions.Options; using Volo.Abp.AspNetCore.Mvc.UI.Bundling; using Volo.Abp.AspNetCore.Mvc.UI.Packages.JQuery; -using Volo.Abp.Localization; using Volo.Abp.Modularity; namespace Volo.Abp.AspNetCore.Mvc.UI.Packages.Timeago; @@ -10,20 +8,9 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Packages.Timeago; [DependsOn(typeof(JQueryScriptContributor))] public class TimeagoScriptContributor : BundleContributor { - public const string PackageName = "jquery.timeago"; - public override void ConfigureBundle(BundleConfigurationContext context) { - context.Files.AddIfNotContains("/libs/timeago/jquery.timeago.js"); - } - - public override void ConfigureDynamicResources(BundleConfigurationContext context) - { - var fileName = context.LazyServiceProvider.LazyGetRequiredService>().Value.GetCurrentUICultureLanguageFilesMap(PackageName); - var filePath = $"/libs/timeago/locales/jquery.timeago.{fileName}.js"; - if (context.FileProvider.GetFileInfo(filePath).Exists) - { - context.Files.Add(filePath); - } + context.Files.AddIfNotContains("/libs/timeago/timeago.full.min.js"); + context.Files.AddIfNotContains("/libs/abp/timeago/abp.timeago.js"); } } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Bundling/SharedThemeGlobalScriptContributor.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Bundling/SharedThemeGlobalScriptContributor.cs index 728becdf6d..7865ec9c3d 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Bundling/SharedThemeGlobalScriptContributor.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Bundling/SharedThemeGlobalScriptContributor.cs @@ -7,7 +7,6 @@ using Volo.Abp.AspNetCore.Mvc.UI.Packages.JQuery; using Volo.Abp.AspNetCore.Mvc.UI.Packages.JQueryValidationUnobtrusive; using Volo.Abp.AspNetCore.Mvc.UI.Packages.Lodash; using Volo.Abp.AspNetCore.Mvc.UI.Packages.Luxon; -using Volo.Abp.AspNetCore.Mvc.UI.Packages.MalihuCustomScrollbar; using Volo.Abp.AspNetCore.Mvc.UI.Packages.Select2; using Volo.Abp.AspNetCore.Mvc.UI.Packages.SweetAlert2; using Volo.Abp.AspNetCore.Mvc.UI.Packages.Timeago; @@ -23,7 +22,6 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Bundling; typeof(Select2ScriptContributor), typeof(DatatablesNetBs5ScriptContributor), typeof(Sweetalert2ScriptContributor), - typeof(MalihuCustomScrollbarPluginScriptBundleContributor), typeof(LuxonScriptContributor), typeof(TimeagoScriptContributor), typeof(BootstrapDatepickerScriptContributor), diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Bundling/SharedThemeGlobalStyleContributor.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Bundling/SharedThemeGlobalStyleContributor.cs index 4f436a02b0..b030508711 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Bundling/SharedThemeGlobalStyleContributor.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/Bundling/SharedThemeGlobalStyleContributor.cs @@ -5,7 +5,6 @@ using Volo.Abp.AspNetCore.Mvc.UI.Packages.BootstrapDaterangepicker; using Volo.Abp.AspNetCore.Mvc.UI.Packages.Core; using Volo.Abp.AspNetCore.Mvc.UI.Packages.DatatablesNetBs5; using Volo.Abp.AspNetCore.Mvc.UI.Packages.FontAwesome; -using Volo.Abp.AspNetCore.Mvc.UI.Packages.MalihuCustomScrollbar; using Volo.Abp.AspNetCore.Mvc.UI.Packages.Select2; using Volo.Abp.Modularity; @@ -16,7 +15,6 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Bundling; typeof(BootstrapStyleContributor), typeof(FontAwesomeStyleContributor), typeof(Select2StyleContributor), - typeof(MalihuCustomScrollbarPluginStyleBundleContributor), typeof(DatatablesNetBs5StyleContributor), typeof(BootstrapDatepickerStyleContributor), typeof(BootstrapDaterangepickerStyleContributor) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/bootstrap/dom-event-handlers.js b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/bootstrap/dom-event-handlers.js index 3199900536..cb1b38ab8c 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/bootstrap/dom-event-handlers.js +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/bootstrap/dom-event-handlers.js @@ -72,7 +72,7 @@ } abp.dom.initializers.initializeTimeAgos = function ($timeagos) { - $timeagos.timeago(); + abp.timeago.render($timeagos.toArray()); } abp.dom.initializers.initializeAutocompleteSelects = function ($autocompleteSelects) { @@ -217,6 +217,7 @@ args.$el.findWithSelf('[data-bs-toggle="tooltip"]').each(function () { $('#' + $(this).attr('aria-describedby')).remove(); }); + abp.timeago.cancel(args.$el.findWithSelf('[timeago-id]').toArray()); }); abp.event.on('abp.configurationInitialized', function () { diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs index bd5e1e82a0..837eb929fe 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs @@ -34,19 +34,22 @@ public class AspNetCoreApiDescriptionModelProvider : IApiDescriptionModelProvide private readonly AbpAspNetCoreMvcOptions _abpAspNetCoreMvcOptions; private readonly AbpApiDescriptionModelOptions _modelOptions; private readonly IXmlDocumentationProvider _xmlDocProvider; + private readonly IPropertyApiDescriptionModelContributor[] _propertyContributors; public AspNetCoreApiDescriptionModelProvider( IOptions options, IApiDescriptionGroupCollectionProvider descriptionProvider, IOptions abpAspNetCoreMvcOptions, IOptions modelOptions, - IXmlDocumentationProvider xmlDocProvider) + IXmlDocumentationProvider xmlDocProvider, + IEnumerable propertyContributors) { _options = options.Value; _descriptionProvider = descriptionProvider; _abpAspNetCoreMvcOptions = abpAspNetCoreMvcOptions.Value; _modelOptions = modelOptions.Value; _xmlDocProvider = xmlDocProvider; + _propertyContributors = propertyContributors.ToArray(); Logger = NullLogger.Instance; } @@ -321,6 +324,8 @@ public class AspNetCoreApiDescriptionModelProvider : IApiDescriptionModelProvide await PopulateTypeDescriptionsAsync(applicationModel.Types[typeName], type); } + await ContributeToPropertiesAsync(applicationModel.Types[typeName], type); + await AddCustomTypesToModelAsync(applicationModel, type.BaseType, includeDescriptions); foreach (var propertyInfo in type.GetProperties().Where(p => p.DeclaringType == type)) @@ -329,6 +334,33 @@ public class AspNetCoreApiDescriptionModelProvider : IApiDescriptionModelProvide } } + protected virtual async Task ContributeToPropertiesAsync(TypeApiDescriptionModel typeModel, Type type) + { + if (_propertyContributors.IsNullOrEmpty() || typeModel.Properties.IsNullOrEmpty()) + { + return; + } + + var propertyInfos = type + .GetProperties(BindingFlags.Instance | BindingFlags.Public) + .Where(p => p.DeclaringType == type) + .ToDictionary(p => p.Name, p => p); + + foreach (var propertyModel in typeModel.Properties!) + { + if (!propertyInfos.TryGetValue(propertyModel.Name, out var propertyInfo)) + { + continue; + } + + var context = new PropertyApiDescriptionModelContributionContext(propertyModel, propertyInfo, type); + foreach (var contributor in _propertyContributors) + { + await contributor.ContributeAsync(context); + } + } + } + private static string CalculateTypeName(Type type) { if (!type.IsGenericTypeDefinition) diff --git a/framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/Localization/ko.json b/framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/Localization/ko.json new file mode 100644 index 0000000000..a41eae4912 --- /dev/null +++ b/framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/Localization/ko.json @@ -0,0 +1,10 @@ +{ + "culture": "ko", + "texts": { + "Volo.Authorization:010001": "권한 부여에 실패했습니다! 지정된 정책에서 권한이 부여되지 않았습니다.", + "Volo.Authorization:010002": "권한 부여에 실패했습니다! 지정된 정책에서 권한이 부여되지 않았습니다: {PolicyName}", + "Volo.Authorization:010003": "권한 부여에 실패했습니다! 지정된 리소스에 대해 정책에서 권한이 부여되지 않았습니다: {ResourceName}", + "Volo.Authorization:010004": "권한 부여에 실패했습니다! 지정된 리소스에 대해 요구 사항이 충족되지 않았습니다: {ResourceName}", + "Volo.Authorization:010005": "권한 부여에 실패했습니다! 지정된 리소스에 대해 요구 사항들이 충족되지 않았습니다: {ResourceName}" + } +} diff --git a/framework/src/Volo.Abp.BlobStoring.FileSystem/Volo.Abp.BlobStoring.FileSystem.csproj b/framework/src/Volo.Abp.BlobStoring.FileSystem/Volo.Abp.BlobStoring.FileSystem.csproj index 38be0da5ae..76c01d33da 100644 --- a/framework/src/Volo.Abp.BlobStoring.FileSystem/Volo.Abp.BlobStoring.FileSystem.csproj +++ b/framework/src/Volo.Abp.BlobStoring.FileSystem/Volo.Abp.BlobStoring.FileSystem.csproj @@ -18,7 +18,6 @@ - diff --git a/framework/src/Volo.Abp.BlobStoring.FileSystem/Volo/Abp/BlobStoring/FileSystem/FileSystemBlobProvider.cs b/framework/src/Volo.Abp.BlobStoring.FileSystem/Volo/Abp/BlobStoring/FileSystem/FileSystemBlobProvider.cs index 75edbc2ac9..0c71bcaad4 100644 --- a/framework/src/Volo.Abp.BlobStoring.FileSystem/Volo/Abp/BlobStoring/FileSystem/FileSystemBlobProvider.cs +++ b/framework/src/Volo.Abp.BlobStoring.FileSystem/Volo/Abp/BlobStoring/FileSystem/FileSystemBlobProvider.cs @@ -1,9 +1,9 @@ using System; using System.IO; using System.Threading.Tasks; -using Polly; using Volo.Abp.DependencyInjection; using Volo.Abp.IO; +using Volo.Abp.Threading; namespace Volo.Abp.BlobStoring.FileSystem; @@ -48,9 +48,8 @@ public class FileSystemBlobProvider : BlobProviderBase, ITransientDependency var targetOpened = false; - await Policy.Handle(_ => sourcePosition >= 0 || !targetOpened) - .WaitAndRetryAsync(2, retryCount => TimeSpan.FromSeconds(retryCount)) - .ExecuteAsync(async () => + await RetryHelper.ExecuteAsync( + async _ => { if (sourcePosition >= 0) { @@ -68,7 +67,14 @@ public class FileSystemBlobProvider : BlobProviderBase, ITransientDependency await fileStream.FlushAsync(); } - }); + }, + new RetryOptions + { + MaxRetryCount = 2, + DelayFactory = retryCount => TimeSpan.FromSeconds(retryCount), + ShouldRetryOnException = ex => ex is IOException && (sourcePosition >= 0 || !targetOpened) + }, + args.CancellationToken); } public override Task DeleteAsync(BlobProviderDeleteArgs args) @@ -92,9 +98,15 @@ public class FileSystemBlobProvider : BlobProviderBase, ITransientDependency return null; } - return await Policy.Handle() - .WaitAndRetryAsync(2, retryCount => TimeSpan.FromSeconds(retryCount)) - .ExecuteAsync(() => Task.FromResult(File.OpenRead(filePath))); + return await RetryHelper.ExecuteAsync( + _ => Task.FromResult(File.OpenRead(filePath)), + new RetryOptions + { + MaxRetryCount = 2, + DelayFactory = retryCount => TimeSpan.FromSeconds(retryCount), + ShouldRetryOnException = ex => ex is IOException + }, + args.CancellationToken); } protected virtual Stream OpenFileStream(string filePath, FileMode fileMode) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo.Abp.Cli.Core.csproj b/framework/src/Volo.Abp.Cli.Core/Volo.Abp.Cli.Core.csproj index 23cb5c2b33..d73bda8303 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo.Abp.Cli.Core.csproj +++ b/framework/src/Volo.Abp.Cli.Core/Volo.Abp.Cli.Core.csproj @@ -19,8 +19,6 @@ - - diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Http/CliHttpClientExtensions.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Http/CliHttpClientExtensions.cs index f6da2e46e4..2c2facd727 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Http/CliHttpClientExtensions.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Http/CliHttpClientExtensions.cs @@ -6,9 +6,8 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using Duende.IdentityModel.Client; -using Polly; -using Polly.Extensions.Http; using Volo.Abp.Cli.Auth; +using Volo.Abp.Threading; using Microsoft.Extensions.Logging; namespace Volo.Abp.Cli.Http; @@ -55,29 +54,35 @@ public static class CliHttpClientExtensions cancellationToken = cancellationTokenSource.Token; } - return await HttpPolicyExtensions - .HandleTransientHttpError() - .OrResult(msg => !msg.IsSuccessStatusCode) - .WaitAndRetryAsync(sleepDurations, - (responseMessage, timeSpan, retryCount, context) => + using var delayEnumerator = sleepDurations.GetEnumerator(); + + return await RetryHelper.ExecuteAsync( + retryCancellationToken => httpClient.GetAsync(url, retryCancellationToken), + new RetryOptions + { + MaxRetryCount = int.MaxValue, + DelayFactory = _ => delayEnumerator.Current, + ShouldRetryOnException = exception => + exception is HttpRequestException && delayEnumerator.MoveNext(), + ShouldRetryOnResult = response => + !response.IsSuccessStatusCode && delayEnumerator.MoveNext(), + OnRetry = attempt => { - if (responseMessage.Exception != null) + if (attempt.Exception != null) { - string httpErrorCode = responseMessage.Result == null ? - httpErrorCode = string.Empty : - "HTTP-" + (int)responseMessage.Result.StatusCode + ", "; - logger?.LogWarning( - $"{retryCount}. HTTP request attempt failed to {url} with an error: {httpErrorCode}{responseMessage.Exception.Message}. " + - $"Waiting {timeSpan.TotalSeconds} secs for the next try..."); + $"{attempt.RetryCount}. HTTP request attempt failed to {url} with an error: {attempt.Exception.Message}. " + + $"Waiting {attempt.RetryDelay.TotalSeconds} secs for the next try..."); } - else if (responseMessage.Result != null) + else if (attempt.Result != null) { logger?.LogWarning( - $"{retryCount}. HTTP request attempt failed to {url} with an error: {(int)responseMessage.Result.StatusCode}-{responseMessage.Result.ReasonPhrase}. " + - $"Waiting {timeSpan.TotalSeconds} secs for the next try..."); + $"{attempt.RetryCount}. HTTP request attempt failed to {url} with an error: {(int)attempt.Result.StatusCode}-{attempt.Result.ReasonPhrase}. " + + $"Waiting {attempt.RetryDelay.TotalSeconds} secs for the next try..."); } - }) - .ExecuteAsync(async () => await httpClient.GetAsync(url, cancellationToken.Value)); + return Task.CompletedTask; + } + }, + cancellationToken.Value); } } diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxying/CSharp/CSharpServiceProxyGenerator.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxying/CSharp/CSharpServiceProxyGenerator.cs index c4d1b5da4c..70911b12b6 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxying/CSharp/CSharpServiceProxyGenerator.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxying/CSharp/CSharpServiceProxyGenerator.cs @@ -1,8 +1,11 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using System.Text; +using System.Text.Json; +using System.Text.RegularExpressions; using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Volo.Abp.Cli.Commands; @@ -19,6 +22,7 @@ public class CSharpServiceProxyGenerator : ServiceProxyGeneratorBase" + $"{Environment.NewLine}" + $"{Environment.NewLine}// ReSharper disable once CheckNamespace" + @@ -54,7 +60,7 @@ public class CSharpServiceProxyGenerator : ServiceProxyGeneratorBase" + $"{Environment.NewLine}" + $"{Environment.NewLine}// ReSharper disable once CheckNamespace" + @@ -66,7 +72,7 @@ public class CSharpServiceProxyGenerator : ServiceProxyGeneratorBase" + $"{Environment.NewLine}" + $"{Environment.NewLine}// ReSharper disable once CheckNamespace" + @@ -110,6 +116,25 @@ public class CSharpServiceProxyGenerator : ServiceProxyGeneratorBase _ambiguousTypeNames = new(); + private HashSet _clientProvidedAssemblyNames; + private HashSet _generatedContractTypeNames = new(StringComparer.Ordinal); + private HashSet _generatedContractTypeNamespacePrefixes = new(StringComparer.Ordinal); + private List _typesToGenerate = new(); + public CSharpServiceProxyGenerator( CliHttpClientFactory cliHttpClientFactory, IJsonSerializer jsonSerializer) : @@ -141,10 +166,40 @@ public class CSharpServiceProxyGenerator : ServiceProxyGeneratorBase x.Controllers). - Where(x => x.Value.Interfaces.Any() && ServicePostfixes.Any(s => x.Value.Interfaces.Last().Type.EndsWith(s)))) + var hasAssemblyNames = !args.WithoutContracts && + applicationApiDescriptionModel.Types?.Values.Any(x => !x.AssemblyName.IsNullOrWhiteSpace()) == true; + if (hasAssemblyNames) { - await GenerateClassFileAsync(args, controller.Value); + LoadClientProvidedAssemblyNames(args.WorkDirectory); + } + else + { + _clientProvidedAssemblyNames = null; + } + + if (!args.WithoutContracts && applicationApiDescriptionModel.Types?.Count > 0) + { + if (!hasAssemblyNames) + { + Logger.LogWarning("The remote service does not provide contract assembly names. Falling back to namespace based contract type detection."); + } + else if (_clientProvidedAssemblyNames == null) + { + Logger.LogWarning("Project assets are unavailable. Falling back to namespace based contract type detection."); + } + } + + _generatedContractTypeNamespacePrefixes = GetGeneratedContractTypeNamespacePrefixes(applicationApiDescriptionModel); + _typesToGenerate = args.WithoutContracts + ? new List() + : GetTypesToGenerate(applicationApiDescriptionModel); + _generatedContractTypeNames = new HashSet(_typesToGenerate + .Select(x => ParseTypeNames(x).First().Name), StringComparer.Ordinal); + _ambiguousTypeNames = GetAmbiguousTypeNames(applicationApiDescriptionModel, _typesToGenerate); + + foreach (var controller in applicationApiDescriptionModel.Modules.Values.SelectMany(x => x.Controllers.Values).Where(ShouldGenerateController)) + { + await GenerateClassFileAsync(args, controller); } if (!args.WithoutContracts) @@ -165,7 +220,7 @@ public class CSharpServiceProxyGenerator : ServiceProxyGeneratorBase usingNamespaceList) { var methodBuilder = new StringBuilder(); - var returnTypeName = GetRealTypeName(action.ReturnValue.Type, usingNamespaceList); + var returnTypeName = GetTypeReference(action.ReturnValue.Type, usingNamespaceList); if (action.Name.EndsWith("Async")) { GenerateAsyncClassMethod(action, returnTypeName, methodBuilder, usingNamespaceList); @@ -291,7 +346,7 @@ public class CSharpServiceProxyGenerator : ServiceProxyGeneratorBase x.Name).Select(x => x.First())) { - methodBuilder.Replace("", $"{GetRealTypeName(parameter.Type, usingNamespaceList)} {parameter.Name}, "); + methodBuilder.Replace("", $"{GetTypeReference(parameter.Type, usingNamespaceList)} {parameter.Name}, "); } methodBuilder.Replace("", string.Empty); @@ -322,7 +377,7 @@ public class CSharpServiceProxyGenerator : ServiceProxyGeneratorBase", $"{GetRealTypeName(parameter.Type, usingNamespaceList)} {parameter.Name}, "); + methodBuilder.Replace("", $"{GetTypeReference(parameter.Type, usingNamespaceList)} {parameter.Name}, "); } methodBuilder.Replace("", string.Empty); @@ -344,7 +399,7 @@ public class CSharpServiceProxyGenerator : ServiceProxyGeneratorBase", $"{Environment.NewLine} {{ typeof({GetRealTypeName(parameter.Type)}), {parameter.Name} }},"); + methodBuilder.Replace("", $"{Environment.NewLine} {{ typeof({GetTypeReference(parameter.Type)}), {parameter.Name} }},"); } methodBuilder.Replace(",", string.Empty); @@ -356,7 +411,7 @@ public class CSharpServiceProxyGenerator : ServiceProxyGeneratorBase x.Name).Select(x => x.First())) { - methodBuilder.Replace("", $"{GetRealTypeName(parameter.Type, usingNamespaceList)} {parameter.Name}, "); + methodBuilder.Replace("", $"{GetTypeReference(parameter.Type, usingNamespaceList)} {parameter.Name}, "); } if (action.ParametersOnMethod.Count == 0) @@ -396,7 +451,7 @@ public class CSharpServiceProxyGenerator : ServiceProxyGeneratorBase", $"{GetRealTypeName(parameter.Type, usingNamespaceList)} {parameter.Name}, "); + methodBuilder.Replace("", $"{GetTypeReference(parameter.Type, usingNamespaceList)} {parameter.Name}, "); } if (action.ParametersOnMethod.Count == 0) @@ -408,6 +463,11 @@ public class CSharpServiceProxyGenerator : ServiceProxyGeneratorBase controller.Interfaces.Last().Type.EndsWith(x)); + } + private bool ShouldGenerateMethod(string appServiceTypeName, ActionApiDescriptionModel action) { return action.ImplementFrom.StartsWith(AppServicePrefix) || @@ -415,53 +475,392 @@ public class CSharpServiceProxyGenerator : ServiceProxyGeneratorBase GetTypesToGenerate(ApplicationApiDescriptionModel applicationApiDescriptionModel) + { + var types = new HashSet(); + var pendingTypeKeys = new Queue(GetSignatureTypeNames(applicationApiDescriptionModel).SelectMany(GetReferencedTypeKeys)); + while (pendingTypeKeys.Count > 0) + { + var typeKey = pendingTypeKeys.Dequeue(); + if (types.Contains(typeKey) || !applicationApiDescriptionModel.Types.TryGetValue(typeKey, out var type) || IsClientProvidedType(typeKey, type)) + { + continue; + } + + types.Add(typeKey); + + var referencedTypeKeys = GetReferencedTypeKeys(type.BaseType) + .Concat((type.Properties ?? []).SelectMany(x => GetReferencedTypeKeys(x.Type))); + foreach (var referencedTypeKey in referencedTypeKeys) + { + pendingTypeKeys.Enqueue(referencedTypeKey); + } + } + + return types.OrderBy(x => x).ToList(); + } + + private List GetSignatureTypeNames(ApplicationApiDescriptionModel applicationApiDescriptionModel) { - var types = new List(); + var signatureTypeNames = new List(); + foreach (var controller in applicationApiDescriptionModel.Modules.Values.SelectMany(x => x.Controllers.Values).Where(ShouldGenerateController)) + { + var appServiceType = controller.Interfaces.Last(); + foreach (var method in appServiceType.Methods) + { + signatureTypeNames.AddRange(method.ParametersOnMethod.Select(x => x.Type)); + signatureTypeNames.Add(method.ReturnValue.Type); + } - foreach (var controller in applicationApiDescriptionModel.Modules.Values.First().Controllers) + foreach (var action in controller.Actions.Values.Where(x => ShouldGenerateMethod(appServiceType.Type, x))) + { + signatureTypeNames.AddRange(action.ParametersOnMethod.Select(x => x.Type)); + signatureTypeNames.AddRange(action.Parameters.Select(x => x.Type)); + signatureTypeNames.Add(action.ReturnValue.Type); + } + } + + return signatureTypeNames; + } + + private static IEnumerable GetReferencedTypeKeys(string typeName) + { + return ParseTypeNames(typeName).Select(x => x.GenericArgumentCount == 0 + ? x.Name + : $"{x.Name}<{Enumerable.Range(0, x.GenericArgumentCount).Select(i => $"T{i}").JoinAsString(",")}>"); + } + + private static IEnumerable<(string Name, int GenericArgumentCount)> ParseTypeNames(string typeName) + { + if (typeName.IsNullOrWhiteSpace()) { - types.AddIfNotContains(applicationApiDescriptionModel.Types.Where(x => x.Key.StartsWith($"{GetTypeNamespace(controller.Value.Type)}")).Select(x => x.Key)); + yield break; } - for (var i = 0; i < types.Count; i++) + var index = 0; + while (index < typeName.Length) { - var className = types[i]; - if (className.StartsWith("Volo.Abp.Application.Dtos.") && className.Contains("<") && className.Contains(">")) + if (!IsTypeNameChar(typeName[index])) { - types[i] = className.Substring( - className.IndexOf("<", StringComparison.Ordinal) + 1, - className.IndexOf(">", StringComparison.Ordinal) - - className.IndexOf("<", StringComparison.Ordinal) -1); + index++; + continue; } + + var start = index; + while (index < typeName.Length && IsTypeNameChar(typeName[index])) + { + index++; + } + + var name = typeName.Substring(start, index - start); + if (!name.Contains('.')) + { + continue; + } + + var genericArgumentCount = index < typeName.Length && typeName[index] == '<' + ? GetGenericArgumentCount(typeName, index) + : 0; + + yield return (name, genericArgumentCount); } + } - types = types.Where(x => !x.StartsWith("System.") && !x.StartsWith("[System.")).Distinct().OrderBy(x => x).ToList(); + private static bool IsTypeNameChar(char c) + { + return char.IsLetterOrDigit(c) || c == '_' || c == '.' || c == '+'; + } - foreach (var type in applicationApiDescriptionModel.Types.Where(x => types.Contains(x.Key))) + private static int GetGenericArgumentCount(string typeName, int openingBracketIndex) + { + var depth = 0; + var count = 1; + for (var i = openingBracketIndex; i < typeName.Length; i++) { - var dto = new StringBuilder(DtoTemplate); - var dtoUsingNamespaceList = new List(DtoUsingNamespaceList) + switch (typeName[i]) { - $"using {GetTypeNamespace(type.Key)};" + case '<': + depth++; + break; + case '>': + if (--depth == 0) + { + return count; + } + break; + case ',' when depth == 1: + count++; + break; + } + } + + return count; + } + + private bool IsClientProvidedType(string typeKey, TypeApiDescriptionModel type) + { + if (!type.AssemblyName.IsNullOrWhiteSpace() && _clientProvidedAssemblyNames != null) + { + return typeKey.StartsWith("System.", StringComparison.Ordinal) || + typeKey.StartsWith("Microsoft.", StringComparison.Ordinal) || + _clientProvidedAssemblyNames.Contains(type.AssemblyName); + } + + return !_generatedContractTypeNamespacePrefixes.Any(x => typeKey.StartsWith(x, StringComparison.Ordinal)) && + ClientProvidedTypeNamespacePrefixes.Any(x => typeKey.StartsWith(x, StringComparison.Ordinal)); + } + + protected void LoadClientProvidedAssemblyNames(string workDirectory) + { + _clientProvidedAssemblyNames = GetClientProvidedAssemblyNames(workDirectory); + } + + private HashSet GetClientProvidedAssemblyNames(string workDirectory) + { + var assetsFilePath = GetProjectAssetsFilePath(workDirectory); + if (!File.Exists(assetsFilePath)) + { + return null; + } + + try + { + using var document = JsonDocument.Parse(File.ReadAllText(assetsFilePath)); + if (document.RootElement.ValueKind != JsonValueKind.Object || + !document.RootElement.TryGetProperty("targets", out var targets) || + targets.ValueKind != JsonValueKind.Object) + { + return null; + } + + var targetAssemblyNames = new List>(); + foreach (var target in targets.EnumerateObject().Where(x => !x.Name.Contains('/'))) + { + if (target.Value.ValueKind != JsonValueKind.Object) + { + continue; + } + + var assemblyNames = new HashSet(StringComparer.OrdinalIgnoreCase); + foreach (var library in target.Value.EnumerateObject()) + { + if (library.Value.ValueKind != JsonValueKind.Object || + !library.Value.TryGetProperty("compile", out var compileAssets) || + compileAssets.ValueKind != JsonValueKind.Object) + { + continue; + } + + foreach (var compileAsset in compileAssets.EnumerateObject() + .Where(x => x.Name.EndsWith(".dll", StringComparison.OrdinalIgnoreCase))) + { + assemblyNames.Add(Path.GetFileNameWithoutExtension(compileAsset.Name)); + } + } + + targetAssemblyNames.Add(assemblyNames); + } + + if (targetAssemblyNames.Count == 0) + { + return null; + } + + var commonAssemblyNames = targetAssemblyNames[0]; + foreach (var assemblyNames in targetAssemblyNames.Skip(1)) + { + commonAssemblyNames.IntersectWith(assemblyNames); + } + + return commonAssemblyNames; + } + catch (IOException) + { + return null; + } + catch (UnauthorizedAccessException) + { + return null; + } + catch (JsonException) + { + return null; + } + } + + protected virtual string GetProjectAssetsFilePath(string workDirectory) + { + var defaultAssetsFilePath = Path.Combine(workDirectory, "obj", "project.assets.json"); + if (File.Exists(defaultAssetsFilePath)) + { + return defaultAssetsFilePath; + } + + var projectFiles = Directory.GetFiles(workDirectory, "*.csproj"); + if (projectFiles.Length != 1) + { + Logger.LogDebug("Could not evaluate the project assets file path because the working directory contains {ProjectCount} project files.", projectFiles.Length); + return defaultAssetsFilePath; + } + + var projectFile = projectFiles[0]; + + try + { + using var process = new Process + { + StartInfo = new ProcessStartInfo("dotnet", $"msbuild \"{projectFile}\" -nologo -getProperty:ProjectAssetsFile") + { + WorkingDirectory = workDirectory, + UseShellExecute = false, + CreateNoWindow = true, + RedirectStandardOutput = true, + RedirectStandardError = true + } }; + process.Start(); + var outputTask = process.StandardOutput.ReadToEndAsync(); + var errorTask = process.StandardError.ReadToEndAsync(); + if (!process.WaitForExit(ProjectEvaluationTimeoutMilliseconds)) + { + process.Kill(); + Logger.LogDebug("Timed out while evaluating the project assets file path."); + return defaultAssetsFilePath; + } - var genericTypeName = type.Key; - if (type.Value.GenericArguments != null) + if (!Task.WaitAll(new Task[] { outputTask, errorTask }, ProjectEvaluationTimeoutMilliseconds)) { - for (var j = 0; j < type.Value.GenericArguments.Length; j++) + Logger.LogDebug("Timed out while reading the project assets file path evaluation output."); + return defaultAssetsFilePath; + } + + if (process.ExitCode == 0) + { + var assetsFilePath = outputTask.Result.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries) + .Select(x => x.Trim()) + .Select(x => Path.IsPathRooted(x) ? x : Path.Combine(workDirectory, x)) + .FirstOrDefault(File.Exists); + if (assetsFilePath != null) { - genericTypeName = genericTypeName.Replace($"T{j}", type.Value.GenericArguments[j]); + return assetsFilePath; } } + } + catch (Exception ex) + { + Logger.LogDebug(ex, "Could not evaluate the project assets file path."); + } + + return defaultAssetsFilePath; + } + + private static HashSet GetGeneratedContractTypeNamespacePrefixes(ApplicationApiDescriptionModel applicationApiDescriptionModel) + { + var prefixes = new HashSet(SharedContractTypeNamespacePrefixes, StringComparer.Ordinal); + foreach (var serviceType in applicationApiDescriptionModel.Modules + .Where(x => !x.Key.Equals("abp", StringComparison.OrdinalIgnoreCase)) + .Select(x => x.Value) + .SelectMany(x => x.Controllers.Values) + .Where(ShouldGenerateController) + .Select(x => x.Interfaces.Last().Type)) + { + var prefix = GetVoloModuleNamespacePrefix(serviceType); + if (prefix != null) + { + prefixes.Add(prefix); + } + } + + return prefixes; + } + + private static string GetVoloModuleNamespacePrefix(string typeName) + { + if (!typeName.StartsWith("Volo.", StringComparison.Ordinal)) + { + return null; + } + + var segments = typeName.Split('.'); + var segmentCount = segments.Length > 2 && segments[1] == "Abp" ? 3 : 2; + return segments.Length > segmentCount + ? segments.Take(segmentCount).JoinAsString(".") + "." + : null; + } + + private Dictionary GetDtoFilePaths(GenerateProxyArgs args, ApplicationApiDescriptionModel applicationApiDescriptionModel) + { + var typeNames = _typesToGenerate + .ToDictionary(x => x, x => GetDtoTypeName(x, applicationApiDescriptionModel.Types[x])); + + var filePaths = typeNames.ToDictionary(x => x.Key, x => GetDtoFilePath(args, x.Value, false, false)); + foreach (var sameFileTypes in filePaths.GroupBy(x => x.Value).Where(x => x.Count() > 1).ToList()) + { + foreach (var typeKey in sameFileTypes.Select(x => x.Key).Where(x => x.Contains('<'))) + { + filePaths[typeKey] = GetDtoFilePath(args, typeNames[typeKey], true, false); + } + } + + foreach (var sameFileTypes in filePaths.GroupBy(x => x.Value).Where(x => x.Count() > 1).ToList()) + { + foreach (var typeKey in sameFileTypes.Select(x => x.Key)) + { + filePaths[typeKey] = GetDtoFilePath(args, typeNames[typeKey], true, true); + } + } + + return filePaths; + } + + private static string GetDtoTypeName(string typeKey, TypeApiDescriptionModel type) + { + return type.GenericArguments.IsNullOrEmpty() + ? typeKey + : $"{typeKey.Left(typeKey.IndexOf('<'))}<{type.GenericArguments.JoinAsString(",")}>"; + } + + private string GetDtoFilePath(GenerateProxyArgs args, string genericTypeName, bool includeGenericArguments, bool includeNamespace) + { + var folder = args.Folder.IsNullOrWhiteSpace() + ? ProxyDirectory + Path.DirectorySeparatorChar + GetTypeNamespace(genericTypeName) + .Replace(".", Path.DirectorySeparatorChar.ToString()) + : args.Folder; + + var realTypeName = GetRealTypeName(genericTypeName, normalizeNestedTypeForGeneratedContracts: true); + var dtoFileName = includeGenericArguments + ? realTypeName.Replace('<', '{').Replace('>', '}').Replace(" ", string.Empty) + : realTypeName.Split("<")[0]; + + if (includeNamespace) + { + dtoFileName = $"{GetTypeNamespace(genericTypeName.Split('<')[0])}.{dtoFileName}"; + } + + return Path.Combine(args.WorkDirectory, folder, $"{dtoFileName}.cs"); + } + + private async Task GenerateDtoFileAsync(GenerateProxyArgs args, ApplicationApiDescriptionModel applicationApiDescriptionModel) + { + var filePaths = GetDtoFilePaths(args, applicationApiDescriptionModel); + + foreach (var type in applicationApiDescriptionModel.Types.Where(x => filePaths.ContainsKey(x.Key))) + { + var dto = new StringBuilder(DtoTemplate); + var dtoUsingNamespaceList = new List(DtoUsingNamespaceList) + { + $"using {GetTypeNamespace(type.Key)};" + }; + + var genericTypeName = GetDtoTypeName(type.Key, type.Value); dto.Replace(NamespacePlaceholder, GetTypeNamespace(genericTypeName)); dto.Replace(DtoClassNamePlaceholder, type.Value.IsEnum - ? "enum " + GetRealTypeName(genericTypeName, dtoUsingNamespaceList) - : "class " + GetRealTypeName(genericTypeName, dtoUsingNamespaceList) + + ? "enum " + GetRealTypeName(genericTypeName, dtoUsingNamespaceList, normalizeNestedTypeForGeneratedContracts: true) + : "class " + GetRealTypeName(genericTypeName, dtoUsingNamespaceList, normalizeNestedTypeForGeneratedContracts: true) + (type.Value.BaseType.IsNullOrEmpty() ? "" - : $" : {GetRealTypeName(type.Value.BaseType, dtoUsingNamespaceList)}")); + : $" : {GetTypeReference(type.Value.BaseType, dtoUsingNamespaceList)}")); var properties = new StringBuilder(); if (type.Value.IsEnum) { @@ -486,9 +885,7 @@ public class CSharpServiceProxyGenerator : ServiceProxyGeneratorBase x).Select(x => x))); dto.Replace(PropertyPlaceholder, properties.ToString()); - var folder = args.Folder.IsNullOrWhiteSpace() - ? ProxyDirectory + Path.DirectorySeparatorChar + GetTypeNamespace(genericTypeName) - .Replace(".", Path.DirectorySeparatorChar.ToString()) - : args.Folder; - - var dtoFileName = GetRealTypeName(genericTypeName).Split("<")[0]; - var filePath = Path.Combine(args.WorkDirectory, folder, - $"{dtoFileName}.cs"); + var filePath = filePaths[type.Key]; Directory.CreateDirectory(Path.GetDirectoryName(filePath)); using (var writer = new StreamWriter(filePath)) { @@ -531,25 +921,59 @@ public class CSharpServiceProxyGenerator : ServiceProxyGeneratorBase usingNamespaceList = null) + private string GetTypeReference(string typeName, List usingNamespaceList = null) + { + return GetRealTypeName(typeName, usingNamespaceList, _ambiguousTypeNames); + } + + private HashSet GetAmbiguousTypeNames( + ApplicationApiDescriptionModel applicationApiDescriptionModel, + IEnumerable typesToGenerate) + { + var typeNames = GetSignatureTypeNames(applicationApiDescriptionModel) + .Concat(typesToGenerate.SelectMany(typeKey => + { + var type = applicationApiDescriptionModel.Types[typeKey]; + return new[] { typeKey, type.BaseType } + .Concat((type.Properties ?? []).Select(x => x.Type)); + })) + .SelectMany(x => ParseTypeNames(x).Select(t => t.Name)) + .Distinct() + .GroupBy(x => NormalizeNestedTypeName(x, _generatedContractTypeNames.Contains(x)).Split('.').Last()) + .Where(x => x.Count() > 1) + .SelectMany(x => x); + + return new HashSet(typeNames); + } + + private string GetRealTypeName( + string typeName, + List usingNamespaceList = null, + ICollection ambiguousTypeNames = null, + bool? normalizeNestedTypeForGeneratedContracts = null) { if (typeName.StartsWith("[") && typeName.EndsWith("]")) { - return GetRealTypeName(typeName.Substring(1, typeName.Length - 2), usingNamespaceList) + "[]"; + return GetRealTypeName(typeName.Substring(1, typeName.Length - 2), usingNamespaceList, ambiguousTypeNames, normalizeNestedTypeForGeneratedContracts) + "[]"; } if (typeName.StartsWith("{") && typeName.EndsWith("}") && typeName.Contains(":")) { - var dic = typeName.Substring(1, typeName.Length - 2).Split(":"); - var key = GetRealTypeName(dic[0], usingNamespaceList); - var value = GetRealTypeName(dic[1], usingNamespaceList); + var dic = typeName.Substring(1, typeName.Length - 2).Split(new[] { ':' }, 2); + var key = GetRealTypeName(dic[0], usingNamespaceList, ambiguousTypeNames, normalizeNestedTypeForGeneratedContracts); + var value = GetRealTypeName(dic[1], usingNamespaceList, ambiguousTypeNames, normalizeNestedTypeForGeneratedContracts); return $"Dictionary<{key}, {value}>"; } + if (!typeName.Contains('.') && !typeName.Contains('<')) + { + return NormalizeTypeName(typeName); + } + if (!typeName.Contains("<")) { usingNamespaceList?.AddIfNotContains($"using {GetTypeNamespace(typeName)};"); - return NormalizeTypeName(typeName.Split(".").Last()); + return NormalizeTypeName(GetShortTypeName(typeName, ambiguousTypeNames, normalizeNestedTypeForGeneratedContracts)); } if(usingNamespaceList != null) @@ -557,56 +981,37 @@ public class CSharpServiceProxyGenerator : ServiceProxyGeneratorBase")) - { - type.Append("<"); - } - } - } - else - { - type.Append(s1[i].Split(".").Last()); - if (i < s1.Length - 1) - { - type.Append("<"); - } - } - } + return Regex.Replace(typeName, @"[\w.+]+", x => x.Value.Contains('.') + ? GetShortTypeName(x.Value, ambiguousTypeNames, normalizeNestedTypeForGeneratedContracts) + : x.Value) + .Replace(",", ", "); + } - return type.ToString(); + private string GetShortTypeName( + string typeFullName, + ICollection ambiguousTypeNames, + bool? normalizeNestedTypeForGeneratedContracts) + { + var referencedTypeName = ParseTypeNames(typeFullName).Select(x => x.Name).FirstOrDefault() ?? typeFullName.TrimEnd('?'); + var normalizeNestedType = normalizeNestedTypeForGeneratedContracts ?? _generatedContractTypeNames.Contains(referencedTypeName); + var normalizedTypeFullName = NormalizeNestedTypeName(typeFullName, normalizeNestedType); + return ambiguousTypeNames != null && ambiguousTypeNames.Contains(referencedTypeName) + ? $"global::{normalizedTypeFullName}" + : normalizeNestedType + ? normalizedTypeFullName.Split(".").Last() + : NormalizeNestedTypeName(typeFullName.Split(".").Last(), false); } - private static void AddGenericTypeUsingNamespace(string typeFullName, List usingNamespaceList) + private static string NormalizeNestedTypeName(string typeName, bool forGeneratedContracts = true) { - if(!typeFullName.Contains("<")) - { - usingNamespaceList.AddIfNotContains($"using {GetTypeNamespace(typeFullName)};"); - } + return typeName.Replace("+", forGeneratedContracts ? NestedTypeSeparator : "."); + } - if (typeFullName.Contains("<") && typeFullName.Contains(">")) + private static void AddGenericTypeUsingNamespace(string typeFullName, List usingNamespaceList) + { + foreach (var typeName in ParseTypeNames(typeFullName)) { - var left = typeFullName.IndexOf("<", StringComparison.Ordinal); - var right = typeFullName.LastIndexOf(">", StringComparison.Ordinal); - var genericTypes = typeFullName.Substring(left + 1, right - left - 1); - foreach (var genericType in genericTypes.Split(",").Where(x => x.Contains("."))) - { - AddGenericTypeUsingNamespace(genericType, usingNamespaceList); - } + usingNamespaceList.AddIfNotContains($"using {GetTypeNamespace(typeName.Name)};"); } } diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/RandomHelper.cs b/framework/src/Volo.Abp.Core/Volo/Abp/RandomHelper.cs index 0a5b3ffd05..01fc02346c 100644 --- a/framework/src/Volo.Abp.Core/Volo/Abp/RandomHelper.cs +++ b/framework/src/Volo.Abp.Core/Volo/Abp/RandomHelper.cs @@ -11,7 +11,9 @@ namespace Volo.Abp; /// public static class RandomHelper { +#if NETSTANDARD2_0 || NETSTANDARD2_1 private static readonly Random Rnd = new Random(); +#endif /// /// Returns a random number within a specified range. @@ -25,10 +27,14 @@ public static class RandomHelper /// public static int GetRandom(int minValue, int maxValue) { +#if NETSTANDARD2_0 || NETSTANDARD2_1 lock (Rnd) { return Rnd.Next(minValue, maxValue); } +#else + return Random.Shared.Next(minValue, maxValue); +#endif } /// @@ -42,10 +48,14 @@ public static class RandomHelper /// public static int GetRandom(int maxValue) { +#if NETSTANDARD2_0 || NETSTANDARD2_1 lock (Rnd) { return Rnd.Next(maxValue); } +#else + return Random.Shared.Next(maxValue); +#endif } /// @@ -54,10 +64,14 @@ public static class RandomHelper /// A 32-bit signed integer greater than or equal to zero and less than . public static int GetRandom() { +#if NETSTANDARD2_0 || NETSTANDARD2_1 lock (Rnd) { return Rnd.Next(); } +#else + return Random.Shared.Next(); +#endif } /// @@ -93,16 +107,16 @@ public static class RandomHelper { Check.NotNull(items, nameof(items)); - var currentList = new List(items); - var randomList = new List(); - - while (currentList.Any()) + var array = items.ToArray(); +#if NETSTANDARD2_0 || NETSTANDARD2_1 + for (var i = array.Length - 1; i > 0; i--) { - var randomIndex = RandomHelper.GetRandom(0, currentList.Count); - randomList.Add(currentList[randomIndex]); - currentList.RemoveAt(randomIndex); + var j = GetRandom(i + 1); + (array[i], array[j]) = (array[j], array[i]); } - - return randomList; +#else + Random.Shared.Shuffle(array); +#endif + return array.ToList(); } } diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/Threading/RetryAttempt.cs b/framework/src/Volo.Abp.Core/Volo/Abp/Threading/RetryAttempt.cs new file mode 100644 index 0000000000..32afaad23b --- /dev/null +++ b/framework/src/Volo.Abp.Core/Volo/Abp/Threading/RetryAttempt.cs @@ -0,0 +1,49 @@ +using System; + +namespace Volo.Abp.Threading; + +/// +/// A failed attempt that is about to retry. +/// +public class RetryAttempt +{ + /// + /// Number of the retry that is about to be performed, starting from 1. + /// + public int RetryCount { get; } + + /// + /// How long to wait before the retry. + /// + public TimeSpan RetryDelay { get; } + + /// + /// The exception that caused the retry. Null if the attempt is retried because of its result. + /// + public Exception? Exception { get; } + + public RetryAttempt(int retryCount, TimeSpan retryDelay, Exception? exception) + { + RetryCount = retryCount; + RetryDelay = retryDelay; + Exception = exception; + } +} + +/// +/// A failed attempt that is about to retry. +/// +/// Type of the value returned by the retried action. +public class RetryAttempt : RetryAttempt +{ + /// + /// The result that caused the retry. Default if the attempt is retried because of an exception. + /// + public TResult? Result { get; } + + public RetryAttempt(int retryCount, TimeSpan retryDelay, Exception? exception, TResult? result) + : base(retryCount, retryDelay, exception) + { + Result = result; + } +} diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/Threading/RetryHelper.cs b/framework/src/Volo.Abp.Core/Volo/Abp/Threading/RetryHelper.cs new file mode 100644 index 0000000000..9c543dfbe0 --- /dev/null +++ b/framework/src/Volo.Abp.Core/Volo/Abp/Threading/RetryHelper.cs @@ -0,0 +1,237 @@ +using System; +using System.Runtime.ExceptionServices; +using System.Threading; +using System.Threading.Tasks; + +namespace Volo.Abp.Threading; + +/// +/// Runs an action and retries it while it keeps failing, waiting between the attempts. +/// See to control the retry count, the delay and which failures are retried. +/// +public static class RetryHelper +{ + // Task.Delay rejects a longer delay on the netstandard targets. + private static readonly TimeSpan MaxDelay = TimeSpan.FromMilliseconds(int.MaxValue); + + /// + /// Runs the given action and retries it while it throws a retryable exception. + /// Rethrows the last exception when the retries are exhausted. + /// + public static async Task ExecuteAsync( + Func action, + RetryOptions? options = null, + CancellationToken cancellationToken = default) + { + Check.NotNull(action, nameof(action)); + + options ??= new RetryOptions(); + + // Read once, so that changing a shared instance cannot affect a running execution. + var maxRetryCount = options.MaxRetryCount; + var delayFactory = options.DelayFactory; + var shouldRetryOnException = options.ShouldRetryOnException; + var onRetry = options.OnRetry; + + Validate(maxRetryCount, delayFactory, shouldRetryOnException); + + var retryCount = 0; + + while (true) + { + cancellationToken.ThrowIfCancellationRequested(); + + Exception? caught = null; + + try + { + await action(cancellationToken); + return; + } + catch (Exception ex) + { + caught = ex; + } + + var exception = caught!; + + // Asked on every attempt, including the last one, which is not retried. + var isHandled = shouldRetryOnException(exception); + + if (!isHandled || IsLastRetry(retryCount, maxRetryCount)) + { + ExceptionDispatchInfo.Capture(exception).Throw(); + } + + retryCount = NextRetryCount(retryCount); + + var delay = GetDelay(delayFactory, retryCount); + if (onRetry != null) + { + await onRetry(new RetryAttempt(retryCount, delay, exception)); + } + + await WaitAsync(delay, cancellationToken); + } + } + + /// + /// Runs the given action and retries it while it throws a retryable exception or returns a retryable result. + /// Rethrows the last exception when the retries are exhausted, or returns the result of the last attempt + /// if it failed because of its result. A retried result is disposed if it is disposable. + /// + public static async Task ExecuteAsync( + Func> action, + RetryOptions? options = null, + CancellationToken cancellationToken = default) + { + Check.NotNull(action, nameof(action)); + + options ??= new RetryOptions(); + + // Read once, so that changing a shared instance cannot affect a running execution. + var maxRetryCount = options.MaxRetryCount; + var delayFactory = options.DelayFactory; + var shouldRetryOnException = options.ShouldRetryOnException; + var shouldRetryOnResult = options.ShouldRetryOnResult; + var onRetry = options.OnRetry; + + Validate(maxRetryCount, delayFactory, shouldRetryOnException); + Check.NotNull(shouldRetryOnResult, nameof(RetryOptions.ShouldRetryOnResult)); + + var retryCount = 0; + + while (true) + { + cancellationToken.ThrowIfCancellationRequested(); + + Exception? exception = null; + var result = default(TResult)!; + + // A result the caller never sees must not leak, whatever throws before it is disposed. + var discardResult = false; + TimeSpan delay; + + try + { + try + { + result = await action(cancellationToken); + discardResult = true; + + if (!shouldRetryOnResult(result)) + { + discardResult = false; + return result; + } + } + catch (Exception ex) + { + exception = ex; + } + + // Asked on every attempt, including the last one, which is not retried. + var isUnhandledException = exception != null && !shouldRetryOnException(exception); + + if (isUnhandledException || IsLastRetry(retryCount, maxRetryCount)) + { + if (exception != null) + { + ExceptionDispatchInfo.Capture(exception).Throw(); + } + + discardResult = false; + return result; + } + + retryCount = NextRetryCount(retryCount); + + delay = GetDelay(delayFactory, retryCount); + if (onRetry != null) + { + await onRetry(new RetryAttempt(retryCount, delay, exception, exception == null ? result : default)); + } + } + finally + { + // After OnRetry and before the wait, as the retried result is reported but not kept. + if (discardResult) + { + await TryDisposeAsync(result); + } + } + + await WaitAsync(delay, cancellationToken); + } + } + + private static void Validate( + int maxRetryCount, + Func delayFactory, + Func shouldRetryOnException) + { + if (maxRetryCount < 0) + { + throw new ArgumentOutOfRangeException(nameof(RetryOptions.MaxRetryCount), maxRetryCount, "Must not be negative."); + } + + Check.NotNull(delayFactory, nameof(RetryOptions.DelayFactory)); + Check.NotNull(shouldRetryOnException, nameof(RetryOptions.ShouldRetryOnException)); + } + + // int.MaxValue means "retry forever": the counter stops there instead of overflowing. + private static bool IsLastRetry(int retryCount, int maxRetryCount) + { + return maxRetryCount != int.MaxValue && retryCount >= maxRetryCount; + } + + private static TimeSpan GetDelay(Func delayFactory, int retryCount) + { + var delay = delayFactory(retryCount); + + // Clamped before it is reported, so that the reported delay is the one that is waited for. + return delay > MaxDelay ? MaxDelay : delay; + } + + internal static TimeSpan GetExponentialDelay(int retryCount) + { + var seconds = Math.Pow(2, retryCount); + + // Stops growing instead of overflowing when the retry count gets high. + return seconds >= MaxDelay.TotalSeconds ? MaxDelay : TimeSpan.FromSeconds(seconds); + } + + private static int NextRetryCount(int retryCount) + { + return retryCount == int.MaxValue ? retryCount : retryCount + 1; + } + + private static async Task TryDisposeAsync(TResult result) + { + try + { + if (result is IAsyncDisposable asyncDisposable) + { + await asyncDisposable.DisposeAsync(); + } + else if (result is IDisposable disposable) + { + disposable.Dispose(); + } + } + catch + { + // A result that is being thrown away should not fail the retry. + } + } + + private static async Task WaitAsync(TimeSpan delay, CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + + if (delay > TimeSpan.Zero) + { + await Task.Delay(delay, cancellationToken); + } + } +} diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/Threading/RetryOptions.cs b/framework/src/Volo.Abp.Core/Volo/Abp/Threading/RetryOptions.cs new file mode 100644 index 0000000000..f3462b75aa --- /dev/null +++ b/framework/src/Volo.Abp.Core/Volo/Abp/Threading/RetryOptions.cs @@ -0,0 +1,69 @@ +using System; +using System.Threading.Tasks; + +namespace Volo.Abp.Threading; + +/// +/// Options to control how retries a failing action. +/// +public class RetryOptions +{ + /// + /// How many times to retry after the initial attempt fails. Default: 3. + /// Set to to retry forever. + /// + public int MaxRetryCount { get; set; } = 3; + + /// + /// Returns how long to wait before the given retry. + /// Default: 2^retryCount seconds, up to the longest delay that can be waited for. + /// + public Func DelayFactory { get; set; } = RetryHelper.GetExponentialDelay; + + /// + /// Decides if the action should be retried after the given exception. + /// Default: retries any exception except . + /// + public Func ShouldRetryOnException { get; set; } = exception => exception is not OperationCanceledException; + + /// + /// Called once per retry, before waiting. + /// + public Func? OnRetry { get; set; } +} + +/// +/// Options to control how retries a failing action that returns a value. +/// The action can also be retried because of the value it returned. +/// +/// Type of the value returned by the retried action. +public class RetryOptions +{ + /// + /// How many times to retry after the initial attempt fails. Default: 3. + /// Set to to retry forever. + /// + public int MaxRetryCount { get; set; } = 3; + + /// + /// Returns how long to wait before the given retry. + /// Default: 2^retryCount seconds, up to the longest delay that can be waited for. + /// + public Func DelayFactory { get; set; } = RetryHelper.GetExponentialDelay; + + /// + /// Decides if the action should be retried after the given exception. + /// Default: retries any exception except . + /// + public Func ShouldRetryOnException { get; set; } = exception => exception is not OperationCanceledException; + + /// + /// Decides if the action should be retried because of the value it returned. Default: no result is retried. + /// + public Func ShouldRetryOnResult { get; set; } = _ => false; + + /// + /// Called once per retry, before the retried result is disposed and before waiting. + /// + public Func, Task>? OnRetry { get; set; } +} diff --git a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Localization/Resources/AbpDdd/ko.json b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Localization/Resources/AbpDdd/ko.json new file mode 100644 index 0000000000..23004a404f --- /dev/null +++ b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Localization/Resources/AbpDdd/ko.json @@ -0,0 +1,6 @@ +{ + "culture": "ko", + "texts": { + "MaxResultCountExceededExceptionMessage": "{0}은(는) {1}보다 클 수 없습니다! 더 많은 결과를 허용하려면 서버 측에서 {2}.{3}을(를) 늘리십시오." + } +} diff --git a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyReadOnlyAppService.cs b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyReadOnlyAppService.cs index 3791c4202f..fa8aafc76a 100644 --- a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyReadOnlyAppService.cs +++ b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/AbstractKeyReadOnlyAppService.cs @@ -2,12 +2,14 @@ using System.Collections.Generic; using System.Linq; using System.Linq.Dynamic.Core; +using System.Threading; using System.Threading.Tasks; using Volo.Abp.Application.Dtos; using Volo.Abp.Auditing; using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Repositories; using Volo.Abp.ObjectMapping; +using Volo.Abp.Threading; namespace Volo.Abp.Application.Services; @@ -44,6 +46,20 @@ public abstract class AbstractKeyReadOnlyAppService + /// Used by the to project the query to the . + /// The and the are not used while the query is projected. + /// + protected virtual IQueryProjector? GetOutputDtoQueryProjector + => LazyServiceProvider.LazyGetService>(); + + /// + /// Used by the to project the query to the . + /// The is not used while the query is projected. + /// + protected virtual IQueryProjector? GetListOutputDtoQueryProjector + => LazyServiceProvider.LazyGetService>(); + protected AbstractKeyReadOnlyAppService(IReadOnlyRepository repository) { ReadOnlyRepository = repository; @@ -53,6 +69,19 @@ public abstract class AbstractKeyReadOnlyAppService(id); + } + + return dtos[0]; + } + var entity = await GetEntityByIdAsync(id); return await MapToGetOutputDtoAsync(entity); @@ -65,7 +94,6 @@ public abstract class AbstractKeyReadOnlyAppService(); var entityDtos = new List(); if (totalCount > 0) @@ -73,8 +101,16 @@ public abstract class AbstractKeyReadOnlyAppService( @@ -85,6 +121,57 @@ public abstract class AbstractKeyReadOnlyAppService GetEntityByIdAsync(TKey id); + private CancellationToken GetCancellationToken() + { + return LazyServiceProvider + .LazyGetService(NullCancellationTokenProvider.Instance) + .FallbackToProvider(); + } + + /// + /// Should create a query that selects the entity with the given . + /// It returns null by default, then the entity is not projected. + /// + /// The id of the entity. + protected virtual Task?> CreateEntityQueryOrNullAsync(TKey id) + { + return Task.FromResult?>(null); + } + + /// + /// Projects the query of the entity with the given to the . + /// It uses the and the by default, + /// and the is used when it returns null. + /// Override it to await other queries, like the query of another aggregate root to join. + /// + /// The id of the entity. + protected virtual async Task?> CreateGetOutputDtoQueryOrNullAsync(TKey id) + { + var queryProjector = GetOutputDtoQueryProjector; + if (queryProjector == null) + { + return null; + } + + var query = await CreateEntityQueryOrNullAsync(id); + + return query == null ? null : queryProjector.ProjectTo(query); + } + + /// + /// Projects the given entity query to the . + /// It uses the by default, + /// and the is used when it returns null. + /// Override it to await other queries, like the query of another aggregate root to join. + /// The projection must return one row per entity: the total count is already calculated and the paging is + /// already applied, so adding or removing rows makes the page inconsistent with the total count. + /// + /// The sorted and paged entity query. + protected virtual Task?> CreateGetListOutputDtoQueryOrNullAsync(IQueryable query) + { + return Task.FromResult(GetListOutputDtoQueryProjector?.ProjectTo(query)); + } + protected virtual async Task CheckGetPolicyAsync() { await CheckPolicyAsync(GetPolicyName); diff --git a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/CrudAppService.cs b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/CrudAppService.cs index 672d85a2be..906b138fba 100644 --- a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/CrudAppService.cs +++ b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/CrudAppService.cs @@ -84,6 +84,13 @@ public abstract class CrudAppService?> CreateEntityQueryOrNullAsync(TKey id) + { + var query = await Repository.GetQueryableAsync(); + + return query.Where(e => e.Id!.Equals(id)); + } + protected override void MapToEntity(TUpdateInput updateInput, TEntity entity) { if (updateInput is IEntityDto entityDto) diff --git a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ReadOnlyAppService.cs b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ReadOnlyAppService.cs index 867ca35ad4..c36d17ffc8 100644 --- a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ReadOnlyAppService.cs +++ b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ReadOnlyAppService.cs @@ -47,6 +47,13 @@ public abstract class ReadOnlyAppService?> CreateEntityQueryOrNullAsync(TKey id) + { + var query = await Repository.GetQueryableAsync(); + + return query.Where(e => e.Id!.Equals(id)); + } + protected override IQueryable ApplyDefaultSorting(IQueryable query) { if (typeof(TEntity).IsAssignableTo()) diff --git a/framework/src/Volo.Abp.Emailing/Volo/Abp/Emailing/Localization/ko.json b/framework/src/Volo.Abp.Emailing/Volo/Abp/Emailing/Localization/ko.json new file mode 100644 index 0000000000..1eef424242 --- /dev/null +++ b/framework/src/Volo.Abp.Emailing/Volo/Abp/Emailing/Localization/ko.json @@ -0,0 +1,25 @@ +{ + "culture": "ko", + "texts": { + "DisplayName:Abp.Mailing.DefaultFromAddress": "기본 발신자 주소", + "DisplayName:Abp.Mailing.DefaultFromDisplayName": "기본 발신자 표시 이름", + "DisplayName:Abp.Mailing.Smtp.Host": "호스트", + "DisplayName:Abp.Mailing.Smtp.Port": "포트", + "DisplayName:Abp.Mailing.Smtp.UserName": "사용자 이름", + "DisplayName:Abp.Mailing.Smtp.Password": "비밀번호", + "DisplayName:Abp.Mailing.Smtp.Domain": "도메인", + "DisplayName:Abp.Mailing.Smtp.EnableSsl": "SSL 사용", + "DisplayName:Abp.Mailing.Smtp.UseDefaultCredentials": "기본 자격 증명 사용", + "Description:Abp.Mailing.DefaultFromAddress": "기본 발신자 주소입니다.", + "Description:Abp.Mailing.DefaultFromDisplayName": "기본 발신자 표시 이름입니다.", + "Description:Abp.Mailing.Smtp.Host": "SMTP 통신에 사용되는 호스트 이름 또는 IP 주소입니다.", + "Description:Abp.Mailing.Smtp.Port": "SMTP 통신에 사용되는 포트입니다.", + "Description:Abp.Mailing.Smtp.UserName": "자격 증명에 연결된 사용자 이름입니다.", + "Description:Abp.Mailing.Smtp.Password": "자격 증명에 연결된 사용자 이름의 비밀번호입니다.", + "Description:Abp.Mailing.Smtp.Domain": "자격 증명을 인증하는 도메인 또는 컴퓨터 이름입니다.", + "Description:Abp.Mailing.Smtp.EnableSsl": "SmtpClient가 SSL(Secure Sockets Layer)을 사용하여 연결을 암호화할지 여부입니다.", + "Description:Abp.Mailing.Smtp.UseDefaultCredentials": "요청과 함께 DefaultCredentials를 전송할지 여부입니다.", + "TextTemplate:StandardEmailTemplates.Layout": "기본 이메일 레이아웃 템플릿", + "TextTemplate:StandardEmailTemplates.Message": "이메일용 단순 메시지 템플릿" + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.ExceptionHandling/Volo/Abp/ExceptionHandling/Localization/ko.json b/framework/src/Volo.Abp.ExceptionHandling/Volo/Abp/ExceptionHandling/Localization/ko.json new file mode 100644 index 0000000000..5af604d208 --- /dev/null +++ b/framework/src/Volo.Abp.ExceptionHandling/Volo/Abp/ExceptionHandling/Localization/ko.json @@ -0,0 +1,31 @@ +{ + "culture": "ko", + "texts": { + "InternalServerErrorMessage": "요청을 처리하는 동안 내부 오류가 발생했습니다!", + "ValidationErrorMessage": "요청이 유효하지 않습니다!", + "ValidationNarrativeErrorMessageTitle": "유효성 검사 중 다음 오류가 발견되었습니다.", + "DefaultErrorMessage": "오류가 발생했습니다!", + "DefaultErrorMessageDetail": "서버에서 오류 세부 정보를 보내지 않았습니다.", + "DefaultErrorMessage401": "인증되지 않았습니다!", + "DefaultErrorMessage401Detail": "이 작업을 수행하려면 로그인해야 합니다.", + "DefaultErrorMessage403": "권한이 없습니다!", + "DefaultErrorMessage403Detail": "이 작업을 수행할 권한이 없습니다!", + "DefaultErrorMessage404": "리소스를 찾을 수 없습니다!", + "DefaultErrorMessage404Detail": "서버에서 요청한 리소스를 찾을 수 없습니다!", + "EntityNotFoundErrorMessage": "{0} 엔터티 중 ID가 {1}인 항목이 없습니다!", + "EntityNotFoundErrorMessageWithoutId": "{0} 엔터티가 없습니다!", + "AbpDbConcurrencyErrorMessage": "제출한 데이터가 이미 다른 사용자에 의해 변경되었습니다. 변경 사항을 취소하고 다시 시도해 주세요.", + "Error": "오류", + "UnhandledException": "처리되지 않은 예외가 발생했습니다!", + "Authorizing": "권한을 확인하는 중…", + "401Message": "인증되지 않음", + "403Message": "접근 금지", + "404Message": "페이지를 찾을 수 없음", + "500Message": "내부 서버 오류", + "403MessageDetail": "이 작업을 수행할 권한이 없습니다!", + "404MessageDetail": "죄송합니다. 이 주소에 해당하는 페이지가 없습니다.", + "Unauthorized": "인증되지 않음", + "invalid_token": "유효하지 않은 토큰", + "SessionExpired": "세션이 만료되었습니다. 애플리케이션을 계속 사용하려면 다시 로그인해 주세요." + } +} diff --git a/framework/src/Volo.Abp.Features/Volo/Abp/Features/Localization/ko.json b/framework/src/Volo.Abp.Features/Volo/Abp/Features/Localization/ko.json new file mode 100644 index 0000000000..5dd9859e62 --- /dev/null +++ b/framework/src/Volo.Abp.Features/Volo/Abp/Features/Localization/ko.json @@ -0,0 +1,8 @@ +{ + "culture": "ko", + "texts": { + "Volo.Feature:010001": "기능이 활성화되지 않았습니다: {FeatureName}", + "Volo.Feature:010002": "필수 기능이 활성화되지 않았습니다. 다음 기능을 모두 활성화해야 합니다: {FeatureNames}", + "Volo.Feature:010003": "필수 기능이 활성화되지 않았습니다. 다음 기능 중 하나 이상을 활성화해야 합니다: {FeatureNames}" + } +} diff --git a/framework/src/Volo.Abp.GlobalFeatures/Volo/Abp/GlobalFeatures/Localization/ko.json b/framework/src/Volo.Abp.GlobalFeatures/Volo/Abp/GlobalFeatures/Localization/ko.json new file mode 100644 index 0000000000..5f4094051d --- /dev/null +++ b/framework/src/Volo.Abp.GlobalFeatures/Volo/Abp/GlobalFeatures/Localization/ko.json @@ -0,0 +1,6 @@ +{ + "culture": "ko", + "texts": { + "Volo.GlobalFeature:010001": "'{ServiceName}' 서비스에서 '{GlobalFeatureName}' 기능을 활성화해야 합니다." + } +} diff --git a/framework/src/Volo.Abp.Http.FluentValidation/Properties/AssemblyInfo.cs b/framework/src/Volo.Abp.Http.FluentValidation/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..1c556d5b2e --- /dev/null +++ b/framework/src/Volo.Abp.Http.FluentValidation/Properties/AssemblyInfo.cs @@ -0,0 +1,3 @@ +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Volo.Abp.Http.FluentValidation.Tests")] diff --git a/framework/src/Volo.Abp.Http.FluentValidation/Volo.Abp.Http.FluentValidation.abppkg b/framework/src/Volo.Abp.Http.FluentValidation/Volo.Abp.Http.FluentValidation.abppkg new file mode 100644 index 0000000000..f4bad072d2 --- /dev/null +++ b/framework/src/Volo.Abp.Http.FluentValidation/Volo.Abp.Http.FluentValidation.abppkg @@ -0,0 +1,3 @@ +{ + "role": "lib.framework" +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.Http.FluentValidation/Volo.Abp.Http.FluentValidation.abppkg.analyze.json b/framework/src/Volo.Abp.Http.FluentValidation/Volo.Abp.Http.FluentValidation.abppkg.analyze.json new file mode 100644 index 0000000000..cdcde838c3 --- /dev/null +++ b/framework/src/Volo.Abp.Http.FluentValidation/Volo.Abp.Http.FluentValidation.abppkg.analyze.json @@ -0,0 +1,68 @@ +{ + "name": "Volo.Abp.Http.FluentValidation", + "hash": "", + "contents": [ + { + "namespace": "Volo.Abp.Http.FluentValidation", + "dependsOnModules": [ + { + "declaringAssemblyName": "Volo.Abp.Http", + "namespace": "Volo.Abp.Http", + "name": "AbpHttpModule" + }, + { + "declaringAssemblyName": "Volo.Abp.FluentValidation", + "namespace": "Volo.Abp.FluentValidation", + "name": "AbpFluentValidationModule" + } + ], + "implementingInterfaces": [ + { + "name": "IAbpModule", + "namespace": "Volo.Abp.Modularity", + "declaringAssemblyName": "Volo.Abp.Core", + "fullName": "Volo.Abp.Modularity.IAbpModule" + }, + { + "name": "IOnPreApplicationInitialization", + "namespace": "Volo.Abp.Modularity", + "declaringAssemblyName": "Volo.Abp.Core", + "fullName": "Volo.Abp.Modularity.IOnPreApplicationInitialization" + }, + { + "name": "IOnApplicationInitialization", + "namespace": "Volo.Abp", + "declaringAssemblyName": "Volo.Abp.Core", + "fullName": "Volo.Abp.IOnApplicationInitialization" + }, + { + "name": "IOnPostApplicationInitialization", + "namespace": "Volo.Abp.Modularity", + "declaringAssemblyName": "Volo.Abp.Core", + "fullName": "Volo.Abp.Modularity.IOnPostApplicationInitialization" + }, + { + "name": "IOnApplicationShutdown", + "namespace": "Volo.Abp", + "declaringAssemblyName": "Volo.Abp.Core", + "fullName": "Volo.Abp.IOnApplicationShutdown" + }, + { + "name": "IPreConfigureServices", + "namespace": "Volo.Abp.Modularity", + "declaringAssemblyName": "Volo.Abp.Core", + "fullName": "Volo.Abp.Modularity.IPreConfigureServices" + }, + { + "name": "IPostConfigureServices", + "namespace": "Volo.Abp.Modularity", + "declaringAssemblyName": "Volo.Abp.Core", + "fullName": "Volo.Abp.Modularity.IPostConfigureServices" + } + ], + "contentType": "abpModule", + "name": "AbpHttpFluentValidationModule", + "summary": null + } + ] +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.Http.FluentValidation/Volo.Abp.Http.FluentValidation.csproj b/framework/src/Volo.Abp.Http.FluentValidation/Volo.Abp.Http.FluentValidation.csproj new file mode 100644 index 0000000000..5c44a55420 --- /dev/null +++ b/framework/src/Volo.Abp.Http.FluentValidation/Volo.Abp.Http.FluentValidation.csproj @@ -0,0 +1,24 @@ + + + + + + + net8.0;net9.0;net10.0 + enable + Nullable + Volo.Abp.Http.FluentValidation + Volo.Abp.Http.FluentValidation + $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; + false + false + false + + + + + + + + + diff --git a/framework/src/Volo.Abp.Http.FluentValidation/Volo/Abp/Http/FluentValidation/AbpHttpFluentValidationModule.cs b/framework/src/Volo.Abp.Http.FluentValidation/Volo/Abp/Http/FluentValidation/AbpHttpFluentValidationModule.cs new file mode 100644 index 0000000000..b81f040620 --- /dev/null +++ b/framework/src/Volo.Abp.Http.FluentValidation/Volo/Abp/Http/FluentValidation/AbpHttpFluentValidationModule.cs @@ -0,0 +1,12 @@ +using Volo.Abp.FluentValidation; +using Volo.Abp.Modularity; + +namespace Volo.Abp.Http.FluentValidation; + +[DependsOn( + typeof(AbpHttpModule), + typeof(AbpFluentValidationModule) + )] +public class AbpHttpFluentValidationModule : AbpModule +{ +} diff --git a/framework/src/Volo.Abp.Http.FluentValidation/Volo/Abp/Http/FluentValidation/FluentValidationPropertyApiDescriptionModelContributor.cs b/framework/src/Volo.Abp.Http.FluentValidation/Volo/Abp/Http/FluentValidation/FluentValidationPropertyApiDescriptionModelContributor.cs new file mode 100644 index 0000000000..64d07bd021 --- /dev/null +++ b/framework/src/Volo.Abp.Http.FluentValidation/Volo/Abp/Http/FluentValidation/FluentValidationPropertyApiDescriptionModelContributor.cs @@ -0,0 +1,318 @@ +using System; +using System.Collections.Concurrent; +using System.Collections.Frozen; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Reflection; +using System.Threading.Tasks; +using FluentValidation; +using FluentValidation.Internal; +using FluentValidation.Validators; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Http.Modeling; +using Volo.Abp.Reflection; + +namespace Volo.Abp.Http.FluentValidation; + +[ExposeServices(typeof(IPropertyApiDescriptionModelContributor))] +public class FluentValidationPropertyApiDescriptionModelContributor : IPropertyApiDescriptionModelContributor, ITransientDependency +{ + private static readonly FrozenSet NumericTypes = new HashSet + { + typeof(byte), + typeof(sbyte), + typeof(short), + typeof(ushort), + typeof(int), + typeof(uint), + typeof(long), + typeof(ulong), + typeof(float), + typeof(double), + typeof(decimal), + typeof(IntPtr), + typeof(UIntPtr) + }.ToFrozenSet(); + + protected IServiceProvider ServiceProvider { get; } + + protected ConcurrentDictionary?> RuleCache { get; } + + public FluentValidationPropertyApiDescriptionModelContributor(IServiceProvider serviceProvider) + { + ServiceProvider = serviceProvider; + RuleCache = new ConcurrentDictionary?>(); + } + + public virtual Task ContributeAsync(PropertyApiDescriptionModelContributionContext context) + { + Check.NotNull(context, nameof(context)); + + var rules = RuleCache.GetOrAdd(context.DeclaringType, GetUnconditionalRules); + if (rules == null) + { + return Task.CompletedTask; + } + + foreach (var validator in rules[context.Model.Name]) + { + ApplyValidator(context.Model, context.PropertyInfo, validator); + } + + return Task.CompletedTask; + } + + protected virtual ILookup? GetUnconditionalRules(Type declaringType) + { + if (declaringType.ContainsGenericParameters) + { + return null; + } + + var validator = ServiceProvider.GetService(typeof(IValidator<>).MakeGenericType(declaringType)) as IValidator; + if (validator == null) + { + return null; + } + + return validator + .CreateDescriptor() + .Rules + .Where(rule => IsUnconditional(rule) && DescribesPropertyOf(rule, declaringType)) + .SelectMany(rule => rule + .Components + .Where(component => !component.HasCondition && !component.HasAsyncCondition) + .Select(component => new KeyValuePair(rule.Member.Name, component.Validator))) + .ToLookup(x => x.Key, x => x.Value, StringComparer.Ordinal); + } + + protected virtual bool DescribesPropertyOf(IValidationRule rule, Type declaringType) + { + // The member is matched instead of the rule's property name, which OverridePropertyName + // and a custom PropertyNameResolver can change. A rule on a nested object declares its + // member on that object, so it must not be attributed to a property of this type. + return rule.Member != null && rule.Member.DeclaringType!.IsAssignableFrom(declaringType); + } + + protected virtual bool IsUnconditional(IValidationRule rule) + { + + // RuleForEach constrains the items, not the collection property itself. + if (IsCollectionRule(rule)) + { + return false; + } + + // A When(...)/Unless(...) block sets the condition on the rule, the chained form sets it on the components. + if (rule.HasCondition || rule.HasAsyncCondition) + { + return false; + } + + // Mirrors DefaultValidatorSelector: ABP never runs a rule that only belongs to a named rule set. + return rule.RuleSets.IsNullOrEmpty() || + rule.RuleSets!.Contains(RulesetValidatorSelector.DefaultRuleSetName, StringComparer.OrdinalIgnoreCase); + } + + protected virtual bool IsCollectionRule(IValidationRule rule) + { + return rule + .GetType() + .GetInterfaces() + .Any(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(ICollectionRule<,>)); + } + + protected virtual void ApplyValidator(PropertyApiDescriptionModel model, PropertyInfo propertyInfo, IPropertyValidator validator) + { + switch (validator) + { + case INotNullValidator: + case INotEmptyValidator: + model.IsRequired = true; + break; + case ILengthValidator lengthValidator: + ApplyLength(model, lengthValidator); + break; + case IRegularExpressionValidator regularExpressionValidator: + ApplyRegularExpression(model, regularExpressionValidator); + break; + case IBetweenValidator betweenValidator: + ApplyBetween(model, propertyInfo, betweenValidator); + break; + case IComparisonValidator comparisonValidator: + ApplyComparison(model, propertyInfo, comparisonValidator); + break; + } + } + + protected virtual void ApplyLength(PropertyApiDescriptionModel model, ILengthValidator validator) + { + // Every length validator has a Func form that leaves the bound at zero on the + // descriptor, so a zero is not distinguishable from a literal one and is left out. + if (validator.Min > 0) + { + model.MinLength = model.MinLength.HasValue + ? Math.Max(model.MinLength.Value, validator.Min) + : validator.Min; + } + + if (validator.Max > 0) + { + model.MaxLength = model.MaxLength.HasValue + ? Math.Min(model.MaxLength.Value, validator.Max) + : validator.Max; + } + } + + protected virtual void ApplyRegularExpression(PropertyApiDescriptionModel model, IRegularExpressionValidator validator) + { + // A single Regex field cannot express "must match all of them", so the first pattern wins. + if (!model.Regex.IsNullOrWhiteSpace() || validator.Expression.IsNullOrWhiteSpace()) + { + return; + } + + model.Regex = validator.Expression; + } + + protected virtual void ApplyComparison(PropertyApiDescriptionModel model, PropertyInfo propertyInfo, IComparisonValidator validator) + { + switch (validator.Comparison) + { + case Comparison.GreaterThan: + ApplyMinimum(model, propertyInfo, validator.ValueToCompare, isExclusive: true); + break; + case Comparison.GreaterThanOrEqual: + ApplyMinimum(model, propertyInfo, validator.ValueToCompare, isExclusive: false); + break; + case Comparison.LessThan: + ApplyMaximum(model, propertyInfo, validator.ValueToCompare, isExclusive: true); + break; + case Comparison.LessThanOrEqual: + ApplyMaximum(model, propertyInfo, validator.ValueToCompare, isExclusive: false); + break; + } + } + + protected virtual void ApplyBetween(PropertyApiDescriptionModel model, PropertyInfo propertyInfo, IBetweenValidator validator) + { + var from = GetNumericBound(propertyInfo, validator.From); + var to = GetNumericBound(propertyInfo, validator.To); + + // A between rule can carry its own comparer, which the descriptor does not expose. An + // interval that reads as empty in the natural order is what one looks like from here, + // and publishing its bounds would say the opposite of what the rule accepts. + if (from == null || to == null || !TryCompareBounds(from, to, out var comparison) || comparison > 0) + { + return; + } + + var isExclusive = validator is not IInclusiveBetweenValidator; + + ApplyMinimum(model, propertyInfo, validator.From, isExclusive); + ApplyMaximum(model, propertyInfo, validator.To, isExclusive); + } + + protected virtual void ApplyMinimum(PropertyApiDescriptionModel model, PropertyInfo propertyInfo, object? value, bool isExclusive) + { + var bound = GetNumericBound(propertyInfo, value); + if (bound == null) + { + return; + } + + if (model.Minimum != null) + { + if (!TryCompareBounds(model.Minimum, bound, out var comparison)) + { + return; + } + + // The higher bound wins, and an exclusive one is the stricter when both sit on the + // same value. The winning bound is published the way it was written, so no value is + // lost on the way through a number type that can not hold it. + if (comparison > 0 || (comparison == 0 && model.MinimumIsExclusive == true)) + { + return; + } + } + + model.Minimum = bound; + model.MinimumIsExclusive = isExclusive; + } + + protected virtual void ApplyMaximum(PropertyApiDescriptionModel model, PropertyInfo propertyInfo, object? value, bool isExclusive) + { + var bound = GetNumericBound(propertyInfo, value); + if (bound == null) + { + return; + } + + if (model.Maximum != null) + { + if (!TryCompareBounds(model.Maximum, bound, out var comparison)) + { + return; + } + + if (comparison < 0 || (comparison == 0 && model.MaximumIsExclusive == true)) + { + return; + } + } + + model.Maximum = bound; + model.MaximumIsExclusive = isExclusive; + } + + protected virtual string? GetNumericBound(PropertyInfo propertyInfo, object? value) + { + // Minimum and Maximum are numeric bounds. A comparison on another type, the ordinal + // comparison of two strings for example, means something else and can not go there. + // A comparison against another property has no value to publish either. + if (value == null || !NumericTypes.Contains(TypeHelper.StripNullable(propertyInfo.PropertyType))) + { + return null; + } + + var bound = Convert.ToString(value, CultureInfo.InvariantCulture); + return bound.IsNullOrWhiteSpace() || !double.TryParse(bound, NumberStyles.Float, CultureInfo.InvariantCulture, out _) + ? null + : bound; + } + + protected virtual bool TryCompareBounds(string left, string right, out int comparison) + { + // Decimal is exact for every integral type and for decimal itself, which double is not + // above its 53 bits of mantissa. Double only comes in for the magnitudes decimal can + // not hold, where its precision is the best there is anyway. + if (TryParseExactly(left, out var leftValue) && TryParseExactly(right, out var rightValue)) + { + comparison = leftValue.CompareTo(rightValue); + return true; + } + + if (double.TryParse(left, NumberStyles.Float, CultureInfo.InvariantCulture, out var leftDouble) && + double.TryParse(right, NumberStyles.Float, CultureInfo.InvariantCulture, out var rightDouble)) + { + comparison = leftDouble.CompareTo(rightDouble); + return true; + } + + comparison = 0; + return false; + } + + protected virtual bool TryParseExactly(string value, out decimal number) + { + if (!decimal.TryParse(value, NumberStyles.Float, CultureInfo.InvariantCulture, out number)) + { + return false; + } + + // A magnitude below the decimal range collapses to a zero, which would compare wrong. + return number != decimal.Zero || !value.Any(c => c is > '0' and <= '9'); + } +} diff --git a/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/IPropertyApiDescriptionModelContributor.cs b/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/IPropertyApiDescriptionModelContributor.cs new file mode 100644 index 0000000000..a802b56409 --- /dev/null +++ b/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/IPropertyApiDescriptionModelContributor.cs @@ -0,0 +1,8 @@ +using System.Threading.Tasks; + +namespace Volo.Abp.Http.Modeling; + +public interface IPropertyApiDescriptionModelContributor +{ + Task ContributeAsync(PropertyApiDescriptionModelContributionContext context); +} diff --git a/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/PropertyApiDescriptionModel.cs b/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/PropertyApiDescriptionModel.cs index d0bf430546..a8d3f3ae5f 100644 --- a/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/PropertyApiDescriptionModel.cs +++ b/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/PropertyApiDescriptionModel.cs @@ -1,5 +1,8 @@ using System; +using System.Collections.Generic; +using System.ComponentModel; using System.ComponentModel.DataAnnotations; +using System.Globalization; using System.Linq; using System.Reflection; using Volo.Abp.Http.ProxyScripting.Configuration; @@ -10,6 +13,23 @@ namespace Volo.Abp.Http.Modeling; [Serializable] public class PropertyApiDescriptionModel { + private static readonly HashSet NumericTypes = new HashSet + { + typeof(byte), + typeof(sbyte), + typeof(short), + typeof(ushort), + typeof(int), + typeof(uint), + typeof(long), + typeof(ulong), + typeof(float), + typeof(double), + typeof(decimal), + typeof(IntPtr), + typeof(UIntPtr) + }; + public string Name { get; set; } = default!; public string? JsonName { get; set; } @@ -28,6 +48,10 @@ public class PropertyApiDescriptionModel public string? Maximum { get; set; } + public bool? MinimumIsExclusive { get; set; } + + public bool? MaximumIsExclusive { get; set; } + public string? Regex { get; set; } public bool IsNullable { get; set; } @@ -41,6 +65,7 @@ public class PropertyApiDescriptionModel public static PropertyApiDescriptionModel Create(PropertyInfo propertyInfo) { var customAttributes = propertyInfo.GetCustomAttributes(true); + var rangeAttribute = customAttributes.OfType().FirstOrDefault(); return new PropertyApiDescriptionModel { Name = propertyInfo.Name, @@ -49,11 +74,95 @@ public class PropertyApiDescriptionModel TypeSimple = ApiTypeNameHelper.GetSimpleTypeName(propertyInfo.PropertyType), IsRequired = customAttributes.OfType().Any() || propertyInfo.GetCustomAttributesData().Any(attr => attr.AttributeType.Name == "RequiredMemberAttribute"), IsNullable = ReflectionHelper.IsNullable(propertyInfo), - Minimum = customAttributes.OfType().Select(x => x.Minimum).FirstOrDefault()?.ToString(), - Maximum = customAttributes.OfType().Select(x => x.Maximum).FirstOrDefault()?.ToString(), + Minimum = GetRangeBound(rangeAttribute, rangeAttribute?.Minimum), + Maximum = GetRangeBound(rangeAttribute, rangeAttribute?.Maximum), + MinimumIsExclusive = GetMinimumIsExclusive(rangeAttribute), + MaximumIsExclusive = GetMaximumIsExclusive(rangeAttribute), MinLength = customAttributes.OfType().FirstOrDefault()?.Length ?? customAttributes.OfType().FirstOrDefault()?.MinimumLength, MaxLength = customAttributes.OfType().FirstOrDefault()?.Length ?? customAttributes.OfType().FirstOrDefault()?.MaximumLength, Regex= customAttributes.OfType().Select(x => x.Pattern).FirstOrDefault() }; } + + private static string? GetRangeBound(RangeAttribute? rangeAttribute, object? bound) + { + if (rangeAttribute == null || bound == null) + { + return null; + } + + // The Range(Type, string, string) constructor keeps its limits as strings until the + // first validation. Converting one the way the attribute converts it reports the value + // the attribute validates against, which is not always the value that was written down. + // The attribute reads its limits in the culture of the request unless it opts into the + // invariant one, so only that opt-in makes the reported limit stable across requests. + if (bound is string text) + { + if (!NumericTypes.Contains(rangeAttribute.OperandType)) + { + return text; + } + + var converted = ConvertRangeLimitOrNull(text, rangeAttribute); + return converted != null + ? Convert.ToString(converted, CultureInfo.InvariantCulture) + : text; + } + + return Convert.ToString(bound, CultureInfo.InvariantCulture); + } + + private static object? ConvertRangeLimitOrNull(string text, RangeAttribute rangeAttribute) + { + try + { + return TypeDescriptor + .GetConverter(rangeAttribute.OperandType) + .ConvertFromString(null, GetRangeLimitCulture(rangeAttribute), text); + } + catch (Exception) + { + // A limit that does not convert is reported the way it was written. The attribute + // throws on it during the first validation, and failing the whole api definition + // over one declaration would hide every other type. + return null; + } + } + + private static CultureInfo GetRangeLimitCulture(RangeAttribute rangeAttribute) + { +#if NET8_0_OR_GREATER + return rangeAttribute.ParseLimitsInInvariantCulture ? CultureInfo.InvariantCulture : CultureInfo.CurrentCulture; +#else + return CultureInfo.CurrentCulture; +#endif + } + + private static bool? GetMinimumIsExclusive(RangeAttribute? rangeAttribute) + { + if (rangeAttribute == null) + { + return null; + } + +#if NET8_0_OR_GREATER + return rangeAttribute.MinimumIsExclusive; +#else + return false; +#endif + } + + private static bool? GetMaximumIsExclusive(RangeAttribute? rangeAttribute) + { + if (rangeAttribute == null) + { + return null; + } + +#if NET8_0_OR_GREATER + return rangeAttribute.MaximumIsExclusive; +#else + return false; +#endif + } } diff --git a/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/PropertyApiDescriptionModelContributionContext.cs b/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/PropertyApiDescriptionModelContributionContext.cs new file mode 100644 index 0000000000..d4acf2c0b4 --- /dev/null +++ b/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/PropertyApiDescriptionModelContributionContext.cs @@ -0,0 +1,27 @@ +using System; +using System.Reflection; +using JetBrains.Annotations; + +namespace Volo.Abp.Http.Modeling; + +public class PropertyApiDescriptionModelContributionContext +{ + [NotNull] + public PropertyApiDescriptionModel Model { get; } + + [NotNull] + public PropertyInfo PropertyInfo { get; } + + [NotNull] + public Type DeclaringType { get; } + + public PropertyApiDescriptionModelContributionContext( + [NotNull] PropertyApiDescriptionModel model, + [NotNull] PropertyInfo propertyInfo, + [NotNull] Type declaringType) + { + Model = Check.NotNull(model, nameof(model)); + PropertyInfo = Check.NotNull(propertyInfo, nameof(propertyInfo)); + DeclaringType = Check.NotNull(declaringType, nameof(declaringType)); + } +} diff --git a/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/TypeApiDescriptionModel.cs b/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/TypeApiDescriptionModel.cs index 703c5a8583..20908f8a04 100644 --- a/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/TypeApiDescriptionModel.cs +++ b/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/TypeApiDescriptionModel.cs @@ -8,6 +8,8 @@ namespace Volo.Abp.Http.Modeling; [Serializable] public class TypeApiDescriptionModel { + public string? AssemblyName { get; set; } + public string? BaseType { get; set; } public bool IsEnum { get; set; } @@ -43,6 +45,7 @@ public class TypeApiDescriptionModel var typeModel = new TypeApiDescriptionModel { + AssemblyName = type.Assembly.GetName().Name, IsEnum = type.IsEnum, BaseType = baseType != null ? TypeHelper.GetFullNameHandlingNullableAndGenerics(baseType) : null }; diff --git a/framework/src/Volo.Abp.Ldap.Abstractions/Volo/Abp/Ldap/Localization/ko.json b/framework/src/Volo.Abp.Ldap.Abstractions/Volo/Abp/Ldap/Localization/ko.json new file mode 100644 index 0000000000..947eef8900 --- /dev/null +++ b/framework/src/Volo.Abp.Ldap.Abstractions/Volo/Abp/Ldap/Localization/ko.json @@ -0,0 +1,19 @@ +{ + "culture": "ko", + "texts": { + "DisplayName:Abp.Ldap.Ldaps": "SSL을 통한 LDAP", + "Description:Abp.Ldap.Ldaps": "SSL을 통한 LDAP", + "DisplayName:Abp.Ldap.ServerHost": "서버 호스트", + "Description:Abp.Ldap.ServerHost": "서버 호스트", + "DisplayName:Abp.Ldap.ServerPort": "서버 포트", + "Description:Abp.Ldap.ServerPort": "서버 포트", + "DisplayName:Abp.Ldap.BaseDc": "기본 도메인 구성 요소", + "Description:Abp.Ldap.BaseDc": "기본 도메인 구성 요소", + "DisplayName:Abp.Ldap.Domain": "도메인", + "Description:Abp.Ldap.Domain": "도메인", + "DisplayName:Abp.Ldap.UserName": "사용자 이름", + "Description:Abp.Ldap.UserName": "사용자 이름", + "DisplayName:Abp.Ldap.Password": "비밀번호", + "Description:Abp.Ldap.Password": "비밀번호" + } +} diff --git a/framework/src/Volo.Abp.Localization/Volo/Abp/Localization/Resources/AbpLocalization/ko.json b/framework/src/Volo.Abp.Localization/Volo/Abp/Localization/Resources/AbpLocalization/ko.json new file mode 100644 index 0000000000..f373dfc4b5 --- /dev/null +++ b/framework/src/Volo.Abp.Localization/Volo/Abp/Localization/Resources/AbpLocalization/ko.json @@ -0,0 +1,7 @@ +{ + "culture": "ko", + "texts": { + "DisplayName:Abp.Localization.DefaultLanguage": "기본 언어", + "Description:Abp.Localization.DefaultLanguage": "애플리케이션의 기본 언어입니다." + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.MudBlazorUI/wwwroot/volo.abp.mudblazorui.css b/framework/src/Volo.Abp.MudBlazorUI/wwwroot/volo.abp.mudblazorui.css index 5fa2c86435..61601954a9 100644 --- a/framework/src/Volo.Abp.MudBlazorUI/wwwroot/volo.abp.mudblazorui.css +++ b/framework/src/Volo.Abp.MudBlazorUI/wwwroot/volo.abp.mudblazorui.css @@ -110,3 +110,24 @@ padding-inline-end: 16px; } + + +/* Password visibility toggle: MudBlazor renders the input end-adornment with a hard-coded + tabindex="-1", so a toggle placed there can never be reached by keyboard. The toggle is + rendered as a normal MudIconButton next to the field and pinned over the input row instead. + The offset is measured from the top of the control because the label sits above the input row + and validation text is rendered below it, so the control's own height is not a stable anchor. */ +.abp-password-field { + position: relative; +} + +.abp-password-field .abp-password-visibility-toggle { + position: absolute; + inset-inline-end: 0; + top: 38px; + transform: translateY(-50%); +} + +.abp-password-field .mud-input:not(.mud-select-input) .mud-input-slot.mud-input-root { + padding-inline-end: 40px !important; +} diff --git a/framework/src/Volo.Abp.MultiTenancy.Abstractions/Volo/Abp/MultiTenancy/Localization/ko.json b/framework/src/Volo.Abp.MultiTenancy.Abstractions/Volo/Abp/MultiTenancy/Localization/ko.json new file mode 100644 index 0000000000..aa003999a1 --- /dev/null +++ b/framework/src/Volo.Abp.MultiTenancy.Abstractions/Volo/Abp/MultiTenancy/Localization/ko.json @@ -0,0 +1,9 @@ +{ + "culture": "ko", + "texts": { + "TenantNotFoundMessage": "테넌트를 찾을 수 없습니다!", + "TenantNotFoundDetails": "다음 테넌트 ID 또는 이름에 해당하는 테넌트가 없습니다: {0}", + "TenantNotActiveMessage": "테넌트가 활성 상태가 아닙니다!", + "TenantNotActiveDetails": "다음 테넌트 ID 또는 이름에 해당하는 테넌트가 활성 상태가 아닙니다: {0}" + } +} diff --git a/framework/src/Volo.Abp.ObjectMapping/Volo/Abp/ObjectMapping/AbpObjectMappingModule.cs b/framework/src/Volo.Abp.ObjectMapping/Volo/Abp/ObjectMapping/AbpObjectMappingModule.cs index e572d6e155..2f1b8830ac 100644 --- a/framework/src/Volo.Abp.ObjectMapping/Volo/Abp/ObjectMapping/AbpObjectMappingModule.cs +++ b/framework/src/Volo.Abp.ObjectMapping/Volo/Abp/ObjectMapping/AbpObjectMappingModule.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.DependencyInjection; +using System.Collections.Generic; +using Microsoft.Extensions.DependencyInjection; using Volo.Abp.DependencyInjection; using Volo.Abp.Modularity; using Volo.Abp.Reflection; @@ -18,6 +19,14 @@ public class AbpObjectMappingModule : AbpModule typeof(IObjectMapper<,>) ).ConvertAll(t => new ServiceIdentifier(t)) ); + + //Register types for IQueryProjector if implements + foreach (var serviceType in ReflectionHelper.GetImplementedGenericTypes( + onServiceExposingContext.ImplementationType, + typeof(IQueryProjector<,>))) + { + onServiceExposingContext.ExposedTypes.AddIfNotContains(new ServiceIdentifier(serviceType)); + } }); } diff --git a/framework/src/Volo.Abp.ObjectMapping/Volo/Abp/ObjectMapping/IQueryProjector.cs b/framework/src/Volo.Abp.ObjectMapping/Volo/Abp/ObjectMapping/IQueryProjector.cs new file mode 100644 index 0000000000..89652e5f40 --- /dev/null +++ b/framework/src/Volo.Abp.ObjectMapping/Volo/Abp/ObjectMapping/IQueryProjector.cs @@ -0,0 +1,24 @@ +using System.Linq; +using Volo.Abp.DependencyInjection; + +namespace Volo.Abp.ObjectMapping; + +/// +/// Maps a query to another. +/// Implement this interface to project a query on the data store side, instead of loading the +/// source objects into the memory and mapping them one by one. +/// Implement it once for a source and destination pair. Use the ReplaceServices option of the +/// DependencyAttribute to replace an existing implementation. +/// +/// Type of the source objects +/// Type of the destination objects +public interface IQueryProjector : ITransientDependency +{ + /// + /// Projects the given query. The returned query must be built on top of it and must keep its order, + /// with a single destination object for each source object, using expressions the query provider can + /// translate. The caller may have already sorted, paged or counted the source query. + /// + /// The query to project + IQueryable ProjectTo(IQueryable source); +} diff --git a/framework/src/Volo.Abp.Timing/Volo/Abp/Timing/Localization/ko.json b/framework/src/Volo.Abp.Timing/Volo/Abp/Timing/Localization/ko.json new file mode 100644 index 0000000000..b0bfb72be9 --- /dev/null +++ b/framework/src/Volo.Abp.Timing/Volo/Abp/Timing/Localization/ko.json @@ -0,0 +1,7 @@ +{ + "culture": "ko", + "texts": { + "DisplayName:Abp.Timing.Timezone": "시간대", + "Description:Abp.Timing.Timezone": "애플리케이션 시간대" + } +} diff --git a/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/Localization/Resource/ko.json b/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/Localization/Resource/ko.json new file mode 100644 index 0000000000..a3b9b1296e --- /dev/null +++ b/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/Localization/Resource/ko.json @@ -0,0 +1,6 @@ +{ + "culture": "ko", + "texts": { + "Menu:Administration": "관리" + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/ar.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/ar.json index eb32a44fa2..8d5370f95e 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/ar.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/ar.json @@ -62,6 +62,7 @@ "Theme": "سمة", "NotAssigned": "غيرمعتمد", "EntityActionsDisabledTooltip": "ليس لديك إذن لتنفيذ أي إجراء.", - "ResourcePermissions": "أذونات" + "ResourcePermissions": "أذونات", + "ShowPassword": "عرض كلمة المرور" } } diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/cs.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/cs.json index 27a174cb49..5d50dc3163 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/cs.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/cs.json @@ -62,6 +62,7 @@ "Theme": "Téma", "NotAssigned": "Nepřiřazena", "EntityActionsDisabledTooltip": "Nemáte oprávnění provést žádnou akci.", - "ResourcePermissions": "Oprávnění" + "ResourcePermissions": "Oprávnění", + "ShowPassword": "Zobrazit heslo" } } diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/de.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/de.json index 869d049be1..e2e4c9a47c 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/de.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/de.json @@ -62,6 +62,7 @@ "Theme": "Thema", "NotAssigned": "Nicht zugeordnet", "EntityActionsDisabledTooltip": "Sie haben keine Berechtigung, Aktionen auszuführen.", - "ResourcePermissions": "Berechtigungen" + "ResourcePermissions": "Berechtigungen", + "ShowPassword": "Passwort anzeigen" } } diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/el.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/el.json index 8c2dc2be1d..a930666e39 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/el.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/el.json @@ -57,5 +57,6 @@ "Apply": "Ισχύουν", "EntityActionsDisabledTooltip": "Δεν έχετε δικαίωμα να εκτελέσετε καμία ενέργεια.", "ResourcePermissions": "Δικαιώματα", + "ShowPassword": "Εμφάνιση κωδικού πρόσβασης" } } diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/en-GB.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/en-GB.json index ce9d962d5e..f1a2bf02c5 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/en-GB.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/en-GB.json @@ -57,6 +57,7 @@ "Today": "Today", "Apply": "Apply", "EntityActionsDisabledTooltip": "You do not have permission to perform any action.", - "ResourcePermissions": "Permissions" + "ResourcePermissions": "Permissions", + "ShowPassword": "Show password" } } diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/en.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/en.json index f328765a39..0bf0a49a17 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/en.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/en.json @@ -62,6 +62,7 @@ "Theme": "Theme", "NotAssigned": "Not Assigned", "EntityActionsDisabledTooltip": "You do not have permission to perform any action.", - "ResourcePermissions": "Permissions" + "ResourcePermissions": "Permissions", + "ShowPassword": "Show password" } } diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/es.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/es.json index 9d341cb88f..fd8a9006ea 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/es.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/es.json @@ -62,6 +62,7 @@ "Theme": "Tema", "NotAssigned": "No asignado", "EntityActionsDisabledTooltip": "No tienes permisos para realizar ninguna acción.", - "ResourcePermissions": "Permisos" + "ResourcePermissions": "Permisos", + "ShowPassword": "Mostrar contraseña" } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/fa.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/fa.json index 5862eab90e..07ca9e5f9b 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/fa.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/fa.json @@ -56,6 +56,7 @@ "Today": "امروز", "Apply": "درخواست دادن", "EntityActionsDisabledTooltip": "شما دسترسی به انجام هر گونه عملیات ندارید.", - "ResourcePermissions": "مجوزها" + "ResourcePermissions": "مجوزها", + "ShowPassword": "نمایش رمز عبور" } } diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/fi.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/fi.json index 51e356559b..bc7ed9c5a2 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/fi.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/fi.json @@ -62,6 +62,7 @@ "Theme": "Teema", "NotAssigned": "Ei määritetty", "EntityActionsDisabledTooltip": "Sinulla ei ole oikeutta suorittaa mitään toimintoa.", - "ResourcePermissions": "Käyttöoikeudet" + "ResourcePermissions": "Käyttöoikeudet", + "ShowPassword": "Näytä salasana" } } diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/fr.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/fr.json index 79a40c57f9..0098158a0a 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/fr.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/fr.json @@ -62,6 +62,7 @@ "Theme": "Thème", "NotAssigned": "Non attribué", "EntityActionsDisabledTooltip": "Vous n'avez pas les permissions pour effectuer une action.", - "ResourcePermissions": "Autorisations" + "ResourcePermissions": "Autorisations", + "ShowPassword": "Afficher le mot de passe" } } diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/hi.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/hi.json index 10c1e426c1..a0c0a7f233 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/hi.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/hi.json @@ -62,6 +62,7 @@ "Theme": "विषय", "NotAssigned": "सौंपा नहीं गया है", "EntityActionsDisabledTooltip": "आपके पास कोई कार्रवाई नहीं है जो करने के लिए है।", - "ResourcePermissions": "अनुमतियाँ" + "ResourcePermissions": "अनुमतियाँ", + "ShowPassword": "पासवर्ड दिखाएं" } } diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/hr.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/hr.json index c36751828c..ea35dfa8ec 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/hr.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/hr.json @@ -62,6 +62,7 @@ "Theme": "Tema", "NotAssigned": "Nije dodijeljeno", "EntityActionsDisabledTooltip": "Nemate dozvolu za izvođenje bilo kakve akcije.", - "ResourcePermissions": "Dozvole" + "ResourcePermissions": "Dozvole", + "ShowPassword": "Pokaži lozinku" } } diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/hu.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/hu.json index e162a2c6c8..cdc71838f5 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/hu.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/hu.json @@ -62,6 +62,7 @@ "Theme": "Téma", "NotAssigned": "Nem kijelölt", "EntityActionsDisabledTooltip": "Nincs jogosultsága bármely művelethez.", - "ResourcePermissions": "Engedélyek" + "ResourcePermissions": "Engedélyek", + "ShowPassword": "Jelszó megjelenítése" } } diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/is.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/is.json index 3d88d70d97..df5123de9e 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/is.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/is.json @@ -62,6 +62,7 @@ "Theme": "Þema", "NotAssigned": "Ekki skráður", "EntityActionsDisabledTooltip": "Þú hefur ekki aðgang að þessum aðgerðum.", - "ResourcePermissions": "Aðgangsheimildir" + "ResourcePermissions": "Aðgangsheimildir", + "ShowPassword": "Sýna lykilorð" } } diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/it.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/it.json index 9bfffe181e..d866284043 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/it.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/it.json @@ -62,6 +62,7 @@ "Theme": "Tema", "NotAssigned": "Non assegnato", "EntityActionsDisabledTooltip": "Non hai i permessi per eseguire alcuna azione.", - "ResourcePermissions": "Autorizzazioni" + "ResourcePermissions": "Autorizzazioni", + "ShowPassword": "Mostra password" } } diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/ko.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/ko.json new file mode 100644 index 0000000000..0be3c1219a --- /dev/null +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/ko.json @@ -0,0 +1,68 @@ +{ + "culture": "ko", + "texts": { + "Languages": "언어", + "AreYouSure": "계속하시겠습니까?", + "Cancel": "취소", + "Clear": "지우기", + "Yes": "예", + "No": "아니요", + "Ok": "확인", + "Close": "닫기", + "Save": "저장", + "SavingWithThreeDot": "저장 중...", + "Actions": "작업", + "Delete": "삭제", + "CreatedSuccessfully": "생성되었습니다.", + "SavedSuccessfully": "저장되었습니다.", + "DeletedSuccessfully": "삭제되었습니다.", + "Edit": "편집", + "Refresh": "새로 고침", + "Language": "언어", + "LoadMore": "더 보기", + "ProcessingWithThreeDot": "처리 중...", + "LoadingWithThreeDot": "불러오는 중...", + "Welcome": "환영합니다.", + "Login": "로그인", + "Register": "회원가입", + "Logout": "로그아웃", + "Submit": "제출", + "Back": "뒤로", + "PagerSearch": "검색", + "PagerNext": "다음", + "PagerPrevious": "이전", + "PagerFirst": "처음", + "PagerLast": "마지막", + "PagerInfo": "총 _TOTAL_개 항목 중 _START_~_END_개를 표시합니다.", + "PagerInfo{0}{1}{2}": "총 {2}개 항목 중 {0}~{1}개를 표시합니다.", + "PagerInfoEmpty": "총 0개 항목 중 0~0개를 표시합니다.", + "PagerInfoFiltered": "(총 _MAX_개 항목에서 필터링됨)", + "NoDataAvailableInDatatable": "사용 가능한 데이터가 없습니다.", + "ErrorLoadingDatatable": "요청 중 오류가 발생했습니다. 자세한 내용은 메시지를 확인하십시오.", + "Total": "전체", + "Selected": "선택됨", + "PagerShowMenuEntries": "_MENU_개 항목 표시", + "DatatableActionDropdownDefaultText": "작업", + "ChangePassword": "비밀번호 변경", + "PersonalInfo": "내 프로필", + "AreYouSureYouWantToCancelEditingWarningMessage": "저장하지 않은 변경 사항이 있습니다.", + "GoHomePage": "홈페이지로 이동", + "GoBack": "뒤로 이동", + "Search": "검색", + "ItemWillBeDeletedMessageWithFormat": "{0}이(가) 삭제됩니다!", + "ItemWillBeDeletedMessage": "이 항목이 삭제됩니다!", + "ManageYourAccount": "계정 관리", + "OthersGroup": "기타", + "Today": "오늘", + "Apply": "적용", + "InternetConnectionInfo": "현재 인터넷에 연결되어 있지 않아 작업을 수행할 수 없습니다.", + "CopiedToTheClipboard": "클립보드에 복사되었습니다.", + "AddNew": "새로 추가", + "ProfilePicture": "프로필 사진", + "Theme": "테마", + "NotAssigned": "할당되지 않음", + "EntityActionsDisabledTooltip": "작업을 수행할 권한이 없습니다.", + "ResourcePermissions": "권한", + "ShowPassword": "비밀번호 표시" + } +} diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/nl.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/nl.json index 51ab0bcd31..22366cf991 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/nl.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/nl.json @@ -62,6 +62,7 @@ "Theme": "Thema", "NotAssigned": "Niet toegekend", "EntityActionsDisabledTooltip": "U hebt geen toegang tot deze acties.", - "ResourcePermissions": "Machtigingen" + "ResourcePermissions": "Machtigingen", + "ShowPassword": "Wachtwoord tonen" } } diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/pl-PL.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/pl-PL.json index 20b4daf7f0..be79d9849c 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/pl-PL.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/pl-PL.json @@ -62,6 +62,7 @@ "Theme": "Temat", "NotAssigned": "Nie przypisano", "EntityActionsDisabledTooltip": "Nie masz uprawnień do wykonania żadnej akcji.", - "ResourcePermissions": "Uprawnienia" + "ResourcePermissions": "Uprawnienia", + "ShowPassword": "Pokaż hasło" } } diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/pt-BR.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/pt-BR.json index 9764d99fe6..f6d66e07c3 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/pt-BR.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/pt-BR.json @@ -62,6 +62,7 @@ "Theme": "Tema", "NotAssigned": "Não atribuído", "EntityActionsDisabledTooltip": "Você não tem permissão para executar qualquer ação.", - "ResourcePermissions": "Permissões" + "ResourcePermissions": "Permissões", + "ShowPassword": "Mostrar senha" } } diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/ro-RO.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/ro-RO.json index 6b7367994c..f70b0f4a6b 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/ro-RO.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/ro-RO.json @@ -62,6 +62,7 @@ "Theme": "Temă", "NotAssigned": "Nealocat", "EntityActionsDisabledTooltip": "Nu aveți permisiune să efectuați nicio acțiune.", - "ResourcePermissions": "Permisiuni" + "ResourcePermissions": "Permisiuni", + "ShowPassword": "Afișează parola" } } diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/ru.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/ru.json index d4f4acf5d6..baaf43bcb8 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/ru.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/ru.json @@ -62,6 +62,7 @@ "Theme": "Тема", "NotAssigned": "Не назначен", "EntityActionsDisabledTooltip": "У вас нет прав на выполнение каких-либо действий.", - "ResourcePermissions": "Разрешения" + "ResourcePermissions": "Разрешения", + "ShowPassword": "Показать пароль" } } diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/sk.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/sk.json index 59d8aecef4..1e6c09fd51 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/sk.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/sk.json @@ -62,6 +62,7 @@ "Theme": "Téma", "NotAssigned": "Nepridelené", "EntityActionsDisabledTooltip": "Nemáte oprávnenie vykonávať žiadnu akciu.", - "ResourcePermissions": "Oprávnenia" + "ResourcePermissions": "Oprávnenia", + "ShowPassword": "Zobraziť heslo" } } diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/sl.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/sl.json index 89f2691a11..3be6d1d83c 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/sl.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/sl.json @@ -62,6 +62,7 @@ "Theme": "Tema", "NotAssigned": "Ni dodeljena", "EntityActionsDisabledTooltip": "Nimate pravic za izvajanje kakršne koli dejanje.", - "ResourcePermissions": "Dovoljenja" + "ResourcePermissions": "Dovoljenja", + "ShowPassword": "Pokaži geslo" } } diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/sv.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/sv.json index fe4b692cdf..b44d00d22f 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/sv.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/sv.json @@ -61,6 +61,7 @@ "Theme": "Tema", "NotAssigned": "Ej tilldelad", "EntityActionsDisabledTooltip": "Du har inte tillgång till dessa åtgärder.", - "ResourcePermissions": "Behörigheter" + "ResourcePermissions": "Behörigheter", + "ShowPassword": "Visa lösenord" } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/tr.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/tr.json index 73a4bb5cb4..a998d72c41 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/tr.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/tr.json @@ -62,6 +62,7 @@ "Theme": "Tema", "NotAssigned": "Atanmadı", "EntityActionsDisabledTooltip": "Bu işlemi gerçekleştirmek için yeterli yetkiniz yok.", - "ResourcePermissions": "İzinler" + "ResourcePermissions": "İzinler", + "ShowPassword": "Şifreyi göster" } } diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/vi.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/vi.json index 015ed883d3..40ba15446d 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/vi.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/vi.json @@ -62,6 +62,7 @@ "Theme": "chủ đề", "NotAssigned": "Không được chỉ định", "EntityActionsDisabledTooltip": "Bạn không có quyền thực hiện bất kỳ hành động nào.", - "ResourcePermissions": "Quyền" + "ResourcePermissions": "Quyền", + "ShowPassword": "Hiện mật khẩu" } } diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/zh-Hans.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/zh-Hans.json index b0759d7da9..bf0481cfc8 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/zh-Hans.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/zh-Hans.json @@ -62,6 +62,7 @@ "Theme": "主题", "NotAssigned": "未分配", "EntityActionsDisabledTooltip": "您没有权限执行任何操作。", - "ResourcePermissions": "权限" + "ResourcePermissions": "权限", + "ShowPassword": "显示密码" } } diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/zh-Hant.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/zh-Hant.json index e35bae3610..c534300915 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/zh-Hant.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/zh-Hant.json @@ -62,6 +62,7 @@ "Theme": "主題", "NotAssigned": "未分配", "EntityActionsDisabledTooltip": "您沒有權限執行任何操作。", - "ResourcePermissions": "權限" + "ResourcePermissions": "權限", + "ShowPassword": "顯示密碼" } } diff --git a/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/ko.json b/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/ko.json new file mode 100644 index 0000000000..9f22a0965e --- /dev/null +++ b/framework/src/Volo.Abp.Validation/Volo/Abp/Validation/Localization/ko.json @@ -0,0 +1,39 @@ +{ + "culture": "ko", + "texts": { + "'{0}' and '{1}' do not match.": "'{0}'와(과) '{1}'이(가) 일치하지 않습니다.", + "The {0} field is not a valid credit card number.": "{0} 필드는 유효한 신용카드 번호가 아닙니다.", + "{0} is not valid.": "{0}은(는) 유효하지 않습니다.", + "The {0} field is not a valid e-mail address.": "{0} 필드는 유효한 이메일 주소가 아닙니다.", + "The {0} field only accepts files with the following extensions: {1}": "{0} 필드는 다음 확장자를 가진 파일만 허용합니다: {1}", + "The field {0} must be a string or array type with a maximum length of '{1}'.": "{0} 필드는 최대 길이가 '{1}'인 문자열 또는 배열 형식이어야 합니다.", + "The field {0} must be a string or array type with a minimum length of '{1}'.": "{0} 필드는 최소 길이가 '{1}'인 문자열 또는 배열 형식이어야 합니다.", + "The {0} field is not a valid phone number.": "{0} 필드는 유효한 전화번호가 아닙니다.", + "The field {0} must be between {1} and {2}.": "{0} 필드는 {1}에서 {2} 사이여야 합니다.", + "The field {0} must match the regular expression '{1}'.": "{0} 필드는 정규식 '{1}'과(와) 일치해야 합니다.", + "The {0} field is required.": "{0} 필드는 필수입니다.", + "The field {0} must be a string with a maximum length of {1}.": "{0} 필드는 최대 길이가 {1}인 문자열이어야 합니다.", + "The field {0} must be a string with a minimum length of {2} and a maximum length of {1}.": "{0} 필드는 최소 길이가 {2}, 최대 길이가 {1}인 문자열이어야 합니다.", + "The {0} field is not a valid fully-qualified http, https, or ftp URL.": "{0} 필드는 유효한 완전한 형식의 http, https 또는 ftp URL이 아닙니다.", + "The field {0} is invalid.": "{0} 필드가 유효하지 않습니다.", + "The value '{0}' is invalid.": "값 '{0}'은(는) 유효하지 않습니다.", + "The field {0} must be a number.": "{0} 필드는 숫자여야 합니다.", + "The field must be a number.": "이 필드는 숫자여야 합니다.", + "ThisFieldIsNotAValidCreditCardNumber.": "이 필드는 유효한 신용카드 번호가 아닙니다.", + "ThisFieldIsNotValid.": "이 필드는 유효하지 않습니다.", + "ThisFieldIsNotAValidEmailAddress.": "이 필드는 유효한 이메일 주소가 아닙니다.", + "ThisFieldOnlyAcceptsFilesWithTheFollowingExtensions:{0}": "이 필드는 다음 확장자를 가진 파일만 허용합니다: {0}", + "ThisFieldMustBeAStringOrArrayTypeWithAMaximumLengthOf{0}": "이 필드는 최대 '{0}'자여야 합니다.", + "ThisFieldMustBeAStringOrArrayTypeWithAMinimumLengthOf{0}": "이 필드는 최소 '{0}'자여야 합니다.", + "ThisFieldIsNotAValidPhoneNumber.": "이 필드는 유효한 전화번호가 아닙니다.", + "ThisFieldMustBeBetween{0}And{1}": "이 필드는 {0}에서 {1} 사이여야 합니다.", + "ThisFieldMustBeGreaterThanOrEqual{0}": "이 필드는 {0} 이상이어야 합니다.", + "ThisFieldMustBeLessOrEqual{0}": "이 필드는 {0} 이하여야 합니다.", + "ThisFieldMustMatchTheRegularExpression{0}": "이 필드는 정규식 '{0}'과(와) 일치해야 합니다.", + "ThisFieldIsRequired.": "이 필드는 필수입니다.", + "ThisFieldMustBeAStringWithAMaximumLengthOf{0}": "이 필드는 최대 '{0}'자여야 합니다.", + "ThisFieldMustBeAStringWithAMinimumLengthOf{1}AndAMaximumLengthOf{0}": "이 필드는 최소 {1}자, 최대 {0}자여야 합니다.", + "ThisFieldIsNotAValidFullyQualifiedHttpHttpsOrFtpUrl": "이 필드는 유효한 완전한 형식의 http, https 또는 ftp URL이 아닙니다.", + "ThisFieldIsInvalid.": "이 필드는 유효하지 않습니다." + } +} diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo.Abp.AspNetCore.Mvc.Tests.csproj b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo.Abp.AspNetCore.Mvc.Tests.csproj index 496dba12ed..7eb833e09a 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo.Abp.AspNetCore.Mvc.Tests.csproj +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo.Abp.AspNetCore.Mvc.Tests.csproj @@ -27,7 +27,7 @@ - + diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs index 4339104b30..a8707a8c38 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs @@ -24,7 +24,7 @@ using Volo.Abp.TestApp; using Volo.Abp.TestApp.Application; using Volo.Abp.Threading; using Volo.Abp.Validation.Localization; -using Volo.Abp.FluentValidation; +using Volo.Abp.Http.FluentValidation; using Volo.Abp.VirtualFileSystem; namespace Volo.Abp.AspNetCore.Mvc; @@ -34,7 +34,7 @@ namespace Volo.Abp.AspNetCore.Mvc; typeof(AbpMemoryDbTestModule), typeof(AbpAspNetCoreMvcModule), typeof(AbpAutofacModule), - typeof(AbpFluentValidationModule) + typeof(AbpHttpFluentValidationModule) )] public class AbpAspNetCoreMvcTestModule : AbpModule { diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ApiExploring/AbpApiDefinitionController_Tests.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ApiExploring/AbpApiDefinitionController_Tests.cs index 5404555ffb..139f0df3e5 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ApiExploring/AbpApiDefinitionController_Tests.cs +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ApiExploring/AbpApiDefinitionController_Tests.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Threading.Tasks; using Shouldly; using Volo.Abp.Http.Modeling; +using Volo.Abp.TestApp.Application; using Xunit; namespace Volo.Abp.AspNetCore.Mvc.ApiExploring; @@ -23,6 +24,7 @@ public class AbpApiDefinitionController_Tests : AspNetCoreMvcTestBase var model = await GetResponseAsObjectAsync("/api/abp/api-definition?includeTypes=true"); model.ShouldNotBeNull(); model.Types.IsNullOrEmpty().ShouldBeFalse(); + model.Types.Values.ShouldAllBe(x => !string.IsNullOrWhiteSpace(x.AssemblyName)); } [Fact] @@ -75,6 +77,20 @@ public class AbpApiDefinitionController_Tests : AspNetCoreMvcTestBase action.AuthorizeDatas.ShouldContain(a => a.Policy == "TestPolicy2" && a.Roles == "Manager"); } + [Fact] + public async Task Should_Include_FluentValidation_Rules_In_Types() + { + var model = await GetResponseAsObjectAsync("/api/abp/api-definition?includeTypes=true"); + + var property = model.Types[typeof(FluentValidationTestInput).FullName!] + .Properties! + .Single(p => p.Name == nameof(FluentValidationTestInput.Name)); + + property.IsRequired.ShouldBeTrue(); + property.MinLength.ShouldBe(3); + property.MaxLength.ShouldBe(10); + } + private static ControllerApiDescriptionModel GetPeopleController(ApplicationApiDescriptionModel model) { return model.Modules.Values diff --git a/framework/test/Volo.Abp.BlobStoring.FileSystem.Tests/Volo/Abp/BlobStoring/FileSystem/FileSystemBlobEncryption_Tests.cs b/framework/test/Volo.Abp.BlobStoring.FileSystem.Tests/Volo/Abp/BlobStoring/FileSystem/FileSystemBlobEncryption_Tests.cs index 5c1bfba625..2f4139478f 100644 --- a/framework/test/Volo.Abp.BlobStoring.FileSystem.Tests/Volo/Abp/BlobStoring/FileSystem/FileSystemBlobEncryption_Tests.cs +++ b/framework/test/Volo.Abp.BlobStoring.FileSystem.Tests/Volo/Abp/BlobStoring/FileSystem/FileSystemBlobEncryption_Tests.cs @@ -344,6 +344,47 @@ public class FileSystemBlobEncryption_Tests : AbpBlobStoringFileSystemTestBase fileBytes.SequenceEqual(content).ShouldBeTrue(); } + [Fact] + public async Task Should_Cancel_A_Save_While_Waiting_Between_Retries() + { + using var source = new MemoryStream("content".GetBytes()); + var provider = new FaultingOpenFileSystemBlobProvider(_filePathCalculator, source); + using var cancellationTokenSource = new CancellationTokenSource(); + + var saveTask = provider.SaveAsync(new BlobProviderSaveArgs( + BlobContainerNameAttribute.GetContainerName(), + _configurationProvider.Get(), + "fs-retry-cancel-save", + source, + cancellationToken: cancellationTokenSource.Token)); + await cancellationTokenSource.CancelAsync(); + + await Should.ThrowAsync(async () => await saveTask); + + provider.OpenAttempts.ShouldBe(1); + } + + [Fact] + public async Task Should_Cancel_A_Get_While_Waiting_Between_Retries() + { + var blobName = "fs-retry-cancel-get"; + var filePath = GetFilePath(blobName); + Directory.CreateDirectory(Path.GetDirectoryName(filePath)!); + await File.WriteAllTextAsync(filePath, "content"); + using var fileLock = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.None); + using var cancellationTokenSource = new CancellationTokenSource(); + var provider = new FileSystemBlobProvider(_filePathCalculator); + + var getTask = provider.GetOrNullAsync(new BlobProviderGetArgs( + BlobContainerNameAttribute.GetContainerName(), + _configurationProvider.Get(), + blobName, + cancellationTokenSource.Token)); + await cancellationTokenSource.CancelAsync(); + + await Should.ThrowAsync(async () => await getTask); + } + [DisableConventionalRegistration] private sealed class FaultingOpenFileSystemBlobProvider : FileSystemBlobProvider { diff --git a/framework/test/Volo.Abp.Cli.Core.Tests/Volo/Abp/Cli/Http/CliHttpClientExtensions_Tests.cs b/framework/test/Volo.Abp.Cli.Core.Tests/Volo/Abp/Cli/Http/CliHttpClientExtensions_Tests.cs new file mode 100644 index 0000000000..20bc58e109 --- /dev/null +++ b/framework/test/Volo.Abp.Cli.Core.Tests/Volo/Abp/Cli/Http/CliHttpClientExtensions_Tests.cs @@ -0,0 +1,88 @@ +using System; +using System.Collections.Generic; +using System.Net; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; +using Shouldly; +using Xunit; + +namespace Volo.Abp.Cli.Http; + +public class CliHttpClientExtensions_Tests +{ + [Fact] + public async Task Should_Not_Enumerate_Delays_When_The_First_Request_Succeeds() + { + using var httpClient = new HttpClient( + new DelegateHttpMessageHandler(_ => new HttpResponseMessage(HttpStatusCode.OK))); + + using var response = await httpClient.GetHttpResponseMessageWithRetryAsync( + "https://abp.io", + sleepDurations: ThrowWhenEnumerated()); + + response.StatusCode.ShouldBe(HttpStatusCode.OK); + } + + [Fact] + public async Task Should_Enumerate_One_Delay_Per_Retry() + { + var requestCount = 0; + var enumeratedDelayCount = 0; + using var httpClient = new HttpClient( + new DelegateHttpMessageHandler(_ => new HttpResponseMessage( + ++requestCount < 3 ? HttpStatusCode.ServiceUnavailable : HttpStatusCode.OK))); + + using var response = await httpClient.GetHttpResponseMessageWithRetryAsync( + "https://abp.io", + sleepDurations: GetDelays()); + + response.StatusCode.ShouldBe(HttpStatusCode.OK); + requestCount.ShouldBe(3); + enumeratedDelayCount.ShouldBe(2); + + IEnumerable GetDelays() + { + for (var i = 0; i < 3; i++) + { + enumeratedDelayCount++; + yield return TimeSpan.Zero; + } + } + } + + [Fact] + public async Task Should_Cancel_While_Waiting_Between_Retries() + { + using var cancellationTokenSource = new CancellationTokenSource(); + using var httpClient = new HttpClient( + new DelegateHttpMessageHandler(_ => new HttpResponseMessage(HttpStatusCode.ServiceUnavailable))); + + var requestTask = httpClient.GetHttpResponseMessageWithRetryAsync( + "https://abp.io", + cancellationTokenSource.Token, + sleepDurations: new[] { TimeSpan.FromSeconds(1) }); + await cancellationTokenSource.CancelAsync(); + + await Should.ThrowAsync(async () => await requestTask); + } + + private static IEnumerable ThrowWhenEnumerated() + { + throw new InvalidOperationException("The delay sequence must remain untouched."); +#pragma warning disable CS0162 + yield break; +#pragma warning restore CS0162 + } + + private sealed class DelegateHttpMessageHandler( + Func responseFactory) : HttpMessageHandler + { + protected override Task SendAsync( + HttpRequestMessage request, + CancellationToken cancellationToken) + { + return Task.FromResult(responseFactory(request)); + } + } +} diff --git a/framework/test/Volo.Abp.Cli.Core.Tests/Volo/Abp/Cli/ServiceProxying/CSharp/CSharpServiceProxyGenerator_Tests.cs b/framework/test/Volo.Abp.Cli.Core.Tests/Volo/Abp/Cli/ServiceProxying/CSharp/CSharpServiceProxyGenerator_Tests.cs new file mode 100644 index 0000000000..ff091b5846 --- /dev/null +++ b/framework/test/Volo.Abp.Cli.Core.Tests/Volo/Abp/Cli/ServiceProxying/CSharp/CSharpServiceProxyGenerator_Tests.cs @@ -0,0 +1,858 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text.Json; +using System.Threading.Tasks; +using Shouldly; +using Volo.Abp.Http.Modeling; +using Volo.Abp.Json.SystemTextJson; +using Xunit; + +namespace Volo.Abp.Cli.ServiceProxying.CSharp; + +public class CSharpServiceProxyGenerator_Tests : IDisposable +{ + private const string OrderAppService = "MyCompany.Orders.Application.IOrderAppService"; + + private static readonly string[] DefaultClientAssemblyNames = + { + "Volo.Abp.Core", + "Volo.Abp.Ddd.Application.Contracts", + "Volo.Abp.Http", + "Volo.Abp.Http.Abstractions", + "Volo.Abp.MultiTenancy.Abstractions", + "Volo.Abp.ObjectExtending", + "Volo.Abp.Validation.Abstractions" + }; + + private readonly TestCSharpServiceProxyGenerator _generator = new(); + private readonly string _workDirectory; + + public CSharpServiceProxyGenerator_Tests() + { + _workDirectory = Path.Combine(Path.GetTempPath(), "abp-csharp-proxy-tests", Guid.NewGuid().ToString("N")); + Directory.CreateDirectory(_workDirectory); + File.WriteAllText(Path.Combine(_workDirectory, "Client.csproj"), ""); + WriteProjectAssets((".NETCoreApp,Version=v10.0", DefaultClientAssemblyNames)); + _generator.WorkDirectory = _workDirectory; + _generator.ProjectAssetsFilePath = Path.Combine(_workDirectory, "obj", "project.assets.json"); + } + + public void Dispose() + { + Directory.Delete(_workDirectory, true); + } + + [Fact] + public void Should_Generate_Types_Used_By_Service_Signatures_From_Any_Namespace() + { + var model = CreateModel( + CreateServiceController(OrderAppService, + CreateMethod("GetAsync", "MyCompany.Orders.OrderDto", "System.Guid"), + CreateMethod("GetListAsync", "Volo.Abp.Application.Dtos.PagedResultDto", "MyCompany.Orders.GetOrdersInput"), + CreateMethod("GetStatusesAsync", "[MyCompany.Shared.OrderStatus]"), + CreateMethod("GetCustomersAsync", "{System.String:MyCompany.Shared.CustomerDto}"))); + + _generator.GetTypes(model).ShouldBe(new[] + { + "MyCompany.Orders.GetOrdersInput", + "MyCompany.Orders.OrderDto", + "MyCompany.Orders.OrderLineDto", + "MyCompany.Shared.AddressDto", + "MyCompany.Shared.CustomerDto", + "MyCompany.Shared.OrderStatus" + }); + } + + [Fact] + public void Should_Generate_Types_Referenced_By_Base_Types_Properties_And_Generic_Arguments() + { + var model = CreateModel( + CreateServiceController(OrderAppService, + CreateMethod("GetAsync", "MyCompany.Orders.OrderDetailDto"))); + + _generator.GetTypes(model).ShouldBe(new[] + { + "MyCompany.Orders.OrderDetailDto", + "MyCompany.Orders.OrderDto", + "MyCompany.Orders.OrderLineDto", + "MyCompany.Shared.AddressDto", + "MyCompany.Shared.CustomerDto", + "MyCompany.Shared.OrderStatus", + "MyCompany.Shared.TagDto", + "MyCompany.Shared.Wrapper" + }); + } + + [Fact] + public void Should_Match_Generic_Types_By_Generic_Argument_Count() + { + var model = CreateModel( + CreateServiceController(OrderAppService, + CreateMethod("GetAsync", "MyCompany.Shared.Result,MyCompany.Shared.AddressDto>"))); + + _generator.GetTypes(model).ShouldBe(new[] + { + "MyCompany.Shared.AddressDto", + "MyCompany.Shared.Result", + "MyCompany.Shared.TagDto", + "MyCompany.Shared.Wrapper" + }); + } + + [Fact] + public void Should_Not_Generate_Types_That_Only_Share_The_Service_Namespace() + { + var model = CreateModel( + CreateServiceController(OrderAppService, + CreateMethod("GetStatusesAsync", "[MyCompany.Shared.OrderStatus]"))); + + var types = _generator.GetTypes(model); + + types.ShouldNotContain("MyCompany.Orders.Application.UnusedDto"); + types.ShouldBe(new[] { "MyCompany.Shared.OrderStatus" }); + } + + [Fact] + public void Should_Not_Generate_Types_Provided_By_The_Framework() + { + var model = CreateModel( + CreateServiceController(OrderAppService, + CreateMethod("GetSettingsAsync", "[Volo.Abp.NameValue]"), + CreateMethod("UploadAsync", "System.Void", "Volo.Abp.Content.IRemoteStreamContent"), + CreateMethod("GetValueTypeAsync", "Volo.Abp.Validation.StringValues.IStringValueType"), + CreateMethod("GetApiDefinitionAsync", "Volo.Abp.Http.Modeling.ApplicationApiDescriptionModel"), + CreateMethod("UploadFileAsync", "System.Void", "Microsoft.AspNetCore.Http.IFormFile"), + CreateMethod("GetExtensibleAsync", "Volo.Abp.ObjectExtending.ExtensibleObject"), + CreateMethod("GetListAsync", "Volo.Abp.Application.Dtos.ListResultDto"))); + + _generator.GetTypes(model).ShouldBeEmpty(); + } + + [Fact] + public async Task Should_Generate_Abp_Module_Contract_Types_But_Not_Framework_Types() + { + _generator.Model = CreateModel( + CreateServiceController(OrderAppService, + CreateMethod("GetUserAsync", "Volo.Abp.Users.UserData"), + CreateMethod("GetTenantAsync", "Volo.Abp.MultiTenancy.TenantConfiguration"), + CreateMethod("GetSettingsAsync", "Volo.Abp.NameValue"))); + + await _generator.GenerateProxyAsync(CreateArgs()); + + var userDataFile = GetProxyFilePath("Volo/Abp/Users/UserData.cs"); + File.Exists(userDataFile).ShouldBeTrue(); + (await File.ReadAllTextAsync(userDataFile)).ShouldContain("public class UserData"); + File.Exists(GetProxyFilePath("Volo/Abp/MultiTenancy/TenantConfiguration.cs")).ShouldBeFalse(); + File.Exists(GetProxyFilePath("Volo/Abp/NameValue.cs")).ShouldBeFalse(); + } + + [Fact] + public void Should_Generate_Types_Of_The_Targeted_Abp_Module() + { + var model = CreateModel( + CreateServiceController("Volo.Abp.Identity.Integration.IIdentityUserIntegrationService", + CreateMethod("SearchAsync", "Volo.Abp.Identity.UserLookupSearchInputDto"), + CreateMethod("GetUserAsync", "Volo.Abp.Users.UserData"), + CreateMethod("GetTenantAsync", "Volo.Abp.MultiTenancy.TenantConfiguration"))); + + _generator.GetTypes(model).ShouldBe(new[] + { + "Volo.Abp.Identity.UserLookupSearchInputDto", + "Volo.Abp.Users.UserData" + }); + } + + [Fact] + public void Should_Generate_Cross_Module_Contracts_Not_Provided_By_Client_Packages() + { + var model = CreateModel( + CreateServiceController("Volo.Abp.Account.IAccountAppService", + CreateMethod("RegisterAsync", "Volo.Abp.Identity.IdentityUserDto"), + CreateMethod("GetTenantAsync", "Volo.Abp.MultiTenancy.TenantConfiguration"))); + + _generator.GetTypes(model).ShouldBe(new[] + { + "Volo.Abp.Identity.IdentityUserDto" + }); + } + + [Fact] + public void Should_Not_Generate_Cross_Module_Contracts_Provided_By_All_Target_Frameworks() + { + WriteProjectAssets( + (".NETCoreApp,Version=v9.0", DefaultClientAssemblyNames.Append("Volo.Abp.Identity.Application.Contracts").ToArray()), + (".NETCoreApp,Version=v10.0", DefaultClientAssemblyNames.Append("Volo.Abp.Identity.Application.Contracts").ToArray())); + var model = CreateModel( + CreateServiceController("Volo.Abp.Account.IAccountAppService", + CreateMethod("RegisterAsync", "Volo.Abp.Identity.IdentityUserDto"))); + + _generator.GetTypes(model).ShouldBeEmpty(); + } + + [Fact] + public void Should_Generate_Contracts_Not_Provided_By_Every_Target_Framework() + { + WriteProjectAssets( + (".NETCoreApp,Version=v9.0", DefaultClientAssemblyNames.Append("Volo.Abp.Identity.Application.Contracts").ToArray()), + (".NETCoreApp,Version=v10.0", DefaultClientAssemblyNames)); + var model = CreateModel( + CreateServiceController("Volo.Abp.Account.IAccountAppService", + CreateMethod("RegisterAsync", "Volo.Abp.Identity.IdentityUserDto"))); + + _generator.GetTypes(model).ShouldBe(new[] + { + "Volo.Abp.Identity.IdentityUserDto" + }); + } + + [Fact] + public void Should_Use_Namespace_Fallback_When_Assembly_Names_Are_Missing() + { + var model = CreateModel( + CreateServiceController("Volo.Abp.Identity.Integration.IIdentityUserIntegrationService", + CreateMethod("SearchAsync", "Volo.Abp.Identity.UserLookupSearchInputDto"), + CreateMethod("GetUserAsync", "Volo.Abp.Users.UserData"), + CreateMethod("GetTenantAsync", "Volo.Abp.MultiTenancy.TenantConfiguration"))); + foreach (var type in model.Types.Values) + { + type.AssemblyName = null; + } + + _generator.GetTypes(model).ShouldBe(new[] + { + "Volo.Abp.Identity.UserLookupSearchInputDto", + "Volo.Abp.Users.UserData" + }); + } + + [Fact] + public void Should_Use_Namespace_Fallback_When_Project_Assets_Are_Missing() + { + File.Delete(Path.Combine(_workDirectory, "obj", "project.assets.json")); + var model = CreateModel( + CreateServiceController("Volo.Abp.Identity.Integration.IIdentityUserIntegrationService", + CreateMethod("SearchAsync", "Volo.Abp.Identity.UserLookupSearchInputDto"), + CreateMethod("GetUserAsync", "Volo.Abp.Users.UserData"), + CreateMethod("GetTenantAsync", "Volo.Abp.MultiTenancy.TenantConfiguration"))); + + _generator.GetTypes(model).ShouldBe(new[] + { + "Volo.Abp.Identity.UserLookupSearchInputDto", + "Volo.Abp.Users.UserData" + }); + } + + [Fact] + public void Should_Use_Namespace_Fallback_When_Project_Assets_Are_Invalid() + { + File.WriteAllText( + Path.Combine(_workDirectory, "obj", "project.assets.json"), + "{\"version\":3,\"targets\":null}"); + var model = CreateModel( + CreateServiceController("Volo.Abp.Identity.Integration.IIdentityUserIntegrationService", + CreateMethod("SearchAsync", "Volo.Abp.Identity.UserLookupSearchInputDto"), + CreateMethod("GetUserAsync", "Volo.Abp.Users.UserData"), + CreateMethod("GetTenantAsync", "Volo.Abp.MultiTenancy.TenantConfiguration"))); + + _generator.GetTypes(model).ShouldBe(new[] + { + "Volo.Abp.Identity.UserLookupSearchInputDto", + "Volo.Abp.Users.UserData" + }); + } + + [Fact] + public void Should_Use_Project_Assets_From_A_Custom_Path() + { + File.Delete(Path.Combine(_workDirectory, "obj", "project.assets.json")); + var customAssetsFilePath = Path.Combine(_workDirectory, "artifacts", "obj", "project.assets.json"); + File.WriteAllText( + Path.Combine(_workDirectory, "Directory.Build.props"), + "artifacts/obj/"); + WriteProjectAssets(customAssetsFilePath, + (".NETCoreApp,Version=v10.0", DefaultClientAssemblyNames)); + _generator.ProjectAssetsFilePath = null; + var model = CreateModel( + CreateServiceController("Volo.Abp.Account.IAccountAppService", + CreateMethod("RegisterAsync", "Volo.Abp.Identity.IdentityUserDto"))); + + _generator.GetTypes(model).ShouldBe(new[] { "Volo.Abp.Identity.IdentityUserDto" }); + } + + [Fact] + public async Task Should_Not_Read_Project_Assets_Without_Contracts() + { + _generator.Model = CreateModel( + CreateServiceController(OrderAppService, + CreateMethod("GetAsync", "MyCompany.Orders.OrderDto"))); + + await _generator.GenerateProxyAsync(CreateArgs(withoutContracts: true)); + + _generator.ProjectAssetsFilePathCallCount.ShouldBe(0); + } + + [Fact] + public void Should_Not_Generate_Types_Of_The_Abp_Framework_Module() + { + var model = CreateModuleModel("abp", + CreateServiceController("Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.IAbpApplicationConfigurationAppService", + CreateMethod("GetAsync", "Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ApplicationConfigurationDto"))); + AddType(model, "Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ApplicationConfigurationDto", null); + + _generator.GetTypes(model).ShouldBeEmpty(); + } + + [Fact] + public void Should_Not_Generate_Types_Of_Controllers_Without_A_Service_Interface() + { + var accountController = new ControllerApiDescriptionModel + { + ControllerName = "Account", + Type = "MyCompany.Orders.Web.AccountController", + Interfaces = new List(), + Actions = new Dictionary + { + ["LoginAsync"] = new() + { + Name = "LoginAsync", + ImplementFrom = "MyCompany.Orders.Web.AccountController", + ParametersOnMethod = new List(), + ReturnValue = new ReturnValueApiDescriptionModel { Type = "MyCompany.Orders.Web.LoginResult" } + } + } + }; + + var model = CreateModel( + accountController, + CreateServiceController(OrderAppService, + CreateMethod("GetStatusesAsync", "[MyCompany.Shared.OrderStatus]"))); + + _generator.GetTypes(model).ShouldBe(new[] { "MyCompany.Shared.OrderStatus" }); + } + + [Fact] + public async Task Should_Generate_Types_Used_By_Action_Parameters() + { + _generator.Model = CreateModel( + CreateServiceController(OrderAppService, + CreateMethod("Search", "System.Int32"))); + _generator.Model.Modules["orders"].Controllers.Values.Single().Actions["Search"].Parameters.Add( + new ParameterApiDescriptionModel + { + Name = "status", + NameOnMethod = "status", + Type = "MyCompany.Shared.OrderStatus" + }); + + await _generator.GenerateProxyAsync(CreateArgs()); + + File.Exists(GetProxyFilePath("MyCompany/Shared/OrderStatus.cs")).ShouldBeTrue(); + } + + [Fact] + public async Task Should_Generate_Generic_Type_Properties_With_Their_Own_Types() + { + _generator.Model = CreateModel( + CreateServiceController(OrderAppService, + CreateMethod("GetAsync", "MyCompany.Shared.Wrapper"))); + + await _generator.GenerateProxyAsync(CreateArgs()); + + var wrapper = await File.ReadAllTextAsync(GetProxyFilePath("MyCompany/Shared/Wrapper.cs")); + wrapper.ShouldContain("public class Wrapper"); + wrapper.ShouldContain("public T Value { get; set; }"); + wrapper.ShouldContain("public T[] Items { get; set; }"); + } + + [Fact] + public async Task Should_Generate_Same_Named_Generic_Types_Into_Separate_Files() + { + _generator.Model = CreateModel( + CreateServiceController(OrderAppService, + CreateMethod("GetAsync", "MyCompany.Shared.Result"), + CreateMethod("GetTagAsync", "MyCompany.Shared.Result"), + CreateMethod("GetTagAndAddressAsync", "MyCompany.Shared.Result"))); + + await _generator.GenerateProxyAsync(CreateArgs()); + + (await File.ReadAllTextAsync(GetProxyFilePath("MyCompany/Shared/Result.cs"))).ShouldContain($"public class Result{Environment.NewLine}"); + (await File.ReadAllTextAsync(GetProxyFilePath("MyCompany/Shared/Result{T}.cs"))).ShouldContain("public class Result"); + (await File.ReadAllTextAsync(GetProxyFilePath("MyCompany/Shared/Result{TItem,TError}.cs"))).ShouldContain("public class Result"); + } + + [Fact] + public async Task Should_Add_Usings_For_Generic_Types_From_Other_Namespaces() + { + _generator.Model = CreateModel( + CreateServiceController(OrderAppService, + CreateMethod("GetAsync", "MyCompany.Generic.Box"), + CreateMethod("GetBoxedAsync", "MyCompany.Orders.BoxedOrderDto"))); + + await _generator.GenerateProxyAsync(CreateArgs()); + + var serviceInterface = await File.ReadAllTextAsync(GetProxyFilePath("MyCompany/Orders/Application/IOrderAppService.cs")); + serviceInterface.ShouldContain("using MyCompany.Generic;"); + serviceInterface.ShouldContain("using MyCompany.Shared;"); + serviceInterface.ShouldContain("Task> GetAsync()"); + + var boxedOrder = await File.ReadAllTextAsync(GetProxyFilePath("MyCompany/Orders/BoxedOrderDto.cs")); + boxedOrder.ShouldContain("using MyCompany.Generic;"); + boxedOrder.ShouldContain("using MyCompany.Shared;"); + boxedOrder.ShouldContain("public Box> Nested { get; set; }"); + } + + [Fact] + public async Task Should_Keep_Service_Interfaces_When_No_Type_Is_Returned_By_The_Server() + { + _generator.Model = CreateModel( + CreateServiceController(OrderAppService, + CreateMethod("GetCountAsync", "System.Int32"))); + _generator.Model.Types.Clear(); + + await _generator.GenerateProxyAsync(CreateArgs()); + + File.Exists(GetProxyFilePath("MyCompany/Orders/Application/IOrderAppService.cs")).ShouldBeTrue(); + File.Exists(GetProxyFilePath("MyCompany/Orders/Application/OrderClientProxy.Generated.cs")).ShouldBeTrue(); + } + + [Fact] + public async Task Should_Generate_Same_Named_Types_Of_Different_Namespaces_Into_Separate_Files_In_A_Single_Folder() + { + _generator.Model = CreateModel( + CreateServiceController(OrderAppService, + CreateMethod("GetOrderStateAsync", "MyCompany.Orders.StateDto"), + CreateMethod("GetSharedStateAsync", "MyCompany.Shared.StateDto"))); + + await _generator.GenerateProxyAsync(CreateArgs(folder: "Proxies")); + + (await File.ReadAllTextAsync(Path.Combine(_workDirectory, "Proxies", "MyCompany.Orders.StateDto.cs"))).ShouldContain("namespace MyCompany.Orders;"); + (await File.ReadAllTextAsync(Path.Combine(_workDirectory, "Proxies", "MyCompany.Shared.StateDto.cs"))).ShouldContain("namespace MyCompany.Shared;"); + File.Exists(Path.Combine(_workDirectory, "Proxies", "StateDto.cs")).ShouldBeFalse(); + + var serviceInterface = await File.ReadAllTextAsync(Path.Combine(_workDirectory, "Proxies", "IOrderAppService.cs")); + serviceInterface.ShouldContain("Task GetOrderStateAsync()"); + serviceInterface.ShouldContain("Task GetSharedStateAsync()"); + } + + [Fact] + public async Task Should_Use_Full_Names_For_Same_Named_Array_Types_In_Service_Signatures() + { + _generator.Model = CreateModel( + CreateServiceController(OrderAppService, + CreateMethod("GetOrderStatesAsync", "MyCompany.Orders.StateDto[]"), + CreateMethod("GetSharedStatesAsync", "MyCompany.Shared.StateDto[]"))); + + await _generator.GenerateProxyAsync(CreateArgs()); + + var serviceInterface = await File.ReadAllTextAsync(GetProxyFilePath("MyCompany/Orders/Application/IOrderAppService.cs")); + serviceInterface.ShouldContain("Task GetOrderStatesAsync()"); + serviceInterface.ShouldContain("Task GetSharedStatesAsync()"); + + var clientProxy = await File.ReadAllTextAsync(GetProxyFilePath("MyCompany/Orders/Application/OrderClientProxy.Generated.cs")); + clientProxy.ShouldContain("public virtual async Task GetOrderStatesAsync()"); + clientProxy.ShouldContain("public virtual async Task GetSharedStatesAsync()"); + clientProxy.ShouldContain("return await RequestAsync(nameof(GetOrderStatesAsync));"); + clientProxy.ShouldContain("return await RequestAsync(nameof(GetSharedStatesAsync));"); + } + + [Fact] + public async Task Should_Use_Valid_CSharp_Names_For_Nested_Clr_Types() + { + _generator.Model = CreateModel( + CreateServiceController(OrderAppService, + CreateMethod("GetNestedAsync", "MyCompany.Orders.Outer+InnerDto"))); + + await _generator.GenerateProxyAsync(CreateArgs()); + + var nestedDtoFile = GetProxyFilePath("MyCompany/Orders/Outer_Nested_InnerDto.cs"); + File.Exists(nestedDtoFile).ShouldBeTrue(); + (await File.ReadAllTextAsync(nestedDtoFile)).ShouldContain("public class Outer_Nested_InnerDto"); + + var serviceInterface = await File.ReadAllTextAsync(GetProxyFilePath("MyCompany/Orders/Application/IOrderAppService.cs")); + serviceInterface.ShouldContain("Task GetNestedAsync()"); + serviceInterface.ShouldNotContain("+"); + + var clientProxy = await File.ReadAllTextAsync(GetProxyFilePath("MyCompany/Orders/Application/OrderClientProxy.Generated.cs")); + clientProxy.ShouldContain("public virtual async Task GetNestedAsync()"); + clientProxy.ShouldNotContain("+"); + } + + [Fact] + public async Task Should_Use_Existing_Nested_Type_Names_When_Contracts_Are_Generated() + { + WriteProjectAssets(( + ".NETCoreApp,Version=v10.0", + DefaultClientAssemblyNames.Append("NestedContracts").ToArray())); + _generator.Model = CreateModel( + CreateServiceController(OrderAppService, + CreateMethod("GetNestedAsync", "MyCompany.Orders.Outer+InnerDto"))); + _generator.Model.Types["MyCompany.Orders.Outer+InnerDto"].AssemblyName = "NestedContracts"; + + await _generator.GenerateProxyAsync(CreateArgs()); + + File.Exists(GetProxyFilePath("MyCompany/Orders/Outer_Nested_InnerDto.cs")).ShouldBeFalse(); + var serviceInterface = await File.ReadAllTextAsync(GetProxyFilePath("MyCompany/Orders/Application/IOrderAppService.cs")); + serviceInterface.ShouldContain("Task GetNestedAsync()"); + var clientProxy = await File.ReadAllTextAsync(GetProxyFilePath("MyCompany/Orders/Application/OrderClientProxy.Generated.cs")); + clientProxy.ShouldContain("public virtual async Task GetNestedAsync()"); + clientProxy.ShouldContain("return await RequestAsync(nameof(GetNestedAsync));"); + } + + [Fact] + public async Task Should_Use_Existing_Nested_Type_Names_Without_Contracts() + { + _generator.Model = CreateModel( + CreateServiceController(OrderAppService, + CreateMethod("GetNestedAsync", "MyCompany.Orders.Outer+InnerDto"))); + _generator.Model.Types.Clear(); + + await _generator.GenerateProxyAsync(CreateArgs(withoutContracts: true)); + + var clientProxy = await File.ReadAllTextAsync(GetProxyFilePath("MyCompany/Orders/Application/OrderClientProxy.Generated.cs")); + clientProxy.ShouldContain("public virtual async Task GetNestedAsync()"); + clientProxy.ShouldContain("return await RequestAsync(nameof(GetNestedAsync));"); + clientProxy.ShouldNotContain("+"); + clientProxy.ShouldNotContain("_Nested_"); + } + + [Fact] + public async Task Should_Generate_Same_Named_Generic_Types_Of_Different_Namespaces_Into_Separate_Files_In_A_Single_Folder() + { + _generator.Model = CreateModel( + CreateServiceController(OrderAppService, + CreateMethod("GetGenericBoxAsync", "MyCompany.Generic.Box"), + CreateMethod("GetSharedBoxAsync", "MyCompany.Shared.Box"))); + AddGenericType(_generator.Model, "MyCompany.Shared.Box", new[] { "T" }, + ("Items", "[T]")); + + await _generator.GenerateProxyAsync(CreateArgs(folder: "Proxies")); + + var folder = Path.Combine(_workDirectory, "Proxies"); + var genericBox = await File.ReadAllTextAsync(Path.Combine(folder, "MyCompany.Generic.Box{T}.cs")); + genericBox.ShouldContain("namespace MyCompany.Generic;"); + genericBox.ShouldContain("public class Box"); + genericBox.ShouldContain("public T Content { get; set; }"); + + var sharedBox = await File.ReadAllTextAsync(Path.Combine(folder, "MyCompany.Shared.Box{T}.cs")); + sharedBox.ShouldContain("namespace MyCompany.Shared;"); + sharedBox.ShouldContain("public class Box"); + sharedBox.ShouldContain("public T[] Items { get; set; }"); + + File.Exists(Path.Combine(folder, "Box.cs")).ShouldBeFalse(); + File.Exists(Path.Combine(folder, "Box{T}.cs")).ShouldBeFalse(); + + var serviceInterface = await File.ReadAllTextAsync(Path.Combine(folder, "IOrderAppService.cs")); + serviceInterface.ShouldContain("Task> GetGenericBoxAsync()"); + serviceInterface.ShouldContain("Task> GetSharedBoxAsync()"); + + var clientProxy = await File.ReadAllTextAsync(Path.Combine(folder, "OrderClientProxy.Generated.cs")); + clientProxy.ShouldContain("return await RequestAsync>(nameof(GetGenericBoxAsync));"); + clientProxy.ShouldContain("return await RequestAsync>(nameof(GetSharedBoxAsync));"); + } + + [Fact] + public async Task Should_Use_Full_Names_For_Same_Named_Types_Of_Different_Namespaces() + { + _generator.Model = CreateModel( + CreateServiceController(OrderAppService, + CreateMethod("GetStatesAsync", "MyCompany.Orders.StatesDto"))); + + await _generator.GenerateProxyAsync(CreateArgs()); + + var states = await File.ReadAllTextAsync(GetProxyFilePath("MyCompany/Orders/StatesDto.cs")); + states.ShouldContain("public class StatesDto"); + states.ShouldContain("public global::MyCompany.Orders.StateDto OrderState { get; set; }"); + states.ShouldContain("public global::MyCompany.Shared.StateDto[] SharedStates { get; set; }"); + states.ShouldContain("public Wrapper Wrapped { get; set; }"); + (await File.ReadAllTextAsync(GetProxyFilePath("MyCompany/Orders/StateDto.cs"))).ShouldContain("public class StateDto"); + } + + [Fact] + public async Task Should_Ignore_Unreferenced_Types_When_Detecting_Ambiguous_Names() + { + _generator.Model = CreateModel( + CreateServiceController(OrderAppService, + CreateMethod("GetStateAsync", "MyCompany.Orders.StateDto"))); + AddType(_generator.Model, "MyCompany.Unrelated.StateDto", null); + + await _generator.GenerateProxyAsync(CreateArgs()); + + var serviceInterface = await File.ReadAllTextAsync(GetProxyFilePath("MyCompany/Orders/Application/IOrderAppService.cs")); + serviceInterface.ShouldContain("Task GetStateAsync()"); + serviceInterface.ShouldNotContain("global::MyCompany.Orders.StateDto"); + } + + [Fact] + public async Task Should_Generate_Nested_Dictionaries() + { + _generator.Model = CreateModel( + CreateServiceController(OrderAppService, + CreateMethod("GetTagMapAsync", "MyCompany.Orders.TagMapDto"))); + + await _generator.GenerateProxyAsync(CreateArgs()); + + (await File.ReadAllTextAsync(GetProxyFilePath("MyCompany/Orders/TagMapDto.cs"))) + .ShouldContain("public Dictionary> Tags { get; set; }"); + File.Exists(GetProxyFilePath("MyCompany/Shared/TagDto.cs")).ShouldBeTrue(); + } + + [Fact] + public async Task Should_Use_Full_Names_For_Same_Named_Types_Without_Contracts() + { + _generator.Model = CreateModel( + CreateServiceController(OrderAppService, + CreateMethod("GetOrderStateAsync", "MyCompany.Orders.StateDto"), + CreateMethod("GetSharedStateAsync", "MyCompany.Shared.StateDto"))); + _generator.Model.Types.Clear(); + + await _generator.GenerateProxyAsync(CreateArgs(withoutContracts: true)); + + var clientProxy = await File.ReadAllTextAsync(GetProxyFilePath("MyCompany/Orders/Application/OrderClientProxy.Generated.cs")); + clientProxy.ShouldContain("using MyCompany.Orders;"); + clientProxy.ShouldContain("using MyCompany.Shared;"); + clientProxy.ShouldContain("public virtual async Task GetOrderStateAsync()"); + clientProxy.ShouldContain("public virtual async Task GetSharedStateAsync()"); + } + + private GenerateProxyArgs CreateArgs(string module = "orders", bool withoutContracts = false, string folder = null) + { + return new GenerateProxyArgs("generate-proxy", _workDirectory, module, null, null, null, null, null, folder, null, null, withoutContracts); + } + + private string GetProxyFilePath(string relativePath) + { + return Path.Combine(_workDirectory, "ClientProxies", relativePath.Replace('/', Path.DirectorySeparatorChar)); + } + + private static ApplicationApiDescriptionModel CreateModel(params ControllerApiDescriptionModel[] controllers) + { + return CreateModuleModel("orders", controllers); + } + + private static ApplicationApiDescriptionModel CreateModuleModel(string moduleName, params ControllerApiDescriptionModel[] controllers) + { + var module = ModuleApiDescriptionModel.Create(moduleName, moduleName); + foreach (var controller in controllers) + { + module.Controllers[controller.Type] = controller; + } + + var model = ApplicationApiDescriptionModel.Create(); + model.AddModule(module); + + AddType(model, "MyCompany.Orders.OrderDto", "Volo.Abp.Application.Dtos.ExtensibleEntityDto", + ("Customer", "MyCompany.Shared.CustomerDto"), + ("Status", "MyCompany.Shared.OrderStatus?"), + ("Lines", "[MyCompany.Orders.OrderLineDto]")); + AddType(model, "MyCompany.Orders.OrderDetailDto", "MyCompany.Orders.OrderDto", + ("Tags", "MyCompany.Shared.Wrapper")); + AddType(model, "MyCompany.Orders.OrderLineDto", null, + ("Price", "System.Decimal")); + AddType(model, "MyCompany.Orders.GetOrdersInput", "Volo.Abp.Application.Dtos.PagedAndSortedResultRequestDto"); + AddType(model, "MyCompany.Orders.Application.UnusedDto", null); + AddType(model, "MyCompany.Shared.CustomerDto", null, + ("Addresses", "{System.String:MyCompany.Shared.AddressDto}"), + ("ValueType", "Volo.Abp.Validation.StringValues.IStringValueType")); + AddType(model, "MyCompany.Shared.AddressDto", null); + AddType(model, "MyCompany.Shared.TagDto", null); + AddGenericType(model, "MyCompany.Shared.Wrapper", new[] { "T" }, + ("Value", "T"), + ("Items", "[T]")); + AddType(model, "MyCompany.Shared.Result", null); + AddGenericType(model, "MyCompany.Shared.Result", new[] { "T" }, + ("Value", "T")); + AddGenericType(model, "MyCompany.Shared.Result", new[] { "TItem", "TError" }, + ("Item", "TItem"), + ("Error", "TError")); + AddType(model, "Volo.Abp.ObjectExtending.OrdersModuleExtensionDto", null); + AddType(model, "MyCompany.Orders.OrderOwnerDto", null, + ("Owner", "Volo.Abp.Identity.IdentityUserDto")); + AddType(model, "Volo.Abp.Identity.IdentityUserDto", "Volo.Abp.Application.Dtos.ExtensibleFullAuditedEntityDto", + ("UserName", "System.String")); + AddType(model, "Volo.Abp.Users.UserData", null, + ("UserName", "System.String")); + AddType(model, "Volo.Abp.Identity.UserLookupSearchInputDto", null, + ("Filter", "System.String")); + AddType(model, "Volo.Abp.MultiTenancy.TenantConfiguration", null, + ("Name", "System.String")); + AddGenericType(model, "MyCompany.Generic.Box", new[] { "T" }, + ("Content", "T")); + AddType(model, "MyCompany.Orders.BoxedOrderDto", null, + ("Nested", "MyCompany.Generic.Box>")); + AddType(model, "MyCompany.Orders.StateDto", null); + AddType(model, "MyCompany.Orders.Outer+InnerDto", null, + ("NestedValue", "System.String")); + AddType(model, "MyCompany.Orders.TagMapDto", null, + ("Tags", "{System.String:{System.String:MyCompany.Shared.TagDto}}")); + AddType(model, "MyCompany.Orders.StatesDto", null, + ("OrderState", "MyCompany.Orders.StateDto"), + ("SharedStates", "[MyCompany.Shared.StateDto]"), + ("Wrapped", "MyCompany.Shared.Wrapper")); + AddType(model, "MyCompany.Shared.StateDto", null); + model.Types["MyCompany.Shared.OrderStatus"] = new TypeApiDescriptionModel + { + IsEnum = true, + EnumNames = new[] { "Pending", "Shipped" }, + EnumValues = new object[] { 0, 1 } + }; + + AddType(model, "Volo.Abp.Application.Dtos.ExtensibleEntityDto", "Volo.Abp.ObjectExtending.ExtensibleObject"); + AddType(model, "Volo.Abp.Application.Dtos.PagedResultDto", "Volo.Abp.Application.Dtos.ListResultDto"); + AddType(model, "Volo.Abp.Application.Dtos.ListResultDto", null); + AddType(model, "Volo.Abp.Application.Dtos.EntityDto", null); + AddType(model, "Volo.Abp.Application.Dtos.PagedAndSortedResultRequestDto", null); + AddType(model, "Volo.Abp.ObjectExtending.ExtensibleObject", null); + AddType(model, "Volo.Abp.NameValue", null); + AddType(model, "Volo.Abp.Content.IRemoteStreamContent", null); + AddType(model, "Volo.Abp.Http.Modeling.ApplicationApiDescriptionModel", null); + AddType(model, "Microsoft.AspNetCore.Http.IFormFile", null, + ("Headers", "Microsoft.AspNetCore.Http.IHeaderDictionary")); + AddType(model, "Volo.Abp.Validation.StringValues.IStringValueType", null, + ("Validator", "Volo.Abp.Validation.StringValues.IValueValidator")); + AddType(model, "Volo.Abp.Validation.StringValues.IValueValidator", null); + + model.Types["Volo.Abp.Identity.IdentityUserDto"].AssemblyName = "Volo.Abp.Identity.Application.Contracts"; + model.Types["Volo.Abp.Users.UserData"].AssemblyName = "Volo.Abp.Users.Abstractions"; + model.Types["Volo.Abp.Identity.UserLookupSearchInputDto"].AssemblyName = "Volo.Abp.Identity.Application.Contracts"; + model.Types["Volo.Abp.MultiTenancy.TenantConfiguration"].AssemblyName = "Volo.Abp.MultiTenancy.Abstractions"; + model.Types["Volo.Abp.ObjectExtending.OrdersModuleExtensionDto"].AssemblyName = "Volo.Abp.ObjectExtending"; + model.Types["Volo.Abp.Application.Dtos.ExtensibleEntityDto"].AssemblyName = "Volo.Abp.Ddd.Application.Contracts"; + model.Types["Volo.Abp.Application.Dtos.PagedResultDto"].AssemblyName = "Volo.Abp.Ddd.Application.Contracts"; + model.Types["Volo.Abp.Application.Dtos.ListResultDto"].AssemblyName = "Volo.Abp.Ddd.Application.Contracts"; + model.Types["Volo.Abp.Application.Dtos.EntityDto"].AssemblyName = "Volo.Abp.Ddd.Application.Contracts"; + model.Types["Volo.Abp.Application.Dtos.PagedAndSortedResultRequestDto"].AssemblyName = "Volo.Abp.Ddd.Application.Contracts"; + model.Types["Volo.Abp.ObjectExtending.ExtensibleObject"].AssemblyName = "Volo.Abp.ObjectExtending"; + model.Types["Volo.Abp.NameValue"].AssemblyName = "Volo.Abp.Core"; + model.Types["Volo.Abp.Content.IRemoteStreamContent"].AssemblyName = "Volo.Abp.Http.Abstractions"; + model.Types["Volo.Abp.Http.Modeling.ApplicationApiDescriptionModel"].AssemblyName = "Volo.Abp.Http"; + model.Types["Volo.Abp.Validation.StringValues.IStringValueType"].AssemblyName = "Volo.Abp.Validation.Abstractions"; + model.Types["Volo.Abp.Validation.StringValues.IValueValidator"].AssemblyName = "Volo.Abp.Validation.Abstractions"; + + return model; + } + + private static void AddType(ApplicationApiDescriptionModel model, string name, string baseType, params (string Name, string Type)[] properties) + { + model.Types[name] = new TypeApiDescriptionModel + { + BaseType = baseType, + Properties = properties.Select(x => new PropertyApiDescriptionModel { Name = x.Name, Type = x.Type }).ToArray() + }; + } + + private static void AddGenericType(ApplicationApiDescriptionModel model, string name, string[] genericArguments, params (string Name, string Type)[] properties) + { + AddType(model, name, null, properties); + model.Types[name].GenericArguments = genericArguments; + } + + private void WriteProjectAssets(params (string Target, string[] Assemblies)[] targets) + { + WriteProjectAssets(Path.Combine(_workDirectory, "obj", "project.assets.json"), targets); + } + + private static void WriteProjectAssets(string assetsFilePath, params (string Target, string[] Assemblies)[] targets) + { + var targetData = targets.ToDictionary( + x => x.Target, + x => new Dictionary + { + ["ClientDependencies/1.0.0"] = new + { + compile = x.Assemblies.ToDictionary( + assemblyName => $"lib/net10.0/{assemblyName}.dll", + _ => new { }) + } + }); + Directory.CreateDirectory(Path.GetDirectoryName(assetsFilePath)!); + File.WriteAllText(assetsFilePath, JsonSerializer.Serialize(new { targets = targetData })); + } + + private static ControllerApiDescriptionModel CreateServiceController(string serviceInterface, params InterfaceMethodApiDescriptionModel[] methods) + { + var serviceName = serviceInterface.Split('.').Last(); + return new ControllerApiDescriptionModel + { + ControllerName = serviceName.Substring(1).Replace("AppService", string.Empty), + Type = serviceInterface.Replace($".{serviceName}", $".{serviceName.Substring(1)}"), + Interfaces = new List + { + new() { Type = serviceInterface, Name = serviceName, Methods = methods } + }, + Actions = methods.ToDictionary(x => x.Name, x => new ActionApiDescriptionModel + { + Name = x.Name, + ImplementFrom = serviceInterface, + ParametersOnMethod = x.ParametersOnMethod, + Parameters = new List(), + ReturnValue = x.ReturnValue + }) + }; + } + + private static InterfaceMethodApiDescriptionModel CreateMethod(string name, string returnType, params string[] parameterTypes) + { + return new InterfaceMethodApiDescriptionModel + { + Name = name, + ParametersOnMethod = parameterTypes.Select((x, i) => new MethodParameterApiDescriptionModel { Name = $"p{i}", Type = x }).ToList(), + ReturnValue = new ReturnValueApiDescriptionModel { Type = returnType } + }; + } + + private class TestCSharpServiceProxyGenerator : CSharpServiceProxyGenerator + { + public ApplicationApiDescriptionModel Model { get; set; } + + public string WorkDirectory { get; set; } + + public string ProjectAssetsFilePath { get; set; } + + public int ProjectAssetsFilePathCallCount { get; private set; } + + public TestCSharpServiceProxyGenerator() + : base(null, new AbpSystemTextJsonSerializer(Microsoft.Extensions.Options.Options.Create(new AbpSystemTextJsonSerializerOptions()))) + { + } + + public List GetTypes(ApplicationApiDescriptionModel model) + { + Model = model; + GenerateProxyAsync(new GenerateProxyArgs( + "generate-proxy", + WorkDirectory, + model.Modules.Keys.First(), + null, + null, + null, + null, + null, + null, + null, + null, + false)).GetAwaiter().GetResult(); + return TypesToGenerate; + } + + protected override List GetTypesToGenerate(ApplicationApiDescriptionModel applicationApiDescriptionModel) + { + TypesToGenerate = base.GetTypesToGenerate(applicationApiDescriptionModel); + return TypesToGenerate; + } + + protected override string GetProjectAssetsFilePath(string workDirectory) + { + ProjectAssetsFilePathCallCount++; + return ProjectAssetsFilePath ?? base.GetProjectAssetsFilePath(workDirectory); + } + + protected override Task GetApplicationApiDescriptionModelAsync(GenerateProxyArgs args, ApplicationApiDescriptionModelRequestDto requestDto = null) + { + return Task.FromResult(Model); + } + + private List TypesToGenerate { get; set; } + } +} diff --git a/framework/test/Volo.Abp.Core.Tests/Volo/Abp/RandomHelper_Tests.cs b/framework/test/Volo.Abp.Core.Tests/Volo/Abp/RandomHelper_Tests.cs new file mode 100644 index 0000000000..6c7ffa9f14 --- /dev/null +++ b/framework/test/Volo.Abp.Core.Tests/Volo/Abp/RandomHelper_Tests.cs @@ -0,0 +1,103 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Shouldly; +using Xunit; + +namespace Volo.Abp; + +public class RandomHelper_Tests +{ + [Fact] + public void GetRandom_Should_Return_Value_In_The_Given_Range() + { + for (var i = 0; i < 100; i++) + { + var value = RandomHelper.GetRandom(10, 20); + value.ShouldBeGreaterThanOrEqualTo(10); + value.ShouldBeLessThan(20); + } + } + + [Fact] + public void GetRandom_Should_Handle_Empty_Range() + { + RandomHelper.GetRandom(0).ShouldBe(0); + RandomHelper.GetRandom(5, 5).ShouldBe(5); + } + + [Fact] + public void GetRandom_Should_Throw_Exception_For_Invalid_Range() + { + Assert.Throws(() => RandomHelper.GetRandom(-1)).ParamName.ShouldBe("maxValue"); + Assert.Throws(() => RandomHelper.GetRandom(10, 5)).ParamName.ShouldBe("minValue"); + } + + [Fact] + public void GenerateRandomizedList_Should_Keep_All_Items() + { + var items = new List { 1, 2, 3, 4, 5, 6, 7, 8 }; + + var randomizedList = RandomHelper.GenerateRandomizedList(items); + + randomizedList.OrderBy(x => x).ShouldBe(items); + } + + [Fact] + public void GenerateRandomizedList_Should_Keep_Duplicate_Items() + { + var items = new List { 1, 1, 2, 2, 2, 3 }; + + var randomizedList = RandomHelper.GenerateRandomizedList(items); + + randomizedList.OrderBy(x => x).ShouldBe(items); + } + + [Fact] + public void GenerateRandomizedList_Should_Work_With_Empty_Items() + { + RandomHelper.GenerateRandomizedList(new List()).ShouldBeEmpty(); + } + + [Fact] + public void GenerateRandomizedList_Should_Work_With_Single_Item() + { + RandomHelper.GenerateRandomizedList(new List { 42 }).ShouldBe(new List { 42 }); + } + + [Fact] + public void GenerateRandomizedList_Should_Not_Change_The_Given_Items() + { + var items = new List { 1, 2, 3, 4, 5, 6, 7, 8 }; + + RandomHelper.GenerateRandomizedList(items); + + items.ShouldBe(new List { 1, 2, 3, 4, 5, 6, 7, 8 }); + } + + [Fact] + public void GenerateRandomizedList_Should_Enumerate_The_Given_Items_Once() + { + var enumerationCount = 0; + + IEnumerable GetItems() + { + enumerationCount++; + yield return 1; + yield return 2; + yield return 3; + } + + RandomHelper.GenerateRandomizedList(GetItems()); + + enumerationCount.ShouldBe(1); + } + + [Fact] + public void GenerateRandomizedList_Should_Throw_Exception_For_Null_Items() + { + Assert + .Throws(() => RandomHelper.GenerateRandomizedList(null!)) + .ParamName.ShouldBe("items"); + } +} diff --git a/framework/test/Volo.Abp.Core.Tests/Volo/Abp/Threading/RetryHelper_Tests.cs b/framework/test/Volo.Abp.Core.Tests/Volo/Abp/Threading/RetryHelper_Tests.cs new file mode 100644 index 0000000000..9cd4beb2ee --- /dev/null +++ b/framework/test/Volo.Abp.Core.Tests/Volo/Abp/Threading/RetryHelper_Tests.cs @@ -0,0 +1,1077 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Threading; +using System.Threading.Tasks; +using Shouldly; +using Xunit; + +namespace Volo.Abp.Threading; + +public class RetryHelper_Tests +{ + private static RetryOptions NoDelay( + int maxRetryCount = 3, + Func? shouldRetryOnException = null, + Func? onRetry = null) + { + var options = new RetryOptions + { + MaxRetryCount = maxRetryCount, + DelayFactory = _ => TimeSpan.Zero, + OnRetry = onRetry + }; + + if (shouldRetryOnException != null) + { + options.ShouldRetryOnException = shouldRetryOnException; + } + + return options; + } + + private static RetryOptions NoDelay( + int maxRetryCount = 3, + Func? shouldRetryOnResult = null, + Func? shouldRetryOnException = null, + Func, Task>? onRetry = null) + { + var options = new RetryOptions + { + MaxRetryCount = maxRetryCount, + DelayFactory = _ => TimeSpan.Zero, + OnRetry = onRetry + }; + + if (shouldRetryOnResult != null) + { + options.ShouldRetryOnResult = shouldRetryOnResult; + } + + if (shouldRetryOnException != null) + { + options.ShouldRetryOnException = shouldRetryOnException; + } + + return options; + } + + private static async Task ThrowFromHelperAsync() + { + await Task.Yield(); + throw new InvalidOperationException("thrown-by-helper"); + } + + #region Defaults + + [Fact] + public void RetryOptions_Should_Have_Expected_Defaults() + { + var options = new RetryOptions(); + + options.MaxRetryCount.ShouldBe(3); + options.OnRetry.ShouldBeNull(); + options.ShouldRetryOnException(new Exception()).ShouldBeTrue(); + options.ShouldRetryOnException(new OperationCanceledException()).ShouldBeFalse(); + + options.DelayFactory(1).ShouldBe(TimeSpan.FromSeconds(2)); + options.DelayFactory(2).ShouldBe(TimeSpan.FromSeconds(4)); + options.DelayFactory(3).ShouldBe(TimeSpan.FromSeconds(8)); + + options.DelayFactory(21).ShouldBe(TimeSpan.FromSeconds(2097152)); + options.DelayFactory(22).ShouldBe(TimeSpan.FromMilliseconds(int.MaxValue)); + options.DelayFactory(int.MaxValue).ShouldBe(TimeSpan.FromMilliseconds(int.MaxValue)); + } + + [Fact] + public void RetryOptions_Of_TResult_Should_Have_Expected_Defaults() + { + var options = new RetryOptions(); + + options.MaxRetryCount.ShouldBe(3); + options.OnRetry.ShouldBeNull(); + options.ShouldRetryOnException(new Exception()).ShouldBeTrue(); + options.ShouldRetryOnException(new OperationCanceledException()).ShouldBeFalse(); + options.ShouldRetryOnResult(42).ShouldBeFalse(); + + options.DelayFactory(1).ShouldBe(TimeSpan.FromSeconds(2)); + options.DelayFactory(2).ShouldBe(TimeSpan.FromSeconds(4)); + options.DelayFactory(3).ShouldBe(TimeSpan.FromSeconds(8)); + + options.DelayFactory(21).ShouldBe(TimeSpan.FromSeconds(2097152)); + options.DelayFactory(22).ShouldBe(TimeSpan.FromMilliseconds(int.MaxValue)); + options.DelayFactory(int.MaxValue).ShouldBe(TimeSpan.FromMilliseconds(int.MaxValue)); + } + + #endregion + + #region ExecuteAsync + + [Fact] + public async Task ExecuteAsync_Should_Not_Retry_When_The_Action_Succeeds() + { + var attempts = 0; + var retries = 0; + + await RetryHelper.ExecuteAsync( + _ => + { + attempts++; + return Task.CompletedTask; + }, + NoDelay(onRetry: _ => { retries++; return Task.CompletedTask; })); + + attempts.ShouldBe(1); + retries.ShouldBe(0); + } + + [Fact] + public async Task ExecuteAsync_Should_Retry_Until_The_Action_Succeeds() + { + var attempts = 0; + + await RetryHelper.ExecuteAsync( + _ => + { + attempts++; + if (attempts < 3) + { + throw new InvalidOperationException("not yet"); + } + + return Task.CompletedTask; + }, + NoDelay()); + + attempts.ShouldBe(3); + } + + [Fact] + public async Task ExecuteAsync_Should_Rethrow_The_Last_Exception_When_The_Retries_Are_Exhausted() + { + var attempts = 0; + + var exception = await Assert.ThrowsAsync(async () => + await RetryHelper.ExecuteAsync( + _ => + { + attempts++; + throw new InvalidOperationException($"attempt-{attempts}"); + }, + NoDelay(maxRetryCount: 3))); + + attempts.ShouldBe(4); // the initial attempt + 3 retries + exception.Message.ShouldBe("attempt-4"); + } + + [Fact] + public async Task ExecuteAsync_Should_Preserve_The_Stack_Trace_Of_The_Rethrown_Exception() + { + var exception = await Assert.ThrowsAsync(async () => + await RetryHelper.ExecuteAsync( + _ => ThrowFromHelperAsync(), + NoDelay(maxRetryCount: 1))); + + exception.Message.ShouldBe("thrown-by-helper"); + exception.StackTrace.ShouldNotBeNull(); + exception.StackTrace.ShouldContain(nameof(ThrowFromHelperAsync)); + } + + [Fact] + public async Task ExecuteAsync_Should_Not_Retry_When_ShouldRetryOnException_Returns_False() + { + var attempts = 0; + var retries = 0; + + await Assert.ThrowsAsync(async () => + await RetryHelper.ExecuteAsync( + _ => + { + attempts++; + throw new InvalidOperationException(); + }, + NoDelay(shouldRetryOnException: _ => false, onRetry: _ => { retries++; return Task.CompletedTask; }))); + + attempts.ShouldBe(1); + retries.ShouldBe(0); + } + + [Fact] + public async Task ExecuteAsync_Should_Only_Retry_The_Handled_Exception_Types() + { + var attempts = 0; + + await Assert.ThrowsAsync(async () => + await RetryHelper.ExecuteAsync( + _ => + { + attempts++; + if (attempts < 3) + { + throw new IOException(); + } + + throw new UnauthorizedAccessException(); + }, + NoDelay(maxRetryCount: 10, shouldRetryOnException: ex => ex is IOException))); + + attempts.ShouldBe(3); // 2 retried IOExceptions, then the unhandled one stops it + } + + [Fact] + public async Task ExecuteAsync_Should_Not_Retry_When_MaxRetryCount_Is_Zero() + { + var attempts = 0; + + await Assert.ThrowsAsync(async () => + await RetryHelper.ExecuteAsync( + _ => + { + attempts++; + throw new InvalidOperationException(); + }, + NoDelay(maxRetryCount: 0))); + + attempts.ShouldBe(1); + } + + [Fact] + public async Task ExecuteAsync_Should_Ask_The_DelayFactory_With_An_Increasing_One_Based_RetryCount() + { + var requestedRetryCounts = new List(); + + await Assert.ThrowsAsync(async () => + await RetryHelper.ExecuteAsync( + _ => throw new InvalidOperationException(), + new RetryOptions + { + MaxRetryCount = 3, + DelayFactory = retryCount => + { + requestedRetryCounts.Add(retryCount); + return TimeSpan.Zero; + } + })); + + requestedRetryCounts.ShouldBe(new[] { 1, 2, 3 }); + } + + [Fact] + public async Task ExecuteAsync_Should_Report_Every_Retry_To_OnRetry() + { + var attempts = 0; + var reported = new List(); + + await Assert.ThrowsAsync(async () => + await RetryHelper.ExecuteAsync( + _ => + { + attempts++; + throw new InvalidOperationException($"attempt-{attempts}"); + }, + new RetryOptions + { + MaxRetryCount = 2, + DelayFactory = retryCount => TimeSpan.FromMilliseconds(retryCount), + OnRetry = attempt => { reported.Add(attempt); return Task.CompletedTask; } + })); + + reported.Count.ShouldBe(2); + + reported[0].RetryCount.ShouldBe(1); + reported[0].RetryDelay.ShouldBe(TimeSpan.FromMilliseconds(1)); + reported[0].Exception.ShouldNotBeNull(); + reported[0].Exception!.Message.ShouldBe("attempt-1"); + + reported[1].RetryCount.ShouldBe(2); + reported[1].RetryDelay.ShouldBe(TimeSpan.FromMilliseconds(2)); + reported[1].Exception!.Message.ShouldBe("attempt-2"); + } + + [Fact] + public async Task ExecuteAsync_Should_Pass_The_CancellationToken_To_The_Action() + { + using var cancellationTokenSource = new CancellationTokenSource(); + var received = CancellationToken.None; + + await RetryHelper.ExecuteAsync( + cancellationToken => + { + received = cancellationToken; + return Task.CompletedTask; + }, + NoDelay(), + cancellationTokenSource.Token); + + received.ShouldBe(cancellationTokenSource.Token); + } + + [Fact] + public async Task ExecuteAsync_Should_Stop_Waiting_When_The_CancellationToken_Is_Cancelled() + { + using var cancellationTokenSource = new CancellationTokenSource(); + var attempts = 0; + + // Cancelled while Task.Delay is running, not before it starts. + cancellationTokenSource.CancelAfter(TimeSpan.FromMilliseconds(50)); + + await Assert.ThrowsAnyAsync(async () => + await RetryHelper.ExecuteAsync( + _ => + { + attempts++; + throw new InvalidOperationException(); + }, + new RetryOptions + { + MaxRetryCount = 5, + DelayFactory = _ => TimeSpan.FromMinutes(1) + }, + cancellationTokenSource.Token)); + + attempts.ShouldBe(1); + } + + [Fact] + public async Task ExecuteAsync_Should_Not_Report_A_Retry_When_The_Action_Was_Cancelled() + { + using var cancellationTokenSource = new CancellationTokenSource(); + var attempts = 0; + var retries = 0; + + await Assert.ThrowsAnyAsync(async () => + await RetryHelper.ExecuteAsync( + cancellationToken => + { + attempts++; + cancellationTokenSource.Cancel(); + cancellationToken.ThrowIfCancellationRequested(); + return Task.CompletedTask; + }, + NoDelay(maxRetryCount: 5, onRetry: _ => { retries++; return Task.CompletedTask; }), + cancellationTokenSource.Token)); + + attempts.ShouldBe(1); + retries.ShouldBe(0); + } + + [Fact] + public async Task ExecuteAsync_Of_TResult_Should_Not_Report_A_Retry_When_The_Action_Was_Cancelled() + { + using var cancellationTokenSource = new CancellationTokenSource(); + var attempts = 0; + var retries = 0; + + await Assert.ThrowsAnyAsync(async () => + await RetryHelper.ExecuteAsync( + cancellationToken => + { + attempts++; + cancellationTokenSource.Cancel(); + cancellationToken.ThrowIfCancellationRequested(); + return Task.FromResult(1); + }, + NoDelay(maxRetryCount: 5, onRetry: _ => { retries++; return Task.CompletedTask; }), + cancellationTokenSource.Token)); + + attempts.ShouldBe(1); + retries.ShouldBe(0); + } + + [Fact] + public async Task ExecuteAsync_Should_Retry_A_Cancellation_Exception_When_The_Predicate_Allows_It() + { + var attempts = 0; + + await RetryHelper.ExecuteAsync( + _ => + { + attempts++; + if (attempts < 3) + { + throw new OperationCanceledException(); + } + + return Task.CompletedTask; + }, + NoDelay(maxRetryCount: 5, shouldRetryOnException: _ => true)); + + attempts.ShouldBe(3); + } + + [Fact] + public async Task ExecuteAsync_Should_Await_OnRetry_Before_The_Next_Attempt() + { + var attempts = 0; + var onRetryFinished = 0; + var onRetryFinishedBeforeNextAttempt = true; + + await RetryHelper.ExecuteAsync( + async _ => + { + attempts++; + if (attempts > 1 && onRetryFinished != attempts - 1) + { + onRetryFinishedBeforeNextAttempt = false; + } + + if (attempts < 3) + { + await Task.Yield(); + throw new InvalidOperationException(); + } + }, + NoDelay( + maxRetryCount: 5, + onRetry: async _ => + { + await Task.Delay(10); + onRetryFinished++; + })); + + attempts.ShouldBe(3); + onRetryFinished.ShouldBe(2); + onRetryFinishedBeforeNextAttempt.ShouldBeTrue(); + } + + [Fact] + public async Task ExecuteAsync_Should_Not_Run_The_Action_When_The_CancellationToken_Is_Already_Cancelled() + { + using var cancellationTokenSource = new CancellationTokenSource(); + cancellationTokenSource.Cancel(); + + var attempts = 0; + + await Assert.ThrowsAnyAsync(async () => + await RetryHelper.ExecuteAsync( + _ => + { + attempts++; + return Task.CompletedTask; + }, + NoDelay(), + cancellationTokenSource.Token)); + + attempts.ShouldBe(0); + } + + [Fact] + public async Task ExecuteAsync_Of_TResult_Should_Not_Run_The_Action_When_The_CancellationToken_Is_Already_Cancelled() + { + using var cancellationTokenSource = new CancellationTokenSource(); + cancellationTokenSource.Cancel(); + + var attempts = 0; + + await Assert.ThrowsAnyAsync(async () => + await RetryHelper.ExecuteAsync( + _ => + { + attempts++; + return Task.FromResult(1); + }, + NoDelay(), + cancellationTokenSource.Token)); + + attempts.ShouldBe(0); + } + + [Fact] + public async Task ExecuteAsync_Should_Throw_When_The_DelayFactory_Throws() + { + await Assert.ThrowsAsync(async () => + await RetryHelper.ExecuteAsync( + _ => throw new InvalidOperationException(), + new RetryOptions + { + MaxRetryCount = 5, + DelayFactory = _ => TimeSpan.FromSeconds(double.MaxValue) + })); + + await Assert.ThrowsAsync(async () => + await RetryHelper.ExecuteAsync( + _ => throw new InvalidOperationException(), + new RetryOptions + { + MaxRetryCount = 5, + DelayFactory = _ => throw new FormatException() + })); + } + + [Fact] + public async Task ExecuteAsync_Should_Report_The_Delay_It_Waits_For() + { + using var cancellationTokenSource = new CancellationTokenSource(); + var reported = TimeSpan.Zero; + + await Assert.ThrowsAnyAsync(async () => + await RetryHelper.ExecuteAsync( + _ => throw new InvalidOperationException(), + new RetryOptions + { + MaxRetryCount = 5, + DelayFactory = _ => TimeSpan.FromDays(100), + OnRetry = attempt => + { + reported = attempt.RetryDelay; + cancellationTokenSource.Cancel(); + return Task.CompletedTask; + } + }, + cancellationTokenSource.Token)); + + reported.ShouldBe(TimeSpan.FromMilliseconds(int.MaxValue)); + } + + [Fact] + public async Task ExecuteAsync_Should_Use_The_Options_As_They_Were_When_It_Started() + { + var attempts = 0; + var options = new RetryOptions + { + MaxRetryCount = 2, + DelayFactory = _ => TimeSpan.Zero + }; + + options.OnRetry = _ => + { + options.MaxRetryCount = 0; + options.DelayFactory = null!; + options.ShouldRetryOnException = null!; + return Task.CompletedTask; + }; + + await Assert.ThrowsAsync(async () => + await RetryHelper.ExecuteAsync( + _ => + { + attempts++; + throw new InvalidOperationException(); + }, + options)); + + attempts.ShouldBe(3); + } + + [Fact] + public async Task ExecuteAsync_Should_Not_Wait_For_A_Negative_Delay() + { + var attempts = 0; + + await Assert.ThrowsAsync(async () => + await RetryHelper.ExecuteAsync( + _ => + { + attempts++; + throw new InvalidOperationException(); + }, + new RetryOptions + { + MaxRetryCount = 2, + DelayFactory = _ => TimeSpan.FromSeconds(-1) + })); + + attempts.ShouldBe(3); + } + + [Fact] + public async Task ExecuteAsync_Should_Ask_The_Exception_Predicate_On_Every_Attempt() + { + var asked = 0; + + await Assert.ThrowsAsync(async () => + await RetryHelper.ExecuteAsync( + _ => throw new InvalidOperationException(), + NoDelay(maxRetryCount: 2, shouldRetryOnException: _ => { asked++; return true; }))); + + asked.ShouldBe(3); // including the last attempt, which is not retried + } + + [Fact] + public async Task ExecuteAsync_Should_Throw_When_MaxRetryCount_Is_Negative() + { + await Assert.ThrowsAsync(async () => + await RetryHelper.ExecuteAsync(_ => Task.CompletedTask, new RetryOptions { MaxRetryCount = -1 })); + } + + [Fact] + public async Task ExecuteAsync_Should_Throw_When_A_Delegate_Option_Is_Null() + { + await Assert.ThrowsAsync(async () => + await RetryHelper.ExecuteAsync(_ => Task.CompletedTask, new RetryOptions { DelayFactory = null! })); + + await Assert.ThrowsAsync(async () => + await RetryHelper.ExecuteAsync(_ => Task.CompletedTask, new RetryOptions { ShouldRetryOnException = null! })); + + await Assert.ThrowsAsync(async () => + await RetryHelper.ExecuteAsync(_ => Task.FromResult(1), new RetryOptions { ShouldRetryOnResult = null! })); + } + + [Fact] + public async Task ExecuteAsync_Should_Throw_When_The_Action_Is_Null() + { + await Assert.ThrowsAsync(async () => + await RetryHelper.ExecuteAsync(null!, NoDelay())); + } + + [Fact] + public async Task ExecuteAsync_Should_Work_Without_Options() + { + var attempts = 0; + + await RetryHelper.ExecuteAsync(_ => + { + attempts++; + return Task.CompletedTask; + }); + + attempts.ShouldBe(1); + } + + #endregion + + #region ExecuteAsync + + [Fact] + public async Task ExecuteAsync_Of_TResult_Should_Return_The_Result_Without_Retrying_By_Default() + { + var attempts = 0; + + var result = await RetryHelper.ExecuteAsync( + _ => + { + attempts++; + return Task.FromResult("ok"); + }, + NoDelay()); + + result.ShouldBe("ok"); + attempts.ShouldBe(1); + } + + [Fact] + public async Task ExecuteAsync_Of_TResult_Should_Retry_While_The_Result_Is_Not_Accepted() + { + var attempts = 0; + + var result = await RetryHelper.ExecuteAsync( + _ => + { + attempts++; + return Task.FromResult(attempts); + }, + NoDelay(maxRetryCount: 5, shouldRetryOnResult: value => value < 3)); + + result.ShouldBe(3); + attempts.ShouldBe(3); + } + + [Fact] + public async Task ExecuteAsync_Of_TResult_Should_Return_The_Last_Result_When_The_Retries_Are_Exhausted() + { + var attempts = 0; + + var result = await RetryHelper.ExecuteAsync( + _ => + { + attempts++; + return Task.FromResult(attempts); + }, + NoDelay(maxRetryCount: 2, shouldRetryOnResult: _ => true)); + + result.ShouldBe(3); // the initial attempt + 2 retries, returned instead of throwing + attempts.ShouldBe(3); + } + + [Fact] + public async Task ExecuteAsync_Of_TResult_Should_Retry_On_Exception_And_Return_The_Result() + { + var attempts = 0; + + var result = await RetryHelper.ExecuteAsync( + _ => + { + attempts++; + if (attempts < 3) + { + throw new IOException(); + } + + return Task.FromResult("ok"); + }, + NoDelay()); + + result.ShouldBe("ok"); + attempts.ShouldBe(3); + } + + [Fact] + public async Task ExecuteAsync_Of_TResult_Should_Rethrow_The_Last_Exception_When_The_Retries_Are_Exhausted() + { + var attempts = 0; + + var exception = await Assert.ThrowsAsync(async () => + await RetryHelper.ExecuteAsync( + _ => + { + attempts++; + throw new InvalidOperationException($"attempt-{attempts}"); + }, + NoDelay(maxRetryCount: 2))); + + attempts.ShouldBe(3); + exception.Message.ShouldBe("attempt-3"); + } + + [Fact] + public async Task ExecuteAsync_Of_TResult_Should_Not_Retry_When_ShouldRetryOnException_Returns_False() + { + var attempts = 0; + + await Assert.ThrowsAsync(async () => + await RetryHelper.ExecuteAsync( + _ => + { + attempts++; + throw new IOException(); + }, + NoDelay(maxRetryCount: 5, shouldRetryOnException: _ => false))); + + attempts.ShouldBe(1); + } + + [Fact] + public async Task ExecuteAsync_Of_TResult_Should_Stop_On_An_Unhandled_Exception_After_Retrying_The_Result() + { + var attempts = 0; + + await Assert.ThrowsAsync(async () => + await RetryHelper.ExecuteAsync( + _ => + { + attempts++; + if (attempts == 1) + { + return Task.FromResult(0); + } + + throw new UnauthorizedAccessException(); + }, + NoDelay( + maxRetryCount: 5, + shouldRetryOnResult: value => value == 0, + shouldRetryOnException: _ => false))); + + attempts.ShouldBe(2); + } + + [Fact] + public async Task ExecuteAsync_Of_TResult_Should_Report_The_Result_To_OnRetry_When_Retried_Because_Of_The_Result() + { + var reported = new List>(); + + var result = await RetryHelper.ExecuteAsync( + _ => Task.FromResult("bad"), + NoDelay(maxRetryCount: 1, shouldRetryOnResult: value => value == "bad", onRetry: attempt => { reported.Add(attempt); return Task.CompletedTask; })); + + result.ShouldBe("bad"); + reported.Count.ShouldBe(1); + reported[0].RetryCount.ShouldBe(1); + reported[0].Result.ShouldBe("bad"); + reported[0].Exception.ShouldBeNull(); + } + + [Fact] + public async Task ExecuteAsync_Of_TResult_Should_Report_The_Exception_To_OnRetry_When_Retried_Because_Of_An_Exception() + { + var reported = new List>(); + var attempts = 0; + + var result = await RetryHelper.ExecuteAsync( + _ => + { + attempts++; + if (attempts == 1) + { + throw new IOException("io-failed"); + } + + return Task.FromResult("ok"); + }, + NoDelay(maxRetryCount: 1, onRetry: attempt => { reported.Add(attempt); return Task.CompletedTask; })); + + result.ShouldBe("ok"); + reported.Count.ShouldBe(1); + reported[0].RetryCount.ShouldBe(1); + reported[0].Exception.ShouldBeOfType(); + reported[0].Result.ShouldBeNull(); + } + + [Fact] + public async Task ExecuteAsync_Of_TResult_Should_Pass_The_CancellationToken_To_The_Action() + { + using var cancellationTokenSource = new CancellationTokenSource(); + var received = CancellationToken.None; + + await RetryHelper.ExecuteAsync( + cancellationToken => + { + received = cancellationToken; + return Task.FromResult(1); + }, + NoDelay(), + cancellationTokenSource.Token); + + received.ShouldBe(cancellationTokenSource.Token); + } + + [Fact] + public async Task ExecuteAsync_Of_TResult_Should_Throw_When_The_Action_Is_Null() + { + await Assert.ThrowsAsync(async () => + await RetryHelper.ExecuteAsync(null!, NoDelay())); + } + + [Fact] + public async Task ExecuteAsync_Of_TResult_Should_Work_Without_Options() + { + var result = await RetryHelper.ExecuteAsync(_ => Task.FromResult("ok")); + + result.ShouldBe("ok"); + } + + #endregion + + #region Disposing and unlimited retries + + [Fact] + public async Task ExecuteAsync_Of_TResult_Should_Dispose_A_Retried_Result() + { + var disposed = new List(); + var attempts = 0; + + var result = await RetryHelper.ExecuteAsync( + _ => + { + attempts++; + return Task.FromResult(new DisposableResult(attempts, disposed)); + }, + NoDelay(maxRetryCount: 5, shouldRetryOnResult: value => value.Id < 3)); + + result.Id.ShouldBe(3); + disposed.ShouldBe(new[] { 1, 2 }); // the returned one is not disposed + } + + [Fact] + public async Task ExecuteAsync_Of_TResult_Should_Not_Dispose_A_Result_That_Is_Not_Retried() + { + var disposed = new List(); + + var result = await RetryHelper.ExecuteAsync( + _ => Task.FromResult(new DisposableResult(1, disposed)), + NoDelay()); + + result.Id.ShouldBe(1); + disposed.ShouldBeEmpty(); + } + + [Fact] + public async Task ExecuteAsync_Of_TResult_Should_Not_Fail_When_Disposing_The_Retried_Result_Throws() + { + var attempts = 0; + + var result = await RetryHelper.ExecuteAsync( + _ => + { + attempts++; + return Task.FromResult(new ThrowingDisposableResult(attempts)); + }, + NoDelay(maxRetryCount: 5, shouldRetryOnResult: value => value.Id < 3)); + + result.Id.ShouldBe(3); + attempts.ShouldBe(3); + } + + [Fact] + public async Task ExecuteAsync_Of_TResult_Should_Dispose_The_Result_When_ShouldRetryOnResult_Throws() + { + var disposed = new List(); + + await Assert.ThrowsAsync(async () => + await RetryHelper.ExecuteAsync( + _ => Task.FromResult(new DisposableResult(1, disposed)), + NoDelay( + maxRetryCount: 1, + shouldRetryOnResult: _ => throw new InvalidOperationException("predicate failed"), + shouldRetryOnException: _ => false))); + + disposed.ShouldBe(new[] { 1 }); + } + + [Fact] + public async Task ExecuteAsync_Of_TResult_Should_Retry_The_Action_When_ShouldRetryOnResult_Throws() + { + var attempts = 0; + + await Assert.ThrowsAsync(async () => + await RetryHelper.ExecuteAsync( + _ => + { + attempts++; + return Task.FromResult(1); + }, + NoDelay( + maxRetryCount: 2, + shouldRetryOnResult: _ => throw new InvalidOperationException("predicate failed")))); + + // A throwing result predicate counts as a failed attempt. + attempts.ShouldBe(3); + } + + [Fact] + public async Task ExecuteAsync_Of_TResult_Should_Dispose_The_Result_When_The_DelayFactory_Throws() + { + var disposed = new List(); + + await Assert.ThrowsAsync(async () => + await RetryHelper.ExecuteAsync( + _ => Task.FromResult(new DisposableResult(1, disposed)), + new RetryOptions + { + MaxRetryCount = 2, + DelayFactory = _ => throw new FormatException(), + ShouldRetryOnResult = _ => true + })); + + disposed.ShouldBe(new[] { 1 }); + } + + [Fact] + public async Task ExecuteAsync_Of_TResult_Should_Dispose_The_Result_When_OnRetry_Throws() + { + var disposed = new List(); + + await Assert.ThrowsAsync(async () => + await RetryHelper.ExecuteAsync( + _ => Task.FromResult(new DisposableResult(1, disposed)), + NoDelay( + maxRetryCount: 2, + shouldRetryOnResult: _ => true, + onRetry: _ => throw new FormatException()))); + + disposed.ShouldBe(new[] { 1 }); + } + + [Fact] + public async Task ExecuteAsync_Of_TResult_Should_Dispose_The_Result_When_ShouldRetryOnException_Throws() + { + var disposed = new List(); + + await Assert.ThrowsAsync(async () => + await RetryHelper.ExecuteAsync( + _ => Task.FromResult(new DisposableResult(1, disposed)), + NoDelay( + maxRetryCount: 2, + shouldRetryOnResult: _ => throw new InvalidOperationException(), + shouldRetryOnException: _ => throw new FormatException()))); + + disposed.ShouldBe(new[] { 1 }); + } + + [Fact] + public async Task ExecuteAsync_Of_TResult_Should_Prefer_IAsyncDisposable_Over_IDisposable() + { + var log = new List(); + var attempts = 0; + + await RetryHelper.ExecuteAsync( + _ => + { + attempts++; + return Task.FromResult(new BothDisposableResult(attempts, log)); + }, + NoDelay(maxRetryCount: 3, shouldRetryOnResult: value => value.Id < 2)); + + log.ShouldBe(new[] { "async:1" }); + } + + [Fact] + public async Task ExecuteAsync_Should_Keep_Retrying_When_MaxRetryCount_Is_The_Maximum() + { + var attempts = 0; + + await RetryHelper.ExecuteAsync( + _ => + { + attempts++; + if (attempts < 5) + { + throw new InvalidOperationException(); + } + + return Task.CompletedTask; + }, + NoDelay(maxRetryCount: int.MaxValue)); + + attempts.ShouldBe(5); + } + + private class DisposableResult : IDisposable + { + public int Id { get; } + + private readonly List _disposed; + + public DisposableResult(int id, List disposed) + { + Id = id; + _disposed = disposed; + } + + public void Dispose() + { + _disposed.Add(Id); + } + } + + private class BothDisposableResult : IDisposable, IAsyncDisposable + { + public int Id { get; } + + private readonly List _log; + + public BothDisposableResult(int id, List log) + { + Id = id; + _log = log; + } + + public void Dispose() + { + _log.Add($"sync:{Id}"); + } + + public ValueTask DisposeAsync() + { + _log.Add($"async:{Id}"); + return default; + } + } + + private class ThrowingDisposableResult : IDisposable + { + public int Id { get; } + + public ThrowingDisposableResult(int id) + { + Id = id; + } + + public void Dispose() + { + throw new InvalidOperationException("dispose failed"); + } + } + + #endregion +} diff --git a/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/Book.cs b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/Book.cs new file mode 100644 index 0000000000..6211160df4 --- /dev/null +++ b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/Book.cs @@ -0,0 +1,23 @@ +using System; +using Volo.Abp.Domain.Entities; + +namespace Volo.Abp.Application.Services.QueryProjection; + +public class Book : Entity +{ + public string Name { get; set; } = default!; + + public int Price { get; set; } + + public Book() + { + + } + + public Book(Guid id, string name, int price) + : base(id) + { + Name = name; + Price = price; + } +} diff --git a/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookAbstractKeyAppService.cs b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookAbstractKeyAppService.cs new file mode 100644 index 0000000000..1110ff841e --- /dev/null +++ b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookAbstractKeyAppService.cs @@ -0,0 +1,27 @@ +using System; +using System.Linq; +using System.Threading.Tasks; +using Volo.Abp.Domain.Repositories; + +namespace Volo.Abp.Application.Services.QueryProjection; + +public class BookAbstractKeyAppService : AbstractKeyReadOnlyAppService +{ + public BookAbstractKeyAppService(IReadOnlyRepository repository) + : base(repository) + { + + } + + protected override async Task GetEntityByIdAsync(Guid id) + { + var query = await ReadOnlyRepository.GetQueryableAsync(); + + return await AsyncExecuter.FirstAsync(query, book => book.Id == id); + } + + protected override IQueryable ApplyDefaultSorting(IQueryable query) + { + return query.OrderBy(book => book.Id); + } +} diff --git a/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookAbstractKeyProjectingAppService.cs b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookAbstractKeyProjectingAppService.cs new file mode 100644 index 0000000000..c6bcf8dbce --- /dev/null +++ b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookAbstractKeyProjectingAppService.cs @@ -0,0 +1,35 @@ +#nullable enable +using System; +using System.Linq; +using System.Threading.Tasks; +using Volo.Abp.Domain.Repositories; + +namespace Volo.Abp.Application.Services.QueryProjection; + +public class BookAbstractKeyProjectingAppService : AbstractKeyReadOnlyAppService +{ + public BookAbstractKeyProjectingAppService(IReadOnlyRepository repository) + : base(repository) + { + + } + + protected override async Task GetEntityByIdAsync(Guid id) + { + var query = await ReadOnlyRepository.GetQueryableAsync(); + + return await AsyncExecuter.FirstAsync(query, book => book.Id == id); + } + + protected override async Task?> CreateEntityQueryOrNullAsync(Guid id) + { + var query = await ReadOnlyRepository.GetQueryableAsync(); + + return query.Where(book => book.Id == id); + } + + protected override IQueryable ApplyDefaultSorting(IQueryable query) + { + return query.OrderBy(book => book.Id); + } +} diff --git a/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookAppService.cs b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookAppService.cs new file mode 100644 index 0000000000..c3ae530e7d --- /dev/null +++ b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookAppService.cs @@ -0,0 +1,13 @@ +using System; +using Volo.Abp.Domain.Repositories; + +namespace Volo.Abp.Application.Services.QueryProjection; + +public class BookAppService : CrudAppService +{ + public BookAppService(IRepository repository) + : base(repository) + { + + } +} diff --git a/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookAsyncProjectionAppService.cs b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookAsyncProjectionAppService.cs new file mode 100644 index 0000000000..21f7516116 --- /dev/null +++ b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookAsyncProjectionAppService.cs @@ -0,0 +1,46 @@ +#nullable enable +using System; +using System.Linq; +using System.Threading.Tasks; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Domain.Repositories; + +namespace Volo.Abp.Application.Services.QueryProjection; + +public class BookAsyncProjectionAppService : CrudAppService +{ + public const string Marker = "-async"; + + private readonly IBookNameSuffixProvider _suffixProvider; + + public BookAsyncProjectionAppService( + IRepository repository, + IBookNameSuffixProvider suffixProvider) + : base(repository) + { + _suffixProvider = suffixProvider; + } + + protected override async Task?> CreateGetOutputDtoQueryOrNullAsync(Guid id) + { + var query = await Repository.GetQueryableAsync(); + + return await ProjectAsync(query.Where(book => book.Id == id)); + } + + protected override async Task?> CreateGetListOutputDtoQueryOrNullAsync(IQueryable query) + { + return await ProjectAsync(query); + } + + private async Task> ProjectAsync(IQueryable query) + { + var suffix = await _suffixProvider.GetAsync(); + + return query.Select(book => new BookDto + { + Id = book.Id, + Name = book.Name + suffix + }); + } +} diff --git a/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookCustomizedAppService.cs b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookCustomizedAppService.cs new file mode 100644 index 0000000000..f5df26baaa --- /dev/null +++ b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookCustomizedAppService.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Volo.Abp.Domain.Repositories; + +namespace Volo.Abp.Application.Services.QueryProjection; + +public class BookCustomizedAppService : CrudAppService +{ + public const string Marker = "-customized"; + + public BookCustomizedAppService(IRepository repository) + : base(repository) + { + + } + + protected override async Task GetEntityByIdAsync(Guid id) + { + var book = await base.GetEntityByIdAsync(id); + book.Name += Marker; + return book; + } + + protected override Task MapToGetOutputDtoAsync(Book entity) + { + return Task.FromResult(new BookDto { Id = entity.Id, Name = entity.Name + Marker }); + } + + protected override Task> MapToGetListOutputDtosAsync(List entities) + { + return Task.FromResult(entities.ConvertAll(entity => new BookDto { Id = entity.Id, Name = entity.Name + Marker })); + } +} diff --git a/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookDetailAppService.cs b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookDetailAppService.cs new file mode 100644 index 0000000000..ec2139a118 --- /dev/null +++ b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookDetailAppService.cs @@ -0,0 +1,15 @@ +using System; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Domain.Repositories; + +namespace Volo.Abp.Application.Services.QueryProjection; + +public class BookDetailAppService : + ReadOnlyAppService +{ + public BookDetailAppService(IReadOnlyRepository repository) + : base(repository) + { + + } +} diff --git a/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookDetailDto.cs b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookDetailDto.cs new file mode 100644 index 0000000000..f278d6d721 --- /dev/null +++ b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookDetailDto.cs @@ -0,0 +1,9 @@ +using System; +using Volo.Abp.Application.Dtos; + +namespace Volo.Abp.Application.Services.QueryProjection; + +public class BookDetailDto : EntityDto +{ + public string Name { get; set; } = default!; +} diff --git a/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookDetailProjector.cs b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookDetailProjector.cs new file mode 100644 index 0000000000..d7e3e19966 --- /dev/null +++ b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookDetailProjector.cs @@ -0,0 +1,18 @@ +using System.Linq; +using Volo.Abp.ObjectMapping; + +namespace Volo.Abp.Application.Services.QueryProjection; + +public class BookDetailProjector : IQueryProjector +{ + public const string Marker = "-detail"; + + public IQueryable ProjectTo(IQueryable source) + { + return source.Select(book => new BookDetailDto + { + Id = book.Id, + Name = book.Name + Marker + }); + } +} diff --git a/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookDto.cs b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookDto.cs new file mode 100644 index 0000000000..08a2117ec2 --- /dev/null +++ b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookDto.cs @@ -0,0 +1,9 @@ +using System; +using Volo.Abp.Application.Dtos; + +namespace Volo.Abp.Application.Services.QueryProjection; + +public class BookDto : EntityDto +{ + public string Name { get; set; } = default!; +} diff --git a/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookLiteAppService.cs b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookLiteAppService.cs new file mode 100644 index 0000000000..c5b28e058b --- /dev/null +++ b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookLiteAppService.cs @@ -0,0 +1,13 @@ +using System; +using Volo.Abp.Domain.Repositories; + +namespace Volo.Abp.Application.Services.QueryProjection; + +public class BookLiteAppService : CrudAppService +{ + public BookLiteAppService(IRepository repository) + : base(repository) + { + + } +} diff --git a/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookLiteDto.cs b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookLiteDto.cs new file mode 100644 index 0000000000..7ab0408c85 --- /dev/null +++ b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookLiteDto.cs @@ -0,0 +1,9 @@ +using System; +using Volo.Abp.Application.Dtos; + +namespace Volo.Abp.Application.Services.QueryProjection; + +public class BookLiteDto : EntityDto +{ + public string Name { get; set; } = default!; +} diff --git a/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookObjectMapper.cs b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookObjectMapper.cs new file mode 100644 index 0000000000..c398f9e25f --- /dev/null +++ b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookObjectMapper.cs @@ -0,0 +1,48 @@ +using Volo.Abp.DependencyInjection; +using Volo.Abp.ObjectMapping; + +namespace Volo.Abp.Application.Services.QueryProjection; + +public class BookObjectMapper : + IObjectMapper, + IObjectMapper, + IObjectMapper, + ITransientDependency +{ + public const string Marker = "-mapped"; + + public BookDto Map(Book source) + { + return new BookDto { Id = source.Id, Name = source.Name + Marker }; + } + + public BookDto Map(Book source, BookDto destination) + { + destination.Id = source.Id; + destination.Name = source.Name + Marker; + return destination; + } + + BookLiteDto IObjectMapper.Map(Book source) + { + return new BookLiteDto { Id = source.Id, Name = source.Name + Marker }; + } + + BookLiteDto IObjectMapper.Map(Book source, BookLiteDto destination) + { + destination.Id = source.Id; + destination.Name = source.Name + Marker; + return destination; + } + + Book IObjectMapper.Map(BookDto source) + { + return new Book(source.Id, source.Name, 0); + } + + Book IObjectMapper.Map(BookDto source, Book destination) + { + destination.Name = source.Name; + return destination; + } +} diff --git a/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookPolicyCheckedAppService.cs b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookPolicyCheckedAppService.cs new file mode 100644 index 0000000000..ee8e73db14 --- /dev/null +++ b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookPolicyCheckedAppService.cs @@ -0,0 +1,29 @@ +using System; +using System.Threading.Tasks; +using Volo.Abp.Domain.Repositories; + +namespace Volo.Abp.Application.Services.QueryProjection; + +public class BookPolicyCheckedException : Exception +{ + +} + +public class BookPolicyCheckedAppService : CrudAppService +{ + public BookPolicyCheckedAppService(IRepository repository) + : base(repository) + { + + } + + protected override Task CheckGetPolicyAsync() + { + throw new BookPolicyCheckedException(); + } + + protected override Task CheckGetListPolicyAsync() + { + throw new BookPolicyCheckedException(); + } +} diff --git a/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookProjector.cs b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookProjector.cs new file mode 100644 index 0000000000..fa292161fc --- /dev/null +++ b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookProjector.cs @@ -0,0 +1,18 @@ +using System.Linq; +using Volo.Abp.ObjectMapping; + +namespace Volo.Abp.Application.Services.QueryProjection; + +public class BookProjector : IQueryProjector +{ + public const string Marker = "-projected"; + + public IQueryable ProjectTo(IQueryable source) + { + return source.Select(book => new BookDto + { + Id = book.Id, + Name = book.Name + Marker + }); + } +} diff --git a/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookReadOnlyAppService.cs b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookReadOnlyAppService.cs new file mode 100644 index 0000000000..9a80d741fb --- /dev/null +++ b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookReadOnlyAppService.cs @@ -0,0 +1,13 @@ +using System; +using Volo.Abp.Domain.Repositories; + +namespace Volo.Abp.Application.Services.QueryProjection; + +public class BookReadOnlyAppService : ReadOnlyAppService +{ + public BookReadOnlyAppService(IReadOnlyRepository repository) + : base(repository) + { + + } +} diff --git a/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookRepository.cs b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookRepository.cs new file mode 100644 index 0000000000..75da4e0da6 --- /dev/null +++ b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookRepository.cs @@ -0,0 +1,106 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Threading; +using System.Threading.Tasks; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Domain.Entities; +using Volo.Abp.Domain.Repositories; + +namespace Volo.Abp.Application.Services.QueryProjection; + +[ExposeServices( + typeof(IRepository), + typeof(IReadOnlyRepository), + typeof(IReadOnlyRepository))] +public class BookRepository : RepositoryBase, ISingletonDependency +{ + private readonly List _books = new(); + + public BookRepository() + : base("InMemory") + { + + } + + public override Task> GetQueryableAsync() + { + return Task.FromResult(_books.AsQueryable()); + } + + [Obsolete("Use GetQueryableAsync method.")] + protected override IQueryable GetQueryable() + { + return _books.AsQueryable(); + } + + public override Task GetAsync(Guid id, bool includeDetails = true, CancellationToken cancellationToken = default) + { + var book = _books.FirstOrDefault(x => x.Id == id); + if (book == null) + { + throw new EntityNotFoundException(typeof(Book), id); + } + + return Task.FromResult(book); + } + + public override Task FindAsync(Guid id, bool includeDetails = true, CancellationToken cancellationToken = default) + { + return Task.FromResult(_books.FirstOrDefault(x => x.Id == id)); + } + + public override Task FindAsync(Expression> predicate, bool includeDetails = true, CancellationToken cancellationToken = default) + { + return Task.FromResult(_books.AsQueryable().FirstOrDefault(predicate)); + } + + public override Task> GetListAsync(bool includeDetails = false, CancellationToken cancellationToken = default) + { + return Task.FromResult(_books.ToList()); + } + + public override Task> GetListAsync(Expression> predicate, bool includeDetails = false, CancellationToken cancellationToken = default) + { + return Task.FromResult(_books.AsQueryable().Where(predicate).ToList()); + } + + public override Task> GetPagedListAsync(int skipCount, int maxResultCount, string sorting, bool includeDetails = false, CancellationToken cancellationToken = default) + { + return Task.FromResult(_books.Skip(skipCount).Take(maxResultCount).ToList()); + } + + public override Task GetCountAsync(CancellationToken cancellationToken = default) + { + return Task.FromResult((long)_books.Count); + } + + public override Task InsertAsync(Book entity, bool autoSave = false, CancellationToken cancellationToken = default) + { + _books.Add(entity); + return Task.FromResult(entity); + } + + public override Task UpdateAsync(Book entity, bool autoSave = false, CancellationToken cancellationToken = default) + { + return Task.FromResult(entity); + } + + public override Task DeleteAsync(Book entity, bool autoSave = false, CancellationToken cancellationToken = default) + { + _books.Remove(entity); + return Task.CompletedTask; + } + + public override Task DeleteAsync(Expression> predicate, bool autoSave = false, CancellationToken cancellationToken = default) + { + _books.RemoveAll(new Predicate(predicate.Compile())); + return Task.CompletedTask; + } + + public override Task DeleteDirectAsync(Expression> predicate, CancellationToken cancellationToken = default) + { + return DeleteAsync(predicate); + } +} diff --git a/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookStructAppService.cs b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookStructAppService.cs new file mode 100644 index 0000000000..34b4945b85 --- /dev/null +++ b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookStructAppService.cs @@ -0,0 +1,13 @@ +using System; +using Volo.Abp.Domain.Repositories; + +namespace Volo.Abp.Application.Services.QueryProjection; + +public class BookStructAppService : ReadOnlyAppService +{ + public BookStructAppService(IReadOnlyRepository repository) + : base(repository) + { + + } +} diff --git a/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookStructDto.cs b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookStructDto.cs new file mode 100644 index 0000000000..f2690bb139 --- /dev/null +++ b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookStructDto.cs @@ -0,0 +1,10 @@ +using System; + +namespace Volo.Abp.Application.Services.QueryProjection; + +public struct BookStructDto +{ + public Guid Id { get; set; } + + public string Name { get; set; } +} diff --git a/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookStructProjector.cs b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookStructProjector.cs new file mode 100644 index 0000000000..4ae26a4b11 --- /dev/null +++ b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookStructProjector.cs @@ -0,0 +1,16 @@ +using System.Linq; +using Volo.Abp.ObjectMapping; + +namespace Volo.Abp.Application.Services.QueryProjection; + +public class BookStructProjector : IQueryProjector +{ + public IQueryable ProjectTo(IQueryable source) + { + return source.Select(book => new BookStructDto + { + Id = book.Id, + Name = book.Name + }); + } +} diff --git a/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookWithoutProjectionAppService.cs b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookWithoutProjectionAppService.cs new file mode 100644 index 0000000000..928c8fee66 --- /dev/null +++ b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/BookWithoutProjectionAppService.cs @@ -0,0 +1,33 @@ +#nullable enable +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Volo.Abp.Domain.Repositories; +using Volo.Abp.ObjectMapping; + +namespace Volo.Abp.Application.Services.QueryProjection; + +public class BookWithoutProjectionAppService : CrudAppService +{ + public const string Marker = "-not-projected"; + + protected override IQueryProjector? GetOutputDtoQueryProjector => null; + + protected override IQueryProjector? GetListOutputDtoQueryProjector => null; + + public BookWithoutProjectionAppService(IRepository repository) + : base(repository) + { + + } + + protected override Task MapToGetOutputDtoAsync(Book entity) + { + return Task.FromResult(new BookDto { Id = entity.Id, Name = entity.Name + Marker }); + } + + protected override Task> MapToGetListOutputDtosAsync(List entities) + { + return Task.FromResult(entities.ConvertAll(entity => new BookDto { Id = entity.Id, Name = entity.Name + Marker })); + } +} diff --git a/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/IBookNameSuffixProvider.cs b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/IBookNameSuffixProvider.cs new file mode 100644 index 0000000000..747a93c15d --- /dev/null +++ b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/IBookNameSuffixProvider.cs @@ -0,0 +1,19 @@ +using System.Threading.Tasks; +using Volo.Abp.DependencyInjection; + +namespace Volo.Abp.Application.Services.QueryProjection; + +public interface IBookNameSuffixProvider +{ + Task GetAsync(); +} + +public class BookNameSuffixProvider : IBookNameSuffixProvider, ITransientDependency +{ + public async Task GetAsync() + { + await Task.Yield(); + + return BookAsyncProjectionAppService.Marker; + } +} diff --git a/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/QueryProjection_Tests.cs b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/QueryProjection_Tests.cs new file mode 100644 index 0000000000..425021fb03 --- /dev/null +++ b/framework/test/Volo.Abp.Ddd.Application.Tests/Volo/Abp/Application/Services/QueryProjection/QueryProjection_Tests.cs @@ -0,0 +1,196 @@ +using System; +using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using Shouldly; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Domain.Entities; +using Volo.Abp.Domain.Repositories; +using Volo.Abp.ObjectMapping; +using Xunit; + +namespace Volo.Abp.Application.Services.QueryProjection; + +public class QueryProjection_Tests : AbpDddApplicationTestBase +{ + private readonly Guid _bookId = Guid.NewGuid(); + + public QueryProjection_Tests() + { + var repository = GetRequiredService>(); + repository.InsertAsync(new Book(_bookId, "Hitchhiker's Guide", 42)).GetAwaiter().GetResult(); + } + + [Fact] + public void Should_Resolve_The_Projector_Independent_From_The_Class_Name() + { + ServiceProvider.GetService>() + .ShouldBeOfType(); + } + + [Fact] + public async Task Should_Project_On_The_Query_For_CrudAppService() + { + var appService = GetRequiredService(); + + (await appService.GetAsync(_bookId)).Name.ShouldEndWith(BookProjector.Marker); + (await appService.GetListAsync(new PagedAndSortedResultRequestDto())) + .Items[0].Name.ShouldEndWith(BookProjector.Marker); + } + + [Fact] + public async Task Should_Project_On_The_Query_For_ReadOnlyAppService() + { + var appService = GetRequiredService(); + + (await appService.GetAsync(_bookId)).Name.ShouldEndWith(BookProjector.Marker); + (await appService.GetListAsync(new PagedAndSortedResultRequestDto())) + .Items[0].Name.ShouldEndWith(BookProjector.Marker); + } + + [Fact] + public async Task Should_Throw_EntityNotFoundException_If_The_Projected_Entity_Does_Not_Exist() + { + var appService = GetRequiredService(); + + await Should.ThrowAsync(async () => await appService.GetAsync(Guid.NewGuid())); + } + + [Fact] + public async Task Should_Use_The_Object_Mapper_If_No_Projector_Was_Registered() + { + var appService = GetRequiredService(); + + (await appService.GetAsync(_bookId)).Name.ShouldEndWith(BookObjectMapper.Marker); + (await appService.GetListAsync(new PagedAndSortedResultRequestDto())) + .Items[0].Name.ShouldEndWith(BookObjectMapper.Marker); + } + + [Fact] + public async Task Should_Use_The_Entity_Based_Overrides_If_The_Projection_Was_Disabled() + { + var appService = GetRequiredService(); + + (await appService.GetAsync(_bookId)).Name.ShouldEndWith(BookWithoutProjectionAppService.Marker); + (await appService.GetListAsync(new PagedAndSortedResultRequestDto())) + .Items[0].Name.ShouldEndWith(BookWithoutProjectionAppService.Marker); + } + + [Fact] + public async Task Should_Not_Use_The_Entity_Based_Overrides_While_Projecting() + { + var appService = GetRequiredService(); + + var dto = await appService.GetAsync(_bookId); + + dto.Name.ShouldEndWith(BookProjector.Marker); + dto.Name.ShouldNotContain(BookCustomizedAppService.Marker); + + var items = (await appService.GetListAsync(new PagedAndSortedResultRequestDto())).Items; + + items[0].Name.ShouldEndWith(BookProjector.Marker); + items[0].Name.ShouldNotContain(BookCustomizedAppService.Marker); + } + + [Fact] + public async Task Should_Use_The_Object_Mapper_If_The_Entity_Query_Can_Not_Be_Created() + { + var appService = GetRequiredService(); + + //GetAsync has no query to project, it falls back to GetEntityByIdAsync + (await appService.GetAsync(_bookId)).Name.ShouldEndWith(BookObjectMapper.Marker); + + //GetListAsync always has a query, so it is still projected + (await appService.GetListAsync(new PagedAndSortedResultRequestDto())) + .Items[0].Name.ShouldEndWith(BookProjector.Marker); + } + + [Fact] + public async Task Should_Use_The_Asynchronously_Created_Projection_Query() + { + var appService = GetRequiredService(); + + (await appService.GetAsync(_bookId)).Name.ShouldEndWith(BookAsyncProjectionAppService.Marker); + (await appService.GetListAsync(new PagedAndSortedResultRequestDto())) + .Items[0].Name.ShouldEndWith(BookAsyncProjectionAppService.Marker); + } + + [Fact] + public async Task Should_Throw_EntityNotFoundException_From_An_Overridden_Projection_Query() + { + var appService = GetRequiredService(); + + await Should.ThrowAsync(async () => await appService.GetAsync(Guid.NewGuid())); + } + + [Fact] + public async Task Should_Throw_EntityNotFoundException_For_A_Value_Type_Dto() + { + var appService = GetRequiredService(); + + (await appService.GetAsync(_bookId)).Name.ShouldBe("Hitchhiker's Guide"); + + await Should.ThrowAsync(async () => await appService.GetAsync(Guid.NewGuid())); + } + + [Fact] + public async Task Should_Not_Project_On_The_Create_And_Update_Paths() + { + var appService = GetRequiredService(); + + var created = await appService.CreateAsync(new BookDto { Name = "New Book" }); + created.Name.ShouldEndWith(BookObjectMapper.Marker); + + var updated = await appService.UpdateAsync(created.Id, new BookDto { Name = "Updated Book" }); + updated.Name.ShouldEndWith(BookObjectMapper.Marker); + } + + [Fact] + public async Task Should_Use_A_Different_Projector_For_The_Get_And_The_List() + { + var appService = GetRequiredService(); + + (await appService.GetAsync(_bookId)).Name.ShouldEndWith(BookDetailProjector.Marker); + (await appService.GetListAsync(new PagedAndSortedResultRequestDto())) + .Items[0].Name.ShouldEndWith(BookProjector.Marker); + } + + [Fact] + public async Task Should_Apply_Paging_And_Sorting_Before_Projecting() + { + var repository = GetRequiredService>(); + await repository.InsertAsync(new Book(Guid.NewGuid(), "A Book", 1)); + await repository.InsertAsync(new Book(Guid.NewGuid(), "Z Book", 2)); + + var appService = GetRequiredService(); + + var firstPage = await appService.GetListAsync( + new PagedAndSortedResultRequestDto { MaxResultCount = 1, Sorting = "Name" }); + + firstPage.TotalCount.ShouldBe(3); + firstPage.Items.Count.ShouldBe(1); + firstPage.Items[0].Name.ShouldBe("A Book" + BookProjector.Marker); + + var secondPage = await appService.GetListAsync( + new PagedAndSortedResultRequestDto { MaxResultCount = 1, SkipCount = 1, Sorting = "Name" }); + + secondPage.Items[0].Name.ShouldBe("Hitchhiker's Guide" + BookProjector.Marker); + } + + [Fact] + public async Task Should_Project_A_Single_Entity_From_An_AbstractKey_Application_Service() + { + var appService = GetRequiredService(); + + (await appService.GetAsync(_bookId)).Name.ShouldEndWith(BookProjector.Marker); + } + + [Fact] + public async Task Should_Check_The_Policies_While_Projecting() + { + var appService = GetRequiredService(); + + await Should.ThrowAsync(async () => await appService.GetAsync(_bookId)); + await Should.ThrowAsync(async () => + await appService.GetListAsync(new PagedAndSortedResultRequestDto())); + } +} diff --git a/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/AbpEntityFrameworkCoreTestModule.cs b/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/AbpEntityFrameworkCoreTestModule.cs index 27992ed124..fae245bc3a 100644 --- a/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/AbpEntityFrameworkCoreTestModule.cs +++ b/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/AbpEntityFrameworkCoreTestModule.cs @@ -7,6 +7,7 @@ using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Autofac; using Volo.Abp.Data; using Volo.Abp.Domain.Repositories; +using Volo.Abp.EntityFrameworkCore.Applications; using Volo.Abp.EntityFrameworkCore.Domain; using Volo.Abp.EntityFrameworkCore.Sqlite; using Volo.Abp.EntityFrameworkCore.TestApp.FifthContext; @@ -92,6 +93,7 @@ public class AbpEntityFrameworkCoreTestModule : AbpModule options.Configure(abpDbContextConfigurationContext => { abpDbContextConfigurationContext.UseSqlite().AddAbpDbContextOptionsExtension(); + abpDbContextConfigurationContext.DbContextOptions.AddInterceptors(new SqlCommandCapture()); }); }); } diff --git a/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Applications/EntityWithIntPkProjectionAppService.cs b/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Applications/EntityWithIntPkProjectionAppService.cs new file mode 100644 index 0000000000..cc6176cddd --- /dev/null +++ b/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Applications/EntityWithIntPkProjectionAppService.cs @@ -0,0 +1,14 @@ +using Volo.Abp.Application.Services; +using Volo.Abp.Domain.Repositories; +using Volo.Abp.TestApp.Domain; + +namespace Volo.Abp.EntityFrameworkCore.Applications; + +public class EntityWithIntPkProjectionAppService : ReadOnlyAppService +{ + public EntityWithIntPkProjectionAppService(IReadOnlyRepository repository) + : base(repository) + { + + } +} diff --git a/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Applications/EntityWithIntPkProjectionDto.cs b/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Applications/EntityWithIntPkProjectionDto.cs new file mode 100644 index 0000000000..f6bbebe850 --- /dev/null +++ b/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Applications/EntityWithIntPkProjectionDto.cs @@ -0,0 +1,8 @@ +using Volo.Abp.Application.Dtos; + +namespace Volo.Abp.EntityFrameworkCore.Applications; + +public class EntityWithIntPkProjectionDto : EntityDto +{ + public string Name { get; set; } +} diff --git a/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Applications/EntityWithIntPkProjector.cs b/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Applications/EntityWithIntPkProjector.cs new file mode 100644 index 0000000000..5e97ceca51 --- /dev/null +++ b/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Applications/EntityWithIntPkProjector.cs @@ -0,0 +1,17 @@ +using System.Linq; +using Volo.Abp.ObjectMapping; +using Volo.Abp.TestApp.Domain; + +namespace Volo.Abp.EntityFrameworkCore.Applications; + +public class EntityWithIntPkProjector : IQueryProjector +{ + public IQueryable ProjectTo(IQueryable source) + { + return source.Select(entity => new EntityWithIntPkProjectionDto + { + Id = entity.Id, + Name = entity.Name + }); + } +} diff --git a/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Applications/PersonProjectionAppService.cs b/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Applications/PersonProjectionAppService.cs new file mode 100644 index 0000000000..fa51e9407f --- /dev/null +++ b/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Applications/PersonProjectionAppService.cs @@ -0,0 +1,15 @@ +using System; +using Volo.Abp.Application.Services; +using Volo.Abp.Domain.Repositories; +using Volo.Abp.TestApp.Domain; + +namespace Volo.Abp.EntityFrameworkCore.Applications; + +public class PersonProjectionAppService : ReadOnlyAppService +{ + public PersonProjectionAppService(IReadOnlyRepository repository) + : base(repository) + { + + } +} diff --git a/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Applications/PersonProjectionDto.cs b/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Applications/PersonProjectionDto.cs new file mode 100644 index 0000000000..57eef129d0 --- /dev/null +++ b/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Applications/PersonProjectionDto.cs @@ -0,0 +1,9 @@ +using System; +using Volo.Abp.Application.Dtos; + +namespace Volo.Abp.EntityFrameworkCore.Applications; + +public class PersonProjectionDto : EntityDto +{ + public string Name { get; set; } +} diff --git a/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Applications/PersonProjector.cs b/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Applications/PersonProjector.cs new file mode 100644 index 0000000000..d9abce7cd8 --- /dev/null +++ b/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Applications/PersonProjector.cs @@ -0,0 +1,17 @@ +using System.Linq; +using Volo.Abp.ObjectMapping; +using Volo.Abp.TestApp.Domain; + +namespace Volo.Abp.EntityFrameworkCore.Applications; + +public class PersonProjector : IQueryProjector +{ + public IQueryable ProjectTo(IQueryable source) + { + return source.Select(person => new PersonProjectionDto + { + Id = person.Id, + Name = person.Name + }); + } +} diff --git a/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Applications/PersonWithCityAppService.cs b/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Applications/PersonWithCityAppService.cs new file mode 100644 index 0000000000..f8a8ba01e5 --- /dev/null +++ b/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Applications/PersonWithCityAppService.cs @@ -0,0 +1,51 @@ +#nullable enable +using System; +using System.Linq; +using System.Threading.Tasks; +using Volo.Abp.Application.Services; +using Volo.Abp.Domain.Repositories; +using Volo.Abp.TestApp.Domain; + +namespace Volo.Abp.EntityFrameworkCore.Applications; + +//City is another aggregate root, so Person has no City navigation property to project. +public class PersonWithCityAppService : ReadOnlyAppService +{ + private readonly IReadOnlyRepository _cityRepository; + + public PersonWithCityAppService( + IReadOnlyRepository repository, + IReadOnlyRepository cityRepository) + : base(repository) + { + _cityRepository = cityRepository; + } + + protected override async Task?> CreateGetOutputDtoQueryOrNullAsync(Guid id) + { + var people = await CreateEntityQueryOrNullAsync(id); + + return people == null ? null : await JoinCitiesAsync(people); + } + + protected override async Task?> CreateGetListOutputDtoQueryOrNullAsync(IQueryable query) + { + return await JoinCitiesAsync(query); + } + + //left join, an inner join would drop the people without a city and break the total count + private async Task> JoinCitiesAsync(IQueryable people) + { + var cities = await _cityRepository.GetQueryableAsync(); + + return from person in people + join city in cities on person.CityId equals city.Id into personCities + from personCity in personCities.DefaultIfEmpty() + select new PersonWithCityDto + { + Id = person.Id, + Name = person.Name, + CityName = personCity != null ? personCity.Name : null + }; + } +} diff --git a/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Applications/PersonWithCityDto.cs b/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Applications/PersonWithCityDto.cs new file mode 100644 index 0000000000..dac278c7b6 --- /dev/null +++ b/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Applications/PersonWithCityDto.cs @@ -0,0 +1,12 @@ +#nullable enable +using System; +using Volo.Abp.Application.Dtos; + +namespace Volo.Abp.EntityFrameworkCore.Applications; + +public class PersonWithCityDto : EntityDto +{ + public string Name { get; set; } + + public string? CityName { get; set; } +} diff --git a/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Applications/QueryProjection_Tests.cs b/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Applications/QueryProjection_Tests.cs new file mode 100644 index 0000000000..d4410c15e7 --- /dev/null +++ b/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Applications/QueryProjection_Tests.cs @@ -0,0 +1,197 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using Shouldly; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Domain.Entities; +using Volo.Abp.Domain.Repositories; +using Volo.Abp.ObjectMapping; +using Volo.Abp.TestApp; +using Volo.Abp.TestApp.Application; +using Volo.Abp.Threading; +using Volo.Abp.TestApp.Domain; +using Xunit; + +namespace Volo.Abp.EntityFrameworkCore.Applications; + +public class QueryProjection_Tests : EntityFrameworkCoreTestBase +{ + private readonly PersonProjectionAppService _personProjectionAppService; + + public QueryProjection_Tests() + { + _personProjectionAppService = GetRequiredService(); + } + + [Fact] + public async Task Should_Get_A_Projected_Entity() + { + var dto = await _personProjectionAppService.GetAsync(TestDataBuilder.UserDouglasId); + + dto.Id.ShouldBe(TestDataBuilder.UserDouglasId); + dto.Name.ShouldBe("Douglas"); + } + + [Fact] + public async Task Should_Throw_EntityNotFoundException_For_A_Missing_Entity() + { + (await Should.ThrowAsync>( + async () => await _personProjectionAppService.GetAsync(Guid.NewGuid())) + ).EntityType.ShouldBe(typeof(Person)); + } + + [Fact] + public async Task Should_Get_A_Projected_List() + { + var result = await _personProjectionAppService.GetListAsync(new PagedAndSortedResultRequestDto()); + + result.TotalCount.ShouldBeGreaterThan(0); + result.Items.Count.ShouldBe((int)result.TotalCount); + result.Items.ShouldContain(x => x.Name == "Douglas"); + } + + [Fact] + public async Task Should_Get_A_Projected_Entity_With_A_Non_Guid_Key() + { + var appService = GetRequiredService(); + var entity = await WithUnitOfWorkAsync( + async () => await GetRequiredService>().FirstAsync()); + + (await appService.GetAsync(entity.Id)).Name.ShouldBe(entity.Name); + } + + [Fact] + public async Task Should_Apply_The_Soft_Delete_Filter_While_Projecting() + { + var result = await _personProjectionAppService.GetListAsync(new PagedAndSortedResultRequestDto()); + + result.Items.ShouldNotContain(x => x.Id == TestDataBuilder.UserJohnDeletedId); + } + + [Fact] + public async Task Should_Only_Select_The_Projected_Columns() + { + await WithUnitOfWorkAsync(async () => + { + var repository = GetRequiredService>(); + var projector = GetRequiredService>(); + + var sql = projector.ProjectTo(await repository.GetQueryableAsync()).ToQueryString(); + + sql.ShouldContain("\"Name\""); + sql.ShouldNotContain("\"Birthday\""); + sql.ShouldNotContain("\"ExtraProperties\""); + + //the data filters are still a part of the query + sql.ShouldContain("Is_Deleted"); + }); + } + + [Fact] + public async Task Should_Join_Another_Aggregate_While_Projecting() + { + var appService = GetRequiredService(); + + var dto = await appService.GetAsync(TestDataBuilder.UserDouglasId); + dto.CityName.ShouldBe("London"); + + var result = await appService.GetListAsync(new PagedAndSortedResultRequestDto()); + result.Items.ShouldContain(x => x.CityName == "London"); + } + + [Fact] + public async Task Should_Keep_The_Total_Count_While_Joining_Another_Aggregate() + { + await WithUnitOfWorkAsync(async () => + { + await GetRequiredService>() + .InsertAsync(new Person(Guid.NewGuid(), "PersonWithoutCity", 30), autoSave: true); + }); + + var result = await GetRequiredService() + .GetListAsync(new PagedAndSortedResultRequestDto()); + + result.Items.Count.ShouldBe((int)result.TotalCount); + result.Items.ShouldContain(x => x.Name == "PersonWithoutCity" && x.CityName == null); + } + + [Fact] + public async Task Should_Execute_The_Projected_Query_From_The_Application_Service() + { + System.Collections.Concurrent.ConcurrentQueue commands; + using (SqlCommandCapture.Begin(out commands)) + { + await GetRequiredService() + .GetListAsync(new PagedAndSortedResultRequestDto()); + } + + //the application service must run the projection itself, not materialize the entities first + var selects = commands.Where(x => x.Contains("FROM \"People\"") && !x.Contains("COUNT")).ToList(); + + var select = selects.ShouldHaveSingleItem(); + select.ShouldContain("\"Name\""); + select.ShouldNotContain("\"Birthday\""); + select.ShouldNotContain("\"ExtraProperties\""); + } + + [Fact] + public async Task Should_Apply_The_Multi_Tenancy_Filter_While_Projecting() + { + var result = await GetRequiredService() + .GetListAsync(new PagedAndSortedResultRequestDto()); + + result.Items.ShouldNotContain(x => x.Name.StartsWith(TestDataBuilder.TenantId1.ToString())); + } + + [Fact] + public async Task Should_Use_The_Ambient_Cancellation_Token_While_Projecting() + { + var cancellationTokenProvider = GetRequiredService(); + var appService = GetRequiredService(); + + //the entity path passes it through Repository.GetAsync, so the projected path must not regress + using (cancellationTokenProvider.Use(new CancellationToken(canceled: true))) + { + await Should.ThrowAsync(async () => + await appService.GetAsync(TestDataBuilder.UserDouglasId)); + } + } + + [Fact] + public async Task Should_Execute_The_Projected_Query_From_The_Application_Service_For_A_Single_Entity() + { + System.Collections.Concurrent.ConcurrentQueue commands; + using (SqlCommandCapture.Begin(out commands)) + { + await GetRequiredService().GetAsync(TestDataBuilder.UserDouglasId); + } + + var selects = commands.Where(x => x.Contains("FROM \"People\"")).ToList(); + + var select = selects.ShouldHaveSingleItem(); + select.ShouldContain("\"Name\""); + select.ShouldNotContain("\"Birthday\""); + select.ShouldNotContain("\"ExtraProperties\""); + } + + [Fact] + public async Task Should_Apply_The_Data_Filters_Of_The_Joined_Aggregate() + { + var cityRepository = GetRequiredService>(); + + await WithUnitOfWorkAsync(async () => + { + var london = await cityRepository.GetAsync(TestDataBuilder.LondonCityId); + await cityRepository.DeleteAsync(london, autoSave: true); + }); + + var result = await GetRequiredService() + .GetListAsync(new PagedAndSortedResultRequestDto()); + + //the soft deleted city is filtered out, the left join still keeps the person + result.Items.ShouldContain(x => x.Name == "Douglas" && x.CityName == null); + } +} diff --git a/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Applications/SqlCommandCapture.cs b/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Applications/SqlCommandCapture.cs new file mode 100644 index 0000000000..7f70e562e5 --- /dev/null +++ b/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Applications/SqlCommandCapture.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Data.Common; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Diagnostics; + +namespace Volo.Abp.EntityFrameworkCore.Applications; + +public class SqlCommandCapture : DbCommandInterceptor +{ + private static readonly AsyncLocal> Commands = new(); + + public static IDisposable Begin(out ConcurrentQueue commands) + { + commands = new ConcurrentQueue(); + Commands.Value = commands; + return new DisposeAction(() => Commands.Value = null); + } + + public override InterceptionResult ReaderExecuting( + DbCommand command, + CommandEventData eventData, + InterceptionResult result) + { + Commands.Value?.Enqueue(command.CommandText); + return base.ReaderExecuting(command, eventData, result); + } + + public override ValueTask> ReaderExecutingAsync( + DbCommand command, + CommandEventData eventData, + InterceptionResult result, + CancellationToken cancellationToken = default) + { + Commands.Value?.Enqueue(command.CommandText); + return base.ReaderExecutingAsync(command, eventData, result, cancellationToken); + } +} diff --git a/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo.Abp.Http.FluentValidation.Tests.abppkg b/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo.Abp.Http.FluentValidation.Tests.abppkg new file mode 100644 index 0000000000..a686451fbc --- /dev/null +++ b/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo.Abp.Http.FluentValidation.Tests.abppkg @@ -0,0 +1,3 @@ +{ + "role": "lib.test" +} \ No newline at end of file diff --git a/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo.Abp.Http.FluentValidation.Tests.csproj b/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo.Abp.Http.FluentValidation.Tests.csproj new file mode 100644 index 0000000000..f3001bd8a8 --- /dev/null +++ b/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo.Abp.Http.FluentValidation.Tests.csproj @@ -0,0 +1,18 @@ + + + + + + net10.0 + enable + + + + + + + + + + + diff --git a/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo/Abp/Http/FluentValidation/AbpHttpFluentValidationTestBase.cs b/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo/Abp/Http/FluentValidation/AbpHttpFluentValidationTestBase.cs new file mode 100644 index 0000000000..be25f2b813 --- /dev/null +++ b/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo/Abp/Http/FluentValidation/AbpHttpFluentValidationTestBase.cs @@ -0,0 +1,42 @@ +using System; +using System.Linq; +using System.Reflection; +using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Http.Modeling; +using Volo.Abp.Modularity; +using Volo.Abp.Testing; + +namespace Volo.Abp.Http.FluentValidation; + +public abstract class AbpHttpFluentValidationTestBase : AbpIntegratedTest + where TStartupModule : IAbpModule +{ + protected virtual async Task GetPropertyAsync(string propertyName) + { + var typeModel = await CreateTypeModelAsync(typeof(TDto)); + return typeModel.Properties!.Single(x => x.Name == propertyName); + } + + protected virtual async Task CreateTypeModelAsync(Type type) + { + var typeModel = TypeApiDescriptionModel.Create(type); + var contributors = ServiceProvider.GetServices().ToArray(); + + var propertyInfos = type + .GetProperties(BindingFlags.Instance | BindingFlags.Public) + .Where(p => p.DeclaringType == type) + .ToDictionary(p => p.Name, p => p); + + foreach (var propertyModel in typeModel.Properties!) + { + var context = new PropertyApiDescriptionModelContributionContext(propertyModel, propertyInfos[propertyModel.Name], type); + foreach (var contributor in contributors) + { + await contributor.ContributeAsync(context); + } + } + + return typeModel; + } +} diff --git a/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo/Abp/Http/FluentValidation/AbpHttpFluentValidationTestModule.cs b/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo/Abp/Http/FluentValidation/AbpHttpFluentValidationTestModule.cs new file mode 100644 index 0000000000..93f54d5afa --- /dev/null +++ b/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo/Abp/Http/FluentValidation/AbpHttpFluentValidationTestModule.cs @@ -0,0 +1,12 @@ +using Volo.Abp.Autofac; +using Volo.Abp.Modularity; + +namespace Volo.Abp.Http.FluentValidation; + +[DependsOn( + typeof(AbpAutofacModule), + typeof(AbpHttpFluentValidationModule) + )] +public class AbpHttpFluentValidationTestModule : AbpModule +{ +} diff --git a/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo/Abp/Http/FluentValidation/FluentValidationApiDescription_Tests.cs b/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo/Abp/Http/FluentValidation/FluentValidationApiDescription_Tests.cs new file mode 100644 index 0000000000..699729689f --- /dev/null +++ b/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo/Abp/Http/FluentValidation/FluentValidationApiDescription_Tests.cs @@ -0,0 +1,358 @@ +using System.Globalization; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using Shouldly; +using Volo.Abp.Autofac; +using Volo.Abp.Http.FluentValidation.TestObjects; +using Volo.Abp.Http.Modeling; +using Volo.Abp.Localization; +using Xunit; + +namespace Volo.Abp.Http.FluentValidation; + +public class FluentValidationApiDescription_Tests : AbpHttpFluentValidationTestBase +{ + protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) + { + options.UseAutofac(); + } + + [Fact] + public void Should_Register_The_Contributor() + { + ServiceProvider + .GetServices() + .ShouldContain(x => x is FluentValidationPropertyApiDescriptionModelContributor); + } + + [Fact] + public async Task Should_Map_Required_Rules() + { + (await GetPropertyAsync(nameof(ConstraintTestDto.NotEmptyValue))).IsRequired.ShouldBeTrue(); + (await GetPropertyAsync(nameof(ConstraintTestDto.NotNullValue))).IsRequired.ShouldBeTrue(); + (await GetPropertyAsync(nameof(ConstraintTestDto.UnconstrainedValue))).IsRequired.ShouldBeFalse(); + } + + [Fact] + public async Task Should_Map_Length_Rules() + { + var length = await GetPropertyAsync(nameof(ConstraintTestDto.LengthValue)); + length.MinLength.ShouldBe(3); + length.MaxLength.ShouldBe(10); + + var minimumLength = await GetPropertyAsync(nameof(ConstraintTestDto.MinimumLengthValue)); + minimumLength.MinLength.ShouldBe(4); + minimumLength.MaxLength.ShouldBeNull(); + + var maximumLength = await GetPropertyAsync(nameof(ConstraintTestDto.MaximumLengthValue)); + maximumLength.MinLength.ShouldBeNull(); + maximumLength.MaxLength.ShouldBe(12); + } + + [Fact] + public async Task Should_Not_Map_Zero_Length_Rules() + { + // A Func bound is reported as a zero too, so a zero can not be published safely. + (await GetPropertyAsync(nameof(ConstraintTestDto.EmptyOnlyValue))).MaxLength.ShouldBeNull(); + (await GetPropertyAsync(nameof(ConstraintTestDto.ZeroLengthValue))).MaxLength.ShouldBeNull(); + + var dynamicLength = await GetPropertyAsync(nameof(ConstraintTestDto.DynamicLengthValue)); + dynamicLength.MinLength.ShouldBeNull(); + dynamicLength.MaxLength.ShouldBeNull(); + } + + [Fact] + public async Task Should_Not_Map_A_Comparison_Bound_That_Is_Not_A_Number() + { + var property = await GetPropertyAsync(nameof(ConstraintTestDto.DateComparisonValue)); + + property.Minimum.ShouldBeNull(); + property.MinimumIsExclusive.ShouldBeNull(); + } + + [Fact] + public async Task Should_Map_A_Bound_Written_In_The_Exponent_Notation() + { + var property = await GetPropertyAsync(nameof(ConstraintTestDto.SmallExponentValue)); + + property.Minimum.ShouldBe("1E-20"); + } + + [Fact] + public async Task Should_Map_A_Bound_Below_The_Decimal_Range() + { + var property = await GetPropertyAsync(nameof(ConstraintTestDto.UnderflowExponentValue)); + + property.Minimum.ShouldBe("1E-30"); + } + + [Fact] + public async Task Should_Map_A_Comparison_On_A_Native_Integer() + { + var property = await GetPropertyAsync(nameof(ConstraintTestDto.NativeIntegerValue)); + + property.Minimum.ShouldBe("5"); + } + + [Fact] + public async Task Should_Not_Map_A_Between_Rule_That_Reads_As_An_Empty_Interval() + { + // The rule carries its own comparer, so its bounds mean the opposite of what they say. + var property = await GetPropertyAsync(nameof(ConstraintTestDto.ReversedBetweenValue)); + + property.Minimum.ShouldBeNull(); + property.Maximum.ShouldBeNull(); + } + + [Fact] + public async Task Should_Not_Map_A_Comparison_On_A_Property_That_Is_Not_A_Number() + { + // The server compares two strings ordinally, so a numeric bound would say something else. + var property = await GetPropertyAsync(nameof(ConstraintTestDto.StringComparisonValue)); + + property.Minimum.ShouldBeNull(); + property.MinimumIsExclusive.ShouldBeNull(); + } + + [Fact] + public async Task Should_Map_Regular_Expression_Rules() + { + var property = await GetPropertyAsync(nameof(ConstraintTestDto.RegexValue)); + + property.Regex.ShouldBe("^[a-z]+$"); + } + + [Fact] + public async Task Should_Map_Inclusive_Comparison_Rules() + { + var minimum = await GetPropertyAsync(nameof(ConstraintTestDto.InclusiveMinimumValue)); + minimum.Minimum.ShouldBe("5"); + minimum.MinimumIsExclusive.ShouldBe(false); + + var maximum = await GetPropertyAsync(nameof(ConstraintTestDto.InclusiveMaximumValue)); + maximum.Maximum.ShouldBe("50"); + maximum.MaximumIsExclusive.ShouldBe(false); + + var between = await GetPropertyAsync(nameof(ConstraintTestDto.InclusiveBetweenValue)); + between.Minimum.ShouldBe("1"); + between.Maximum.ShouldBe("10"); + between.MinimumIsExclusive.ShouldBe(false); + between.MaximumIsExclusive.ShouldBe(false); + } + + [Fact] + public async Task Should_Map_Exclusive_Comparison_Rules() + { + var minimum = await GetPropertyAsync(nameof(ConstraintTestDto.ExclusiveMinimumValue)); + minimum.Minimum.ShouldBe("5"); + minimum.MinimumIsExclusive.ShouldBe(true); + + var maximum = await GetPropertyAsync(nameof(ConstraintTestDto.ExclusiveMaximumValue)); + maximum.Maximum.ShouldBe("50"); + maximum.MaximumIsExclusive.ShouldBe(true); + + var between = await GetPropertyAsync(nameof(ConstraintTestDto.ExclusiveBetweenValue)); + between.Minimum.ShouldBe("1"); + between.Maximum.ShouldBe("10"); + between.MinimumIsExclusive.ShouldBe(true); + between.MaximumIsExclusive.ShouldBe(true); + } + + [Fact] + public async Task Should_Not_Map_Comparison_Against_Another_Property() + { + var property = await GetPropertyAsync(nameof(ConstraintTestDto.ComparedToOtherPropertyValue)); + + property.Minimum.ShouldBeNull(); + property.Maximum.ShouldBeNull(); + } + + [Fact] + public async Task Should_Not_Map_RuleForEach_Rules_To_The_Collection_Property() + { + var property = await GetPropertyAsync(nameof(ConstraintTestDto.CollectionValue)); + + property.IsRequired.ShouldBeFalse(); + } + + [Fact] + public async Task Should_Not_Map_Conditional_Rules() + { + (await GetPropertyAsync(nameof(ConditionalTestDto.ChainedConditionValue))).IsRequired.ShouldBeFalse(); + (await GetPropertyAsync(nameof(ConditionalTestDto.UnlessConditionValue))).IsRequired.ShouldBeFalse(); + (await GetPropertyAsync(nameof(ConditionalTestDto.AsyncConditionValue))).IsRequired.ShouldBeFalse(); + (await GetPropertyAsync(nameof(ConditionalTestDto.UnconditionalValue))).IsRequired.ShouldBeTrue(); + + var blockCondition = await GetPropertyAsync(nameof(ConditionalTestDto.BlockConditionValue)); + blockCondition.IsRequired.ShouldBeFalse(); + blockCondition.MaxLength.ShouldBeNull(); + } + + [Fact] + public async Task Should_Not_Map_Rules_Of_Named_Rule_Sets() + { + var namedRuleSet = await GetPropertyAsync(nameof(RuleSetTestDto.NamedRuleSetValue)); + namedRuleSet.IsRequired.ShouldBeFalse(); + namedRuleSet.MinLength.ShouldBeNull(); + + var defaultRuleSet = await GetPropertyAsync(nameof(RuleSetTestDto.DefaultRuleSetValue)); + defaultRuleSet.IsRequired.ShouldBeTrue(); + } + + [Fact] + public async Task Should_Keep_The_Stricter_Bound_When_Merging_With_Data_Annotations() + { + var length = await GetPropertyAsync(nameof(DataAnnotationTestDto.MergedLengthValue)); + length.MinLength.ShouldBe(5); + length.MaxLength.ShouldBe(10); + + var range = await GetPropertyAsync(nameof(DataAnnotationTestDto.MergedRangeValue)); + range.Minimum.ShouldBe("10"); + range.Maximum.ShouldBe("90"); + range.MinimumIsExclusive.ShouldBe(false); + range.MaximumIsExclusive.ShouldBe(false); + } + + [Fact] + public async Task Should_Read_Exclusive_Bounds_From_The_Range_Attribute() + { + var property = await GetPropertyAsync(nameof(DataAnnotationTestDto.ExclusiveAttributeValue)); + + property.Minimum.ShouldBe("1"); + property.Maximum.ShouldBe("100"); + property.MinimumIsExclusive.ShouldBe(true); + property.MaximumIsExclusive.ShouldBe(true); + } + + [Fact] + public async Task Should_Keep_The_Exclusivity_Of_The_Winning_Bound() + { + // The attribute bounds are stricter, so the exclusive flags must not leak onto them. + var looser = await GetPropertyAsync(nameof(DataAnnotationTestDto.LooserFluentBoundValue)); + looser.Minimum.ShouldBe("0"); + looser.Maximum.ShouldBe("100"); + looser.MinimumIsExclusive.ShouldBe(false); + looser.MaximumIsExclusive.ShouldBe(false); + + // On an equal bound the exclusive rule is the stricter one and wins. + var same = await GetPropertyAsync(nameof(DataAnnotationTestDto.SameBoundValue)); + same.Minimum.ShouldBe("10"); + same.Maximum.ShouldBe("90"); + same.MinimumIsExclusive.ShouldBe(true); + same.MaximumIsExclusive.ShouldBe(true); + } + + [Fact] + public async Task Should_Compare_Bounds_Beyond_The_Double_Precision_Exactly() + { + // Both bounds collapse to the same double, so only an exact comparison keeps the + // stricter attribute bound instead of replacing it with the looser rule. + var property = await GetPropertyAsync(nameof(DataAnnotationTestDto.HighPrecisionValue)); + + property.Minimum.ShouldBe("9007199254740993"); + property.Maximum.ShouldBe("18446744073709551615"); + } + + [Fact] + public async Task Should_Keep_The_Attribute_Regular_Expression() + { + var property = await GetPropertyAsync(nameof(DataAnnotationTestDto.AttributeRegexValue)); + + property.Regex.ShouldBe("^attribute$"); + } + + [Fact] + public async Task Should_Ignore_Types_Without_A_Validator() + { + var property = await GetPropertyAsync(nameof(UnvalidatedTestDto.Value)); + + property.IsRequired.ShouldBeFalse(); + property.MinLength.ShouldBeNull(); + property.MaxLength.ShouldBeNull(); + } + + [Fact] + public async Task Should_Ignore_Open_Generic_Types() + { + var typeModel = await CreateTypeModelAsync(typeof(GenericTestDto<>)); + var property = typeModel.Properties!.Single(x => x.Name == nameof(GenericTestDto.Name)); + + property.IsRequired.ShouldBeFalse(); + property.MinLength.ShouldBeNull(); + property.MaxLength.ShouldBeNull(); + property.Regex.ShouldBeNull(); + } + + [Fact] + public async Task Should_Merge_Range_Attribute_Bounds_Under_Any_Culture() + { + using (CultureHelper.Use(CultureInfo.GetCultureInfo("de-DE"))) + { + var property = await GetPropertyAsync(nameof(CultureTestDto.DecimalRangeValue)); + + property.Minimum.ShouldBe("2"); + property.Maximum.ShouldBe("9.5"); + + var typed = await GetPropertyAsync(nameof(CultureTestDto.TypedDecimalRangeValue)); + typed.Minimum.ShouldBe("2"); + typed.Maximum.ShouldBe("9.5"); + + // A bound outside the decimal range still loses to the stricter rule. + var exponent = await GetPropertyAsync(nameof(CultureTestDto.ExponentRangeValue)); + exponent.Minimum.ShouldBe("2"); + exponent.Maximum.ShouldBe("1E+30"); + } + } + + [Fact] + public async Task Should_Map_Rules_With_An_Overridden_Property_Name() + { + var property = await GetPropertyAsync(nameof(PropertyNameTestDto.RenamedValue)); + + property.IsRequired.ShouldBeTrue(); + property.MaxLength.ShouldBe(20); + } + + [Fact] + public async Task Should_Not_Map_Rules_Of_A_Nested_Object_To_A_Property_Of_The_Same_Name() + { + var property = await GetPropertyAsync(nameof(PropertyNameTestDto.City)); + + property.IsRequired.ShouldBeFalse(); + property.MaxLength.ShouldBeNull(); + } + + [Fact] + public async Task Should_Not_Map_Rules_Of_A_Nested_Object_To_The_Nested_Type() + { + // The model of the nested type is shared by every DTO that uses it, so a rule declared + // by the validator of one of them can not be attributed to it. + var property = await GetPropertyAsync(nameof(PropertyNameTestAddress.City)); + + property.IsRequired.ShouldBeFalse(); + property.MaxLength.ShouldBeNull(); + } + + [Fact] + public async Task Should_Not_Map_Rules_Of_A_Derived_Validator_To_A_Base_Property() + { + // Each type describes only the properties it declares, and the base type is described + // with its own validator, which does not exist here. + var inherited = await GetPropertyAsync(nameof(InheritanceTestBaseDto.InheritedValue)); + inherited.IsRequired.ShouldBeFalse(); + inherited.MaxLength.ShouldBeNull(); + + var own = await GetPropertyAsync(nameof(InheritanceTestDto.OwnValue)); + own.IsRequired.ShouldBeTrue(); + } + + [Fact] + public async Task Should_Keep_A_Bound_That_Is_Not_A_Number() + { + var property = await GetPropertyAsync(nameof(CultureTestDto.DateRangeValue)); + + property.Minimum.ShouldBe("2020-01-01"); + property.Maximum.ShouldBe("2030-01-01"); + } +} diff --git a/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo/Abp/Http/FluentValidation/FluentValidationApiDescription_WithoutAutofac_Tests.cs b/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo/Abp/Http/FluentValidation/FluentValidationApiDescription_WithoutAutofac_Tests.cs new file mode 100644 index 0000000000..f9fc111fac --- /dev/null +++ b/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo/Abp/Http/FluentValidation/FluentValidationApiDescription_WithoutAutofac_Tests.cs @@ -0,0 +1,25 @@ +using System.Threading.Tasks; +using Shouldly; +using Volo.Abp.Http.FluentValidation.TestObjects; +using Volo.Abp.Modularity; +using Xunit; + +namespace Volo.Abp.Http.FluentValidation; + +public class FluentValidationApiDescription_WithoutAutofac_Tests + : AbpHttpFluentValidationTestBase +{ + [DependsOn(typeof(AbpHttpFluentValidationModule))] + public class TestModule : AbpModule + { + } + + [Fact] + public async Task Should_Contribute_Without_Autofac() + { + var property = await GetPropertyAsync(nameof(ConstraintTestDto.LengthValue)); + + property.MinLength.ShouldBe(3); + property.MaxLength.ShouldBe(10); + } +} diff --git a/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo/Abp/Http/FluentValidation/TestObjects/ConditionalTestDto.cs b/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo/Abp/Http/FluentValidation/TestObjects/ConditionalTestDto.cs new file mode 100644 index 0000000000..59a27e0c84 --- /dev/null +++ b/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo/Abp/Http/FluentValidation/TestObjects/ConditionalTestDto.cs @@ -0,0 +1,41 @@ +using System.Threading.Tasks; +using FluentValidation; + +namespace Volo.Abp.Http.FluentValidation.TestObjects; + +public class ConditionalTestDto +{ + public bool Enabled { get; set; } + + public string? ChainedConditionValue { get; set; } + + public string? BlockConditionValue { get; set; } + + public string? UnlessConditionValue { get; set; } + + public string? AsyncConditionValue { get; set; } + + public string? UnconditionalValue { get; set; } +} + +public class ConditionalTestDtoValidator : AbstractValidator +{ + public ConditionalTestDtoValidator() + { + RuleFor(x => x.ChainedConditionValue).NotEmpty().When(x => x.Enabled); + + When(x => x.Enabled, () => + { + RuleFor(x => x.BlockConditionValue).NotEmpty().MaximumLength(32); + }); + + Unless(x => x.Enabled, () => + { + RuleFor(x => x.UnlessConditionValue).NotEmpty(); + }); + + RuleFor(x => x.AsyncConditionValue).NotEmpty().WhenAsync((x, _) => Task.FromResult(x.Enabled)); + + RuleFor(x => x.UnconditionalValue).NotEmpty(); + } +} diff --git a/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo/Abp/Http/FluentValidation/TestObjects/ConstraintTestDto.cs b/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo/Abp/Http/FluentValidation/TestObjects/ConstraintTestDto.cs new file mode 100644 index 0000000000..2a93cbd79e --- /dev/null +++ b/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo/Abp/Http/FluentValidation/TestObjects/ConstraintTestDto.cs @@ -0,0 +1,94 @@ +using System; +using System.Collections.Generic; +using FluentValidation; + +namespace Volo.Abp.Http.FluentValidation.TestObjects; + +public class ConstraintTestDto +{ + public string? NotEmptyValue { get; set; } + + public string? NotNullValue { get; set; } + + public string? LengthValue { get; set; } + + public string? MinimumLengthValue { get; set; } + + public string? MaximumLengthValue { get; set; } + + public string? RegexValue { get; set; } + + public int InclusiveMinimumValue { get; set; } + + public int InclusiveMaximumValue { get; set; } + + public int ExclusiveMinimumValue { get; set; } + + public int ExclusiveMaximumValue { get; set; } + + public int InclusiveBetweenValue { get; set; } + + public int ExclusiveBetweenValue { get; set; } + + public int ComparedToOtherPropertyValue { get; set; } + + public List CollectionValue { get; set; } = new List(); + + public string? EmptyOnlyValue { get; set; } + + public string? ZeroLengthValue { get; set; } + + public string? DynamicLengthValue { get; set; } + + public DateTime DateComparisonValue { get; set; } + + public double SmallExponentValue { get; set; } + + public double UnderflowExponentValue { get; set; } + + public string? StringComparisonValue { get; set; } + + public nint NativeIntegerValue { get; set; } + + public int ReversedBetweenValue { get; set; } + + public string? UnconstrainedValue { get; set; } +} + +public class ReversedComparer : IComparer +{ + public int Compare(int x, int y) + { + return y.CompareTo(x); + } +} + +public class ConstraintTestDtoValidator : AbstractValidator +{ + public ConstraintTestDtoValidator() + { + RuleFor(x => x.NotEmptyValue).NotEmpty(); + RuleFor(x => x.NotNullValue).NotNull(); + RuleFor(x => x.LengthValue).Length(3, 10); + RuleFor(x => x.MinimumLengthValue).MinimumLength(4); + RuleFor(x => x.MaximumLengthValue).MaximumLength(12); + RuleFor(x => x.RegexValue).Matches("^[a-z]+$"); + RuleFor(x => x.InclusiveMinimumValue).GreaterThanOrEqualTo(5); + RuleFor(x => x.InclusiveMaximumValue).LessThanOrEqualTo(50); + RuleFor(x => x.ExclusiveMinimumValue).GreaterThan(5); + RuleFor(x => x.ExclusiveMaximumValue).LessThan(50); + RuleFor(x => x.InclusiveBetweenValue).InclusiveBetween(1, 10); + RuleFor(x => x.ExclusiveBetweenValue).ExclusiveBetween(1, 10); + RuleFor(x => x.ComparedToOtherPropertyValue).GreaterThanOrEqualTo(x => x.InclusiveMinimumValue); + RuleForEach(x => x.CollectionValue).NotEmpty(); + RuleFor(x => x.EmptyOnlyValue).MaximumLength(0); + RuleFor(x => x.ZeroLengthValue).Length(0, 0); + RuleFor(x => x.DateComparisonValue).GreaterThanOrEqualTo(new DateTime(2020, 1, 1)); + RuleFor(x => x.DynamicLengthValue).Length(_ => 2, _ => 8); + RuleFor(x => x.SmallExponentValue).GreaterThanOrEqualTo(1e-20); + RuleFor(x => x.UnderflowExponentValue).GreaterThanOrEqualTo(1e-30); + RuleFor(x => x.StringComparisonValue).GreaterThan("10"); + RuleFor(x => x.NativeIntegerValue).GreaterThanOrEqualTo((nint)5); + RuleFor(x => x.ReversedBetweenValue).InclusiveBetween(10, 1, new ReversedComparer()); + } +} diff --git a/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo/Abp/Http/FluentValidation/TestObjects/CultureTestDto.cs b/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo/Abp/Http/FluentValidation/TestObjects/CultureTestDto.cs new file mode 100644 index 0000000000..13aca5cfeb --- /dev/null +++ b/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo/Abp/Http/FluentValidation/TestObjects/CultureTestDto.cs @@ -0,0 +1,30 @@ +using System; +using System.ComponentModel.DataAnnotations; +using FluentValidation; + +namespace Volo.Abp.Http.FluentValidation.TestObjects; + +public class CultureTestDto +{ + [Range(1.5, 9.5)] + public double DecimalRangeValue { get; set; } + + [Range(typeof(decimal), "1,5", "9,5")] + public decimal TypedDecimalRangeValue { get; set; } + + [Range(typeof(double), "1e-30", "1e30", ParseLimitsInInvariantCulture = true)] + public double ExponentRangeValue { get; set; } + + [Range(typeof(DateTime), "2020-01-01", "2030-01-01")] + public DateTime DateRangeValue { get; set; } +} + +public class CultureTestDtoValidator : AbstractValidator +{ + public CultureTestDtoValidator() + { + RuleFor(x => x.DecimalRangeValue).GreaterThanOrEqualTo(2.0); + RuleFor(x => x.TypedDecimalRangeValue).GreaterThanOrEqualTo(2m); + RuleFor(x => x.ExponentRangeValue).GreaterThanOrEqualTo(2d); + } +} diff --git a/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo/Abp/Http/FluentValidation/TestObjects/DataAnnotationTestDto.cs b/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo/Abp/Http/FluentValidation/TestObjects/DataAnnotationTestDto.cs new file mode 100644 index 0000000000..1220d65a24 --- /dev/null +++ b/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo/Abp/Http/FluentValidation/TestObjects/DataAnnotationTestDto.cs @@ -0,0 +1,42 @@ +using System.ComponentModel.DataAnnotations; +using FluentValidation; + +namespace Volo.Abp.Http.FluentValidation.TestObjects; + +public class DataAnnotationTestDto +{ + [MinLength(2)] + [MaxLength(50)] + public string? MergedLengthValue { get; set; } + + [RegularExpression("^attribute$")] + public string? AttributeRegexValue { get; set; } + + [Range(0, 100)] + public int MergedRangeValue { get; set; } + + [Range(0, 100)] + public int LooserFluentBoundValue { get; set; } + + [Range(10, 90)] + public int SameBoundValue { get; set; } + + [Range(1, 100, MinimumIsExclusive = true, MaximumIsExclusive = true)] + public int ExclusiveAttributeValue { get; set; } + + [Range(typeof(ulong), "9007199254740993", "18446744073709551615", ParseLimitsInInvariantCulture = true)] + public ulong HighPrecisionValue { get; set; } +} + +public class DataAnnotationTestDtoValidator : AbstractValidator +{ + public DataAnnotationTestDtoValidator() + { + RuleFor(x => x.MergedLengthValue).Length(5, 10); + RuleFor(x => x.AttributeRegexValue).Matches("^fluent$"); + RuleFor(x => x.MergedRangeValue).GreaterThanOrEqualTo(10).LessThanOrEqualTo(90); + RuleFor(x => x.LooserFluentBoundValue).GreaterThan(-5).LessThan(500); + RuleFor(x => x.SameBoundValue).GreaterThan(10).LessThan(90); + RuleFor(x => x.HighPrecisionValue).GreaterThanOrEqualTo(9_007_199_254_740_992UL); + } +} diff --git a/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo/Abp/Http/FluentValidation/TestObjects/GenericTestDto.cs b/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo/Abp/Http/FluentValidation/TestObjects/GenericTestDto.cs new file mode 100644 index 0000000000..64f5145376 --- /dev/null +++ b/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo/Abp/Http/FluentValidation/TestObjects/GenericTestDto.cs @@ -0,0 +1,18 @@ +using FluentValidation; + +namespace Volo.Abp.Http.FluentValidation.TestObjects; + +public class GenericTestDto +{ + public T? Value { get; set; } + + public string? Name { get; set; } +} + +public class GenericTestDtoValidator : AbstractValidator> +{ + public GenericTestDtoValidator() + { + RuleFor(x => x.Name).NotEmpty().Length(3, 9).Matches("^[a-z]+$"); + } +} diff --git a/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo/Abp/Http/FluentValidation/TestObjects/InheritanceTestDto.cs b/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo/Abp/Http/FluentValidation/TestObjects/InheritanceTestDto.cs new file mode 100644 index 0000000000..13f78223d5 --- /dev/null +++ b/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo/Abp/Http/FluentValidation/TestObjects/InheritanceTestDto.cs @@ -0,0 +1,22 @@ +using FluentValidation; + +namespace Volo.Abp.Http.FluentValidation.TestObjects; + +public class InheritanceTestBaseDto +{ + public string? InheritedValue { get; set; } +} + +public class InheritanceTestDto : InheritanceTestBaseDto +{ + public string? OwnValue { get; set; } +} + +public class InheritanceTestDtoValidator : AbstractValidator +{ + public InheritanceTestDtoValidator() + { + RuleFor(x => x.InheritedValue).NotEmpty().MaximumLength(15); + RuleFor(x => x.OwnValue).NotEmpty(); + } +} diff --git a/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo/Abp/Http/FluentValidation/TestObjects/PropertyNameTestDto.cs b/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo/Abp/Http/FluentValidation/TestObjects/PropertyNameTestDto.cs new file mode 100644 index 0000000000..390d186e00 --- /dev/null +++ b/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo/Abp/Http/FluentValidation/TestObjects/PropertyNameTestDto.cs @@ -0,0 +1,26 @@ +using FluentValidation; + +namespace Volo.Abp.Http.FluentValidation.TestObjects; + +public class PropertyNameTestDto +{ + public string? RenamedValue { get; set; } + + public string? City { get; set; } + + public PropertyNameTestAddress Address { get; set; } = new PropertyNameTestAddress(); +} + +public class PropertyNameTestAddress +{ + public string? City { get; set; } +} + +public class PropertyNameTestDtoValidator : AbstractValidator +{ + public PropertyNameTestDtoValidator() + { + RuleFor(x => x.RenamedValue).NotEmpty().MaximumLength(20).OverridePropertyName("displayed_name"); + RuleFor(x => x.Address.City).NotEmpty().MaximumLength(30); + } +} diff --git a/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo/Abp/Http/FluentValidation/TestObjects/RuleSetTestDto.cs b/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo/Abp/Http/FluentValidation/TestObjects/RuleSetTestDto.cs new file mode 100644 index 0000000000..e5867996a6 --- /dev/null +++ b/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo/Abp/Http/FluentValidation/TestObjects/RuleSetTestDto.cs @@ -0,0 +1,26 @@ +using FluentValidation; + +namespace Volo.Abp.Http.FluentValidation.TestObjects; + +public class RuleSetTestDto +{ + public string? NamedRuleSetValue { get; set; } + + public string? DefaultRuleSetValue { get; set; } +} + +public class RuleSetTestDtoValidator : AbstractValidator +{ + public RuleSetTestDtoValidator() + { + RuleSet("Create", () => + { + RuleFor(x => x.NamedRuleSetValue).NotEmpty().MinimumLength(4); + }); + + RuleSet("default", () => + { + RuleFor(x => x.DefaultRuleSetValue).NotEmpty(); + }); + } +} diff --git a/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo/Abp/Http/FluentValidation/TestObjects/UnvalidatedTestDto.cs b/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo/Abp/Http/FluentValidation/TestObjects/UnvalidatedTestDto.cs new file mode 100644 index 0000000000..c82257ecbd --- /dev/null +++ b/framework/test/Volo.Abp.Http.FluentValidation.Tests/Volo/Abp/Http/FluentValidation/TestObjects/UnvalidatedTestDto.cs @@ -0,0 +1,6 @@ +namespace Volo.Abp.Http.FluentValidation.TestObjects; + +public class UnvalidatedTestDto +{ + public string? Value { get; set; } +} diff --git a/framework/test/Volo.Abp.Http.Tests/Volo/Abp/Http/Modeling/PropertyApiDescriptionModel_Tests.cs b/framework/test/Volo.Abp.Http.Tests/Volo/Abp/Http/Modeling/PropertyApiDescriptionModel_Tests.cs new file mode 100644 index 0000000000..565d66c3c8 --- /dev/null +++ b/framework/test/Volo.Abp.Http.Tests/Volo/Abp/Http/Modeling/PropertyApiDescriptionModel_Tests.cs @@ -0,0 +1,125 @@ +using System; +using System.ComponentModel.DataAnnotations; +using System.Globalization; +using Shouldly; +using Volo.Abp.Localization; +using Xunit; + +namespace Volo.Abp.Http.Modeling; + +public class PropertyApiDescriptionModel_Tests +{ + [Fact] + public void Create_Should_Write_Range_Bounds_With_The_Invariant_Culture() + { + using (CultureHelper.Use(CultureInfo.GetCultureInfo("de-DE"))) + { + var model = CreateModel(nameof(TestClass.DecimalRangeValue)); + + model.Minimum.ShouldBe("1.5"); + model.Maximum.ShouldBe("9.5"); + } + } + + [Fact] + public void Create_Should_Write_Typed_Range_Bounds_With_The_Invariant_Culture() + { + using (CultureHelper.Use(CultureInfo.GetCultureInfo("de-DE"))) + { + var model = CreateModel(nameof(TestClass.TypedDecimalRangeValue)); + + model.Minimum.ShouldBe("1.5"); + model.Maximum.ShouldBe("9.5"); + } + } + + [Fact] + public void Create_Should_Convert_A_Typed_Range_Bound_With_Its_Operand_Type() + { + // A magnitude outside the decimal range is still a valid double bound. + var model = CreateModel(nameof(TestClass.ExponentRangeValue)); + + model.Minimum.ShouldBe("1E-30"); + model.Maximum.ShouldBe("1E+30"); + } + + [Fact] + public void Create_Should_Convert_A_Typed_Double_Range_Bound_Written_In_Another_Culture() + { + using (CultureHelper.Use(CultureInfo.GetCultureInfo("de-DE"))) + { + var model = CreateModel(nameof(TestClass.CultureExponentRangeValue)); + + model.Minimum.ShouldBe("1.5E+30"); + model.Maximum.ShouldBe("9.5E+30"); + } + } + + [Fact] + public void Create_Should_Keep_A_Typed_Range_Bound_That_Is_Not_A_Number() + { + var model = CreateModel(nameof(TestClass.DateRangeValue)); + + model.Minimum.ShouldBe("2020-01-01"); + model.Maximum.ShouldBe("2030-01-01"); + } + + [Fact] + public void Create_Should_Read_The_Exclusive_Bounds_Of_The_Range_Attribute() + { + var model = CreateModel(nameof(TestClass.ExclusiveRangeValue)); + + model.Minimum.ShouldBe("1"); + model.Maximum.ShouldBe("100"); + model.MinimumIsExclusive.ShouldBe(true); + model.MaximumIsExclusive.ShouldBe(true); + } + + [Fact] + public void Create_Should_Report_An_Inclusive_Range_Attribute_As_Inclusive() + { + var model = CreateModel(nameof(TestClass.DecimalRangeValue)); + + model.MinimumIsExclusive.ShouldBe(false); + model.MaximumIsExclusive.ShouldBe(false); + } + + [Fact] + public void Create_Should_Leave_The_Exclusive_Bounds_Null_Without_A_Range_Attribute() + { + var model = CreateModel(nameof(TestClass.UnconstrainedValue)); + + model.Minimum.ShouldBeNull(); + model.Maximum.ShouldBeNull(); + model.MinimumIsExclusive.ShouldBeNull(); + model.MaximumIsExclusive.ShouldBeNull(); + } + + private static PropertyApiDescriptionModel CreateModel(string propertyName) + { + return PropertyApiDescriptionModel.Create(typeof(TestClass).GetProperty(propertyName)!); + } + + public class TestClass + { + [Range(1.5, 9.5)] + public double DecimalRangeValue { get; set; } + + [Range(typeof(decimal), "1,5", "9,5")] + public decimal TypedDecimalRangeValue { get; set; } + + [Range(typeof(double), "1e-30", "1e30", ParseLimitsInInvariantCulture = true)] + public double ExponentRangeValue { get; set; } + + [Range(typeof(double), "1,5E+30", "9,5E+30")] + public double CultureExponentRangeValue { get; set; } + + [Range(typeof(DateTime), "2020-01-01", "2030-01-01")] + public DateTime DateRangeValue { get; set; } + + [Range(1, 100, MinimumIsExclusive = true, MaximumIsExclusive = true)] + public int ExclusiveRangeValue { get; set; } + + public string? UnconstrainedValue { get; set; } + } +} diff --git a/framework/test/Volo.Abp.Mapperly.Tests/Volo/Abp/Mapperly/AbpMapperlyQueryProjection_Tests.cs b/framework/test/Volo.Abp.Mapperly.Tests/Volo/Abp/Mapperly/AbpMapperlyQueryProjection_Tests.cs new file mode 100644 index 0000000000..6715fdfa74 --- /dev/null +++ b/framework/test/Volo.Abp.Mapperly.Tests/Volo/Abp/Mapperly/AbpMapperlyQueryProjection_Tests.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.Extensions.DependencyInjection; +using Shouldly; +using Volo.Abp.Mapperly.SampleClasses; +using Volo.Abp.ObjectMapping; +using Volo.Abp.Testing; +using Xunit; + +namespace Volo.Abp.Mapperly; + +public class AbpMapperlyQueryProjection_Tests : AbpIntegratedTest +{ + [Fact] + public void Should_Project_A_Queryable() + { + var queryProjector = ServiceProvider.GetRequiredService>(); + + var entities = new List + { + new MyEntity { Id = Guid.NewGuid(), Number = 42 } + }.AsQueryable(); + + var dtos = queryProjector.ProjectTo(entities).ToList(); + + dtos.Count.ShouldBe(1); + dtos[0].Id.ShouldBe(entities.First().Id); + dtos[0].Number.ShouldBe(42); + } + + + [Fact] + public void Should_Register_A_Projector_Only_Once() + { + //MyEntityQueryProjector also matches the class name convention of ExposeServicesAttribute + ServiceProvider.GetServices>().ShouldHaveSingleItem(); + } +} diff --git a/framework/test/Volo.Abp.Mapperly.Tests/Volo/Abp/Mapperly/SampleClasses/MyEntityQueryProjector.cs b/framework/test/Volo.Abp.Mapperly.Tests/Volo/Abp/Mapperly/SampleClasses/MyEntityQueryProjector.cs new file mode 100644 index 0000000000..980e40a94b --- /dev/null +++ b/framework/test/Volo.Abp.Mapperly.Tests/Volo/Abp/Mapperly/SampleClasses/MyEntityQueryProjector.cs @@ -0,0 +1,11 @@ +using System.Linq; +using Riok.Mapperly.Abstractions; +using Volo.Abp.ObjectMapping; + +namespace Volo.Abp.Mapperly.SampleClasses; + +[Mapper(RequiredMappingStrategy = RequiredMappingStrategy.Target)] +public partial class MyEntityQueryProjector : IQueryProjector +{ + public partial IQueryable ProjectTo(IQueryable source); +} diff --git a/framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/Applications/PersonProjectionAppService.cs b/framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/Applications/PersonProjectionAppService.cs new file mode 100644 index 0000000000..d625b518e8 --- /dev/null +++ b/framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/Applications/PersonProjectionAppService.cs @@ -0,0 +1,15 @@ +using System; +using Volo.Abp.Application.Services; +using Volo.Abp.Domain.Repositories; +using Volo.Abp.TestApp.Domain; + +namespace Volo.Abp.MongoDB.Applications; + +public class PersonProjectionAppService : ReadOnlyAppService +{ + public PersonProjectionAppService(IReadOnlyRepository repository) + : base(repository) + { + + } +} diff --git a/framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/Applications/PersonProjectionDto.cs b/framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/Applications/PersonProjectionDto.cs new file mode 100644 index 0000000000..2a8e716a8c --- /dev/null +++ b/framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/Applications/PersonProjectionDto.cs @@ -0,0 +1,9 @@ +using System; +using Volo.Abp.Application.Dtos; + +namespace Volo.Abp.MongoDB.Applications; + +public class PersonProjectionDto : EntityDto +{ + public string Name { get; set; } +} diff --git a/framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/Applications/PersonProjector.cs b/framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/Applications/PersonProjector.cs new file mode 100644 index 0000000000..eac0c6fd3a --- /dev/null +++ b/framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/Applications/PersonProjector.cs @@ -0,0 +1,17 @@ +using System.Linq; +using Volo.Abp.ObjectMapping; +using Volo.Abp.TestApp.Domain; + +namespace Volo.Abp.MongoDB.Applications; + +public class PersonProjector : IQueryProjector +{ + public IQueryable ProjectTo(IQueryable source) + { + return source.Select(person => new PersonProjectionDto + { + Id = person.Id, + Name = person.Name + }); + } +} diff --git a/framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/Applications/QueryProjection_Tests.cs b/framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/Applications/QueryProjection_Tests.cs new file mode 100644 index 0000000000..a7bf1367a6 --- /dev/null +++ b/framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/Applications/QueryProjection_Tests.cs @@ -0,0 +1,46 @@ +using System; +using System.Threading.Tasks; +using Shouldly; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Domain.Entities; +using Volo.Abp.TestApp; +using Volo.Abp.TestApp.Domain; +using Xunit; + +namespace Volo.Abp.MongoDB.Applications; + +[Collection(MongoTestCollection.Name)] +public class QueryProjection_Tests : MongoDbTestBase +{ + private readonly PersonProjectionAppService _personProjectionAppService; + + public QueryProjection_Tests() + { + _personProjectionAppService = GetRequiredService(); + } + + [Fact] + public async Task Should_Get_A_Projected_Entity() + { + var dto = await _personProjectionAppService.GetAsync(TestDataBuilder.UserDouglasId); + + dto.Id.ShouldBe(TestDataBuilder.UserDouglasId); + dto.Name.ShouldBe("Douglas"); + } + + [Fact] + public async Task Should_Throw_EntityNotFoundException_For_A_Missing_Entity() + { + await Should.ThrowAsync>( + async () => await _personProjectionAppService.GetAsync(Guid.NewGuid())); + } + + [Fact] + public async Task Should_Get_A_Projected_List() + { + var result = await _personProjectionAppService.GetListAsync(new PagedAndSortedResultRequestDto()); + + result.TotalCount.ShouldBeGreaterThan(0); + result.Items.ShouldContain(x => x.Name == "Douglas"); + } +} diff --git a/latest-versions.json b/latest-versions.json index aca0c089cd..6d300697a4 100644 --- a/latest-versions.json +++ b/latest-versions.json @@ -1,4 +1,13 @@ [ + { + "version": "10.6.1", + "releaseDate": "", + "type": "stable", + "message": "", + "leptonx": { + "version": "5.6.1" + } + }, { "version": "10.6.0", "releaseDate": "", diff --git a/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/ko.json b/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/ko.json new file mode 100644 index 0000000000..f74050f8d5 --- /dev/null +++ b/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/ko.json @@ -0,0 +1,75 @@ +{ + "culture": "ko", + "texts": { + "Menu:Account": "계정", + "UserName": "사용자 이름", + "EmailAddress": "이메일 주소", + "UserNameOrEmailAddress": "사용자 이름 또는 이메일 주소", + "Password": "비밀번호", + "RememberMe": "로그인 상태 유지", + "UseAnotherServiceToLogin": "다른 서비스를 사용하여 로그인", + "UserLockedOutMessage": "잘못된 로그인 시도로 인해 사용자 계정이 잠겼습니다. 잠시 후 다시 시도해 주세요.", + "InvalidUserNameOrPassword": "사용자 이름 또는 비밀번호가 올바르지 않습니다!", + "LoginIsNotAllowed": "로그인할 수 없습니다! 계정이 비활성 상태이거나 이메일 또는 전화번호 확인이 필요합니다.", + "SelfRegistrationDisabledMessage": "이 애플리케이션에서는 자체 회원가입이 비활성화되어 있습니다. 새 사용자를 등록하려면 애플리케이션 관리자에게 문의해 주세요.", + "LocalLoginDisabledMessage": "이 애플리케이션에서는 로컬 로그인이 비활성화되어 있습니다.", + "Login": "로그인", + "Cancel": "취소", + "Register": "회원가입", + "AreYouANewUser": "신규 사용자이신가요?", + "AlreadyRegistered": "이미 가입하셨나요?", + "InvalidLoginRequest": "잘못된 로그인 요청", + "ThereAreNoLoginSchemesConfiguredForThisClient": "이 클라이언트에 구성된 로그인 스키마가 없습니다.", + "LogInUsingYourProviderAccount": "{0} 계정으로 로그인", + "DisplayName:CurrentPassword": "현재 비밀번호", + "DisplayName:NewPassword": "새 비밀번호", + "DisplayName:NewPasswordConfirm": "새 비밀번호 확인", + "PasswordChangedMessage": "비밀번호가 변경되었습니다.", + "DisplayName:UserName": "사용자 이름", + "DisplayName:Email": "이메일", + "DisplayName:Name": "이름", + "DisplayName:Surname": "성", + "DisplayName:Password": "비밀번호", + "DisplayName:EmailAddress": "이메일 주소", + "DisplayName:PhoneNumber": "전화번호", + "PersonalSettings": "개인 설정", + "PersonalSettingsSaved": "개인 설정이 저장되었습니다.", + "PersonalSettingsChangedConfirmationModalTitle": "개인 정보 변경됨", + "PersonalSettingsChangedConfirmationModalDescription": "변경 사항은 다시 로그인한 후 반영됩니다. 지금 로그아웃하시겠습니까?", + "PasswordChanged": "비밀번호 변경됨", + "NewPasswordConfirmFailed": "새 비밀번호를 확인해 주세요.", + "NewPasswordSameAsOld": "새 비밀번호는 기존 비밀번호와 달라야 합니다.", + "Manage": "관리", + "MyAccount": "내 계정", + "DisplayName:Abp.Account.IsSelfRegistrationEnabled": "자체 회원가입 활성화 여부", + "Description:Abp.Account.IsSelfRegistrationEnabled": "사용자가 직접 계정을 등록할 수 있는지 여부입니다.", + "DisplayName:Abp.Account.EnableLocalLogin": "로컬 계정으로 인증", + "Description:Abp.Account.EnableLocalLogin": "서버에서 사용자의 로컬 계정 인증을 허용할지 여부를 나타냅니다.", + "LoggedOutTitle": "로그아웃됨", + "LoggedOutText": "로그아웃되었습니다. 잠시 후 리디렉션됩니다.", + "ReturnToText": "애플리케이션으로 돌아가려면 여기를 클릭하세요.", + "OrLoginWith": "또는 다음 계정으로 로그인:", + "ForgotPassword": "비밀번호를 잊으셨나요?", + "SendPasswordResetLink_Information": "비밀번호 재설정 링크가 이메일로 전송됩니다. 몇 분 이내에 이메일을 받지 못한 경우 다시 시도해 주세요.", + "PasswordResetMailSentMessage": "계정 복구 이메일을 이메일 주소로 전송했습니다. 15분 이내에 받은편지함에서 이메일을 찾을 수 없다면 스팸 메일함을 확인해 주세요. 스팸 메일함에서 찾은 경우 스팸이 아닌 것으로 표시해 주세요. ", + "ResetPassword": "비밀번호 재설정", + "ConfirmPassword": "비밀번호 확인", + "ResetPassword_Information": "새 비밀번호를 입력해 주세요.", + "YourPasswordIsSuccessfullyReset": "비밀번호가 재설정되었습니다.", + "GoToTheApplication": "애플리케이션으로 이동", + "BackToLogin": "로그인으로 돌아가기", + "ProfileTab:Password": "비밀번호 변경", + "ProfileTab:PersonalInfo": "개인 정보", + "ReturnToApplication": "애플리케이션으로 돌아가기", + "Volo.Account:InvalidEmailAddress": "지정한 이메일 주소를 찾을 수 없습니다: {0}", + "PasswordReset": "비밀번호 재설정", + "PasswordResetInfoInEmail": "계정 복구 요청이 접수되었습니다! 본인이 요청한 경우 다음 링크를 클릭하여 비밀번호를 재설정하세요.", + "ResetMyPassword": "내 비밀번호 재설정", + "AccessDenied": "액세스가 거부되었습니다!", + "AccessDeniedMessage": "이 리소스에 액세스할 권한이 없습니다.", + "OrRegisterWith": "또는 다음 계정으로 회원가입", + "RegisterUsingYourProviderAccount": "{0} 계정으로 회원가입", + "RequireMigrateSeedTitle": "관리자 사용자를 찾을 수 없습니다.", + "RequireMigrateSeedMessage": "데이터베이스 시드가 실행되었는지 확인해 주세요. 해결 방법은 문서를 참조하세요." + } +} diff --git a/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/pt.json b/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/pt.json new file mode 100644 index 0000000000..df64691b13 --- /dev/null +++ b/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/pt.json @@ -0,0 +1,75 @@ +{ + "culture": "pt", + "texts": { + "Menu:Account": "Conta", + "UserName": "Nome de utilizador", + "EmailAddress": "Endereço de email", + "UserNameOrEmailAddress": "Nome de utilizador ou endereço de email", + "Password": "Palavra-passe", + "RememberMe": "Manter sessão iniciada", + "UseAnotherServiceToLogin": "Utilizar outro serviço para iniciar sessão", + "UserLockedOutMessage": "A sua conta foi bloqueada pelo administrador ou devido a tentativas de início de sessão inválidas. Tente novamente mais tarde. Contacte o administrador de sistema se considerar que se trata de um erro.", + "InvalidUserNameOrPassword": "Nome de utilizador ou palavra-passe inválidos!", + "LoginIsNotAllowed": "Não tem permissão para iniciar sessão! A sua conta está inativa ou precisa de confirmar o seu email/número de telefone.", + "SelfRegistrationDisabledMessage": "O registo autónomo está desativado nesta aplicação. Contacte o administrador da aplicação para registar um novo utilizador.", + "LocalLoginDisabledMessage": "O início de sessão local está desativado nesta aplicação.", + "Login": "Iniciar sessão", + "Cancel": "Cancelar", + "Register": "Registar", + "AreYouANewUser": "É um novo utilizador?", + "AlreadyRegistered": "Já está registado?", + "InvalidLoginRequest": "Pedido de início de sessão inválido", + "ThereAreNoLoginSchemesConfiguredForThisClient": "Não existem esquemas de início de sessão configurados para este cliente.", + "LogInUsingYourProviderAccount": "Inicie sessão com a sua conta {0}", + "DisplayName:CurrentPassword": "Palavra-passe atual", + "DisplayName:NewPassword": "Nova palavra-passe", + "DisplayName:NewPasswordConfirm": "Confirmar nova palavra-passe", + "PasswordChangedMessage": "A sua palavra-passe foi alterada com sucesso.", + "DisplayName:UserName": "Nome de utilizador", + "DisplayName:Email": "Email", + "DisplayName:Name": "Nome", + "DisplayName:Surname": "Apelido", + "DisplayName:Password": "Palavra-passe", + "DisplayName:EmailAddress": "Endereço de email", + "DisplayName:PhoneNumber": "Número de telefone", + "PersonalSettings": "Definições pessoais", + "PersonalSettingsSaved": "Definições pessoais guardadas", + "PersonalSettingsChangedConfirmationModalTitle": "Informação pessoal alterada", + "PersonalSettingsChangedConfirmationModalDescription": "Para aplicar estas alterações, tem de iniciar sessão novamente. Pretende terminar sessão?", + "PasswordChanged": "Palavra-passe alterada", + "NewPasswordConfirmFailed": "Confirme a nova palavra-passe.", + "NewPasswordSameAsOld": "A nova palavra-passe tem de ser diferente da anterior.", + "Manage": "Gerir", + "MyAccount": "A minha conta", + "DisplayName:Abp.Account.IsSelfRegistrationEnabled": "Registo de novos utilizadores ativado", + "Description:Abp.Account.IsSelfRegistrationEnabled": "Define se um utilizador pode registar a sua própria conta.", + "DisplayName:Abp.Account.EnableLocalLogin": "Autenticação com uma conta local", + "Description:Abp.Account.EnableLocalLogin": "Indica se o servidor permite que os utilizadores se autentiquem com uma conta local.", + "LoggedOutTitle": "Sessão terminada", + "LoggedOutText": "A sua sessão foi terminada e será redirecionado em breve.", + "ReturnToText": "Clique aqui para voltar à aplicação", + "OrLoginWith": "Ou inicie sessão com:", + "ForgotPassword": "Esqueceu-se da palavra-passe?", + "SendPasswordResetLink_Information": "Será enviada para o seu email uma ligação para repor a palavra-passe. Se não receber o email dentro de alguns minutos, tente novamente.", + "PasswordResetMailSentMessage": "Foi enviado um email de recuperação de conta. Se não o receber em 15 minutos, verifique a pasta de correio não solicitado e marque-o como 'Não é spam'.", + "ResetPassword": "Repor palavra-passe", + "ConfirmPassword": "Confirme (repita) a palavra-passe", + "ResetPassword_Information": "Introduza a sua nova palavra-passe.", + "YourPasswordIsSuccessfullyReset": "A sua palavra-passe foi reposta com sucesso.", + "GoToTheApplication": "Ir para a aplicação", + "BackToLogin": "Voltar ao início de sessão", + "ProfileTab:Password": "Alterar palavra-passe", + "ProfileTab:PersonalInfo": "Informação pessoal", + "ReturnToApplication": "Voltar à aplicação", + "Volo.Account:InvalidEmailAddress": "Não foi possível encontrar o email indicado: {0}", + "PasswordReset": "Reposição de palavra-passe", + "PasswordResetInfoInEmail": "Recebemos um pedido de recuperação de conta! Se foi você que efetuou este pedido, clique na ligação seguinte para repor a sua palavra-passe.", + "ResetMyPassword": "Repor a minha palavra-passe", + "AccessDenied": "Acesso negado!", + "AccessDeniedMessage": "Não tem acesso a este recurso.", + "OrRegisterWith": "Ou registe-se com", + "RegisterUsingYourProviderAccount": "Registe-se com a sua conta {0}", + "RequireMigrateSeedTitle": "Não foi possível encontrar o utilizador administrador", + "RequireMigrateSeedMessage": "Certifique-se de que o seed da base de dados foi executado. Consulte a documentação para possíveis soluções." + } +} diff --git a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Components/ProfileManagementGroup/Password/Default.cshtml b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Components/ProfileManagementGroup/Password/Default.cshtml index e012bdd3f4..75c9c472e9 100644 --- a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Components/ProfileManagementGroup/Password/Default.cshtml +++ b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Components/ProfileManagementGroup/Password/Default.cshtml @@ -1,7 +1,9 @@ -@using Volo.Abp.Account.Localization +@using Localization.Resources.AbpUi +@using Volo.Abp.Account.Localization @using Volo.Abp.Users @using Microsoft.AspNetCore.Mvc.Localization @inject IHtmlLocalizer L +@inject IHtmlLocalizer UiL @inject ICurrentUser CurrentUser @model Volo.Abp.Account.Web.Pages.Account.Components.ProfileManagementGroup.Password.AccountProfilePasswordManagementGroupViewComponent.ChangePasswordInfoModel @@ -13,21 +15,21 @@
- +

}
- +

- +
diff --git a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Components/ProfileManagementGroup/Password/Default.js b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Components/ProfileManagementGroup/Password/Default.js index ec23761729..ca89718adb 100644 --- a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Components/ProfileManagementGroup/Password/Default.js +++ b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Components/ProfileManagementGroup/Password/Default.js @@ -6,12 +6,9 @@ return; } - if (passwordInput.attr("type") === "password") { - passwordInput.attr("type", "text"); - } - else { - passwordInput.attr("type", "password"); - } + let isRevealing = passwordInput.attr("type") === "password"; + passwordInput.attr("type", isRevealing ? "text" : "password"); + button.attr("aria-pressed", isRevealing); let icon = button.find("i"); if (icon) { diff --git a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Login.cshtml b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Login.cshtml index 1c883936b4..4fd5e6d5c3 100644 --- a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Login.cshtml +++ b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Login.cshtml @@ -1,4 +1,5 @@ @page +@using Localization.Resources.AbpUi @using Microsoft.AspNetCore.Mvc.Localization @using Volo.Abp.Account.Localization @using Volo.Abp.Account.Settings @@ -8,6 +9,7 @@ @using Volo.Abp.Settings @model Volo.Abp.Account.Web.Pages.Account.LoginModel @inject IHtmlLocalizer L +@inject IHtmlLocalizer UiL @inject IThemeManager ThemeManager @inject Volo.Abp.Settings.ISettingProvider SettingProvider @@ -53,7 +55,7 @@
- +
diff --git a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Login.js b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Login.js index 56934f4fef..381f414305 100644 --- a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Login.js +++ b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Login.js @@ -6,12 +6,9 @@ $(function () { return; } - if (passwordInput.attr("type") === "password") { - passwordInput.attr("type", "text"); - } - else { - passwordInput.attr("type", "password"); - } + let isRevealing = passwordInput.attr("type") === "password"; + passwordInput.attr("type", isRevealing ? "text" : "password"); + button.attr("aria-pressed", isRevealing); let icon = button.find("i"); if (icon) { diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/Localization/ko.json b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/Localization/ko.json new file mode 100644 index 0000000000..a08ef4a57d --- /dev/null +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/Localization/ko.json @@ -0,0 +1,118 @@ +{ + "culture": "ko", + "texts": { + "Permission:AuditLogging": "감사 로깅", + "Permission:AuditLogs": "감사 로그", + "Menu:AuditLogging": "감사 로그", + "AuditLogs": "감사 로그", + "HttpStatus": "HTTP 상태", + "HttpMethod": "HTTP 메서드", + "HttpMethodFilter": "HTTP 메서드 필터", + "HttpRequest": "HTTP 요청", + "User": "사용자", + "UserNameFilter": "사용자 필터", + "HasException": "예외 발생 여부", + "IpAddress": "IP 주소", + "Time": "시간", + "Date": "날짜", + "Duration": "소요 시간", + "Detail": "세부 정보", + "Overall": "전체", + "Actions": "작업", + "ClientIpAddress": "클라이언트 IP 주소", + "ClientName": "클라이언트 이름", + "BrowserInfo": "브라우저 정보", + "Url": "URL", + "UserName": "사용자 이름", + "TenantImpersonator": "테넌트 가장 사용자", + "UserImpersonator": "사용자 가장 사용자", + "UrlFilter": "URL 필터", + "Exceptions": "예외", + "Comments": "설명", + "HttpStatusCode": "HTTP 상태 코드", + "HttpStatusCodeFilter": "HTTP 상태 코드 필터", + "ServiceName": "서비스", + "MethodName": "메서드", + "CorrelationId": "상관관계 ID", + "ApplicationName": "애플리케이션 이름", + "ExecutionDuration": "실행 시간", + "ExtraProperties": "추가 속성", + "MaxDuration": "최대 소요 시간", + "MinDuration": "최소 소요 시간", + "MinMaxDuration": "소요 시간(최소~최대)", + "{0}Milliseconds": "{0}밀리초", + "ExecutionTime": "실행 시간", + "Parameters": "매개변수", + "EntityTypeFullName": "엔터티 형식 전체 이름", + "Entity": "엔터티", + "ChangeType": "변경 형식", + "ChangeTime": "변경 시간", + "NewValue": "새 값", + "OriginalValue": "이전 값", + "PropertyName": "속성 이름", + "PropertyTypeFullName": "속성 형식 전체 이름", + "Yes": "예", + "No": "아니요", + "Changes": "변경 사항", + "AverageExecutionDurationInLogsPerDay": "평균 실행 시간", + "AverageExecutionDurationInMilliseconds": "평균 실행 시간(밀리초)", + "ErrorRateInLogs": "로그 오류율", + "Success": "성공", + "Fault": "실패", + "NoChanges": "변경 사항 없음", + "EntityChanges": "엔터티 변경 사항", + "EntityId": "엔터티 ID", + "EntityChangeStartTime": "최소 변경 날짜", + "EntityChangeEndTime": "최대 변경 날짜", + "EntityHistory": "엔터티 기록", + "DaysAgoTitle": "{0} {1}.", + "DaysAgoWithUserTitle": "{0} {1}, {2} 사용자가 수행했습니다.", + "MinutesAgo": "{0}분 전", + "HoursAgo": "{0}시간 전", + "DaysAgo": "{0}일 전", + "Created": "생성함", + "Updated": "수정함", + "Deleted": "삭제함", + "ChangeHistory": "변경 기록", + "FullChangeHistory": "전체 변경 기록", + "ChangeDetails": "변경 세부 정보", + "DurationMs": "소요 시간(ms)", + "StartDate": "시작 날짜", + "EndDate": "종료 날짜", + "Feature:AuditLoggingGroup": "감사 로깅", + "Feature:AuditLoggingEnable": "감사 로그 페이지 사용", + "Feature:AuditLoggingEnableDescription": "애플리케이션에서 감사 로그 페이지를 사용합니다.", + "Feature:AuditLoggingSettingManagementEnable": "감사 로그 설정 관리 사용", + "Feature:AuditLoggingSettingManagementEnableDescription": "애플리케이션에서 감사 로그 설정 관리를 구성할 수 있습니다.", + "InvalidAuditLogDeletionSettings": "감사 로그 삭제 설정이 올바르지 않습니다. 삭제를 사용하는 경우 기간은 0일보다 커야 합니다.", + "AuditLogSettingsGeneral": "일반", + "AuditLogSettingsGlobal": "전역", + "DisplayName:IsPeriodicDeleterEnabled": "시스템 전체에서 정리 서비스 사용", + "Description:IsPeriodicDeleterEnabled": "이 옵션을 사용하지 않으면 주기적 삭제 서비스가 작동하지 않으며 감사 로그가 자동으로 삭제되지 않습니다.", + "DisplayName:GlobalIsExpiredDeleterEnabled": "모든 테넌트와 호스트에 정리 서비스 사용", + "Description:GlobalIsExpiredDeleterEnabled": "이 옵션을 사용하면 별도 설정이 없는 모든 테넌트와 호스트의 만료된 항목이 자동으로 삭제됩니다.", + "DisplayName:IsExpiredDeleterEnabled": "정리 서비스 사용", + "Description:IsExpiredDeleterEnabled": "이 옵션을 사용하면 만료된 항목이 자동으로 삭제됩니다.", + "DisplayName:ExpiredDeleterPeriod": "만료 항목 삭제 기간", + "Description:ExpiredDeleterPeriod": "만료된 항목이 자동으로 삭제될 때까지의 일수를 설정합니다.", + "ExpiredDeleterPeriodUnit": "일", + "AuditLogsBeforeXWillBeDeleted": "{0} 이전의 감사 로그가 삭제됩니다.", + "TenantId": "테넌트 ID", + "Permission:Export": "감사 로그 내보내기", + "ExportToExcel": "Excel로 내보내기", + "Exporting": "내보내는 중", + "ExportCompleted": "내보내기가 완료되었습니다.", + "ExportFailed": "내보내기에 실패했습니다.", + "ThereWereNoRecordsToExport": "내보낼 레코드가 없습니다.", + "ExportJobQueued": "{0}개 레코드에 대한 내보내기 작업이 대기열에 추가되었습니다. 내보내기가 완료되면 이메일을 보내드립니다.", + "ExportReady": "{0}개 레코드 내보내기가 완료되어 다운로드할 수 있습니다.", + "FileName": "파일 이름", + "TotalRecords": "전체 레코드 수", + "ExcelFileAttachedMessage": "Excel 파일이 이 이메일에 첨부되어 있습니다.", + "EntityChangeExportCompletedSubject": "엔터티 변경 사항 내보내기 완료", + "AuditLogExportCompletedSubject": "감사 로그 내보내기 완료", + "DownloadLinkExplanation": "{0}(UTC)까지 아래 링크를 사용하여 파일을 다운로드할 수 있습니다.", + "DownloadNow": "지금 다운로드", + "TryAgainMessage": "다시 시도해 주세요. 문제가 계속되면 지원팀에 문의해 주세요." + } +} diff --git a/modules/blob-storing-database/src/Volo.Abp.BlobStoring.Database.Domain.Shared/Volo/Abp/BlobStoring/Database/Localization/ko.json b/modules/blob-storing-database/src/Volo.Abp.BlobStoring.Database.Domain.Shared/Volo/Abp/BlobStoring/Database/Localization/ko.json new file mode 100644 index 0000000000..17fcfd79c4 --- /dev/null +++ b/modules/blob-storing-database/src/Volo.Abp.BlobStoring.Database.Domain.Shared/Volo/Abp/BlobStoring/Database/Localization/ko.json @@ -0,0 +1,6 @@ +{ + "culture": "ko", + "texts": { + "MyAccount": "내 계정" + } +} \ No newline at end of file diff --git a/modules/blogging/src/Volo.Blogging.Domain.Shared/Volo/Blogging/Localization/Resources/ko.json b/modules/blogging/src/Volo.Blogging.Domain.Shared/Volo/Blogging/Localization/Resources/ko.json new file mode 100644 index 0000000000..0aa35fe93e --- /dev/null +++ b/modules/blogging/src/Volo.Blogging.Domain.Shared/Volo/Blogging/Localization/Resources/ko.json @@ -0,0 +1,93 @@ +{ + "culture": "ko", + "texts": { + "Menu:Blogs": "블로그", + "Menu:BlogManagement": "블로그 관리", + "Permission:Management": "관리", + "Permission:Edit": "편집", + "Permission:Create": "생성", + "Permission:Delete": "삭제", + "Permission:Blogging": "블로그", + "Permission:Blogs": "블로그", + "Permission:Posts": "게시물", + "Permission:Tags": "태그", + "Permission:Comments": "댓글", + "Permission:ClearCache": "캐시 지우기", + "Title": "제목", + "Delete": "삭제", + "Reply": "답글", + "ReplyTo": "{0}에 답글 달기", + "ContinueReading": "계속 읽기", + "DaysAgo": "{0}일 전", + "DayAgo": "{0}일 전", + "YearsAgo": "{0}년 전", + "YearAgo": "{0}년 전", + "MonthsAgo": "{0}개월 전", + "MonthAgo": "{0}개월 전", + "WeeksAgo": "{0}주 전", + "WeekAgo": "{0}주 전", + "MinutesAgo": "{0}분 전", + "MinuteAgo": "{0}분 전", + "SecondsAgo": "{0}초 전", + "SecondAgo": "{0}초 전", + "HoursAgo": "{0}시간 전", + "HourAgo": "{0}시간 전", + "Now": "지금", + "Content": "내용", + "SeeAll": "모두 보기", + "PopularTags": "인기 태그", + "WiewsWithCount": "조회수 {0}회", + "LastPosts": "최신 게시물", + "LeaveComment": "댓글 남기기", + "TagsInThisArticle": "이 글의 태그", + "Posts": "게시물", + "Edit": "편집", + "BLOG": "블로그", + "CommentDeletionWarningMessage": "댓글이 삭제됩니다.", + "PostDeletionWarningMessage": "게시물이 삭제됩니다.", + "BlogDeletionWarningMessage": "블로그가 삭제됩니다.", + "AreYouSure": "계속하시겠습니까?", + "CommentWithCount": "댓글 {0}개", + "Comment": "댓글", + "ShareOnTwitter": "트위터에 공유", + "CoverImage": "커버 이미지", + "CreateANewPost": "새 게시물 만들기", + "CreateANewBlog": "새 블로그 만들기", + "WhatIsNew": "새로운 소식", + "Name": "이름", + "ShortName": "짧은 이름", + "CreationTime": "생성 시간", + "Description": "설명", + "Blogs": "블로그", + "Tags": "태그", + "ShareOn": "공유", + "TitleLengthWarning": "SEO에 적합하도록 제목을 60자 이내로 작성해야 합니다.", + "ClearCache": "캐시 지우기", + "ClearCacheConfirmationMessage": "캐시를 지우시겠습니까?", + "MarkdownSupported": "Markdown을 지원합니다.", + "FileUploadInfo": "이미지를 끌어다 놓거나 복사한 이미지를 붙여넣을 수 있습니다.", + "PostDescriptionHint": "* 게시물 링크 미리 보기에 표시되며 HTML을 지원합니다.", + "ReadMore": "계속 읽기", + "MemberNotPublishedPostYet": "아직 게시물이 없습니다!", + "UpdateUserWebSiteInfo": "예: https://johndoe.com", + "UpdateUserTwitterInfo": "예: johndoe", + "UpdateUserGithubInfo": "예: johndoe", + "UpdateUserLinkedinInfo": "예: https://www.linkedin.com/...", + "UpdateUserCompanyInfo": "예: Volosoft", + "UpdateUserJobTitleInfo": "예: 소프트웨어 개발자", + "WebSite": "웹사이트", + "UserName": "사용자 이름", + "FullURL": "전체 URL", + "JobTitle": "직책", + "PersonalWebsite": "개인 웹사이트", + "EditProfile": "프로필 편집", + "MoreFromBlog": "블로그의 다른 글", + "MoreFromUser": "{0}님의 다른 글", + "BlogPosts": "게시물", + "Views": "조회수", + "Biography": "소개", + "Social": "소셜 미디어", + "NewBlogPost": "새 블로그 게시물", + "BlogMemberMetaDescription": ".NET 개발, 크로스 플랫폼, ASP.NET 애플리케이션 템플릿, ABP 관련 소식 등을 다루는 ABP 블로그입니다." + } +} diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Index.cshtml b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Index.cshtml index a0ca2d81e3..4278e807ad 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Index.cshtml +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Index.cshtml @@ -1,7 +1,6 @@ @page @using Microsoft.AspNetCore.Authorization @using Volo.Blogging.Areas.Blog.Helpers.TagHelpers -@using Volo.Abp.AspNetCore.Mvc.UI.Packages.OwlCarousel @using Volo.Blogging @inject IAuthorizationService Authorization @model IndexModel @@ -19,13 +18,11 @@ @section scripts { - } @section styles { - } diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Shared/Scripts/blog.js b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Shared/Scripts/blog.js index ca0b21d203..37cd1643bb 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Shared/Scripts/blog.js +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Shared/Scripts/blog.js @@ -1,11 +1,4 @@ (function () { - function handleArrows() { - var herosWidth = $('.hero-articles').width(); - var arrowsPosition = herosWidth / 2 - 90; - $('.owl-next').css('right', arrowsPosition); - $('.owl-prev').css('left', arrowsPosition); - } - function handleImages() { //if ($(window).width() > 767) { // $(".box-articles .img-container").each(function () { @@ -18,36 +11,8 @@ //} } - function handleOwlCarousel() { - $('.hero-section .owl-carousel').owlCarousel({ - loop: true, - margin: 0, - nav: false, - dots: false, - //center: true, - autoplay: true, - autoHeight: true, - autoplaySpeed: 1000, - items: 1, - }); - $('.card-article-container .owl-carousel').owlCarousel({ - loop: true, - margin: 0, - nav: false, - dots: false, - autoplay: true, - autoplaySpeed: 1000, - responsive: { - 0: { - items: 1, - }, - }, - }); - } - $(function () { handleImages(); - handleOwlCarousel(); $('.nav-link').on('click', function () { $(this).parent().parent(); @@ -55,13 +20,8 @@ $(window).resize(function () { setTimeout(function () { - handleArrows(); handleImages(); }, 500); }); - - setTimeout(function () { - handleArrows(); - }, 500); }); })(); diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/ko.json b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/ko.json new file mode 100644 index 0000000000..f844f1cf7e --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/ko.json @@ -0,0 +1,290 @@ +{ + "culture": "ko", + "texts": { + "AddSubMenuItem": "하위 메뉴 항목 추가", + "AreYouSure": "계속하시겠습니까?", + "AverageRating": "평균 평점", + "BlogDeletionConfirmationMessage": "블로그 '{0}'을(를) 삭제합니다. 계속하시겠습니까?", + "BlogFeatureNotAvailable": "현재 이 기능을 사용할 수 없습니다. 사용하려면 'GlobalFeatureManager'에서 활성화하세요.", + "BlogId": "블로그", + "BlogPostDeletionConfirmationMessage": "블로그 게시물 '{0}'을(를) 삭제합니다. 계속하시겠습니까?", + "BlogPosts": "블로그 게시물", + "Blogs": "블로그", + "ChoosePreference": "환경 설정 선택...", + "Cms": "CMS", + "CmsKit.Comments": "댓글", + "CmsKit.Ratings": "평점", + "CmsKit.Reactions": "반응", + "CmsKit.Tags": "태그", + "CmsKit.MarkedItems": "표시된 항목", + "CmsKit:0002": "콘텐츠가 이미 존재합니다!", + "CmsKit:0003": "엔터티 {0}은(는) 태그를 지정할 수 없습니다.", + "CmsKit:Blog:0001": "지정한 슬러그({Slug})가 이미 존재합니다!", + "CmsKit:BlogPost:0001": "지정한 슬러그가 이미 존재합니다!", + "CmsKit:Comments:0001": "엔터티 {EntityType}에는 댓글을 작성할 수 없습니다.", + "CmsKit:Media:0001": "'{Name}'은(는) 유효한 미디어 이름이 아닙니다.", + "CmsKit:Media:0002": "이 엔터티에는 미디어를 추가할 수 없습니다.", + "CmsKit:Page:0001": "지정한 URL({Slug})이(가) 이미 존재합니다. 다른 URL을 사용하세요.", + "CmsKit:Rating:0001": "엔터티 {EntityType}에는 평점을 매길 수 없습니다.", + "CmsKit:Reaction:0001": "엔터티 {EntityType}에는 반응을 추가할 수 없습니다.", + "CmsKit:Tag:0002": "이 엔터티에는 태그를 지정할 수 없습니다!", + "CmsKit:MarkedItem:ToggleConfirmation": "표시된 항목 상태를 전환하시겠습니까?", + "ToggleFavorite": "즐겨찾기 추가/제거", + "FavoritesFilterMessage": "즐겨찾기를 필터링하려면 로그인하세요.", + "FilterOnFavorites": "즐겨찾기로 필터링", + "CommentAuthorizationExceptionMessage": "해당 댓글은 공개적으로 표시할 수 없습니다.", + "CmsKit:Modals:Login": "로그인", + "CmsKit:Modals:LoginModalDefaultMessage": "계속하려면 로그인하세요!", + "CmsKit:Modals:YouAreNotAuthenticated": "이 작업을 수행할 권한이 없습니다.", + "CommentDeletionConfirmationMessage": "이 댓글과 모든 답글을 삭제합니다!", + "CmsKit:MarkedItem:0001": "엔터티 {EntityType}은(는) 표시할 수 없습니다.", + "CmsKit:MarkedItem:0002": "엔터티 유형 '{EntityType}'에 대한 정의를 찾을 수 없습니다.", + "CmsKit:MarkedItem:0003": "엔터티 유형 '{EntityType}'에 대한 정의가 이미 존재합니다. 각 엔터티 유형에는 하나의 정의만 있어야 합니다.", + "CmsKit:MarkedItem:LoginMessage": "이 항목을 표시하려면 로그인하세요.", + "Comments": "댓글", + "Content": "콘텐츠", + "ContentDeletionConfirmationMessage": "이 콘텐츠를 삭제하시겠습니까?", + "Contents": "콘텐츠", + "CoverImage": "표지 이미지", + "CreateBlogPostPage": "새 블로그 게시물", + "CreationTime": "생성 시간", + "Delete": "삭제", + "Detail": "상세 정보", + "Details": "상세 정보", + "DisplayName": "표시 이름", + "DoYouPreferAdditionalEmails": "추가 이메일을 받으시겠습니까?", + "Edit": "편집", + "EndDate": "종료일", + "EntityId": "엔터티 ID", + "EntityType": "엔터티 유형", + "ExportCSV": "CSV 내보내기", + "Features": "기능", + "GenericDeletionConfirmationMessage": "'{0}'을(를) 삭제하시겠습니까?", + "IsActive": "활성", + "LastModification": "마지막 수정", + "LastModificationTime": "마지막 수정 시간", + "LoginToAddComment": "댓글을 작성하려면 로그인하세요.", + "LoginToRate": "평점을 매기려면 로그인하세요.", + "LoginToReact": "반응을 남기려면 로그인하세요.", + "LoginToReply": "답글을 작성하려면 로그인하세요.", + "MainMenu": "주 메뉴", + "MakeMainMenu": "주 메뉴로 설정", + "Menu:CMS": "CMS", + "Menus": "메뉴", + "MenuDeletionConfirmationMessage": "메뉴 '{0}'을(를) 삭제합니다. 계속하시겠습니까?", + "MenuItemDeletionConfirmationMessage": "이 메뉴 항목을 삭제하시겠습니까?", + "MenuItemMoveConfirmMessage": "'{0}'을(를) '{1}' 아래로 이동하시겠습니까?", + "MenuItems": "메뉴 항목", + "Message": "메시지", + "MessageDeletionConfirmationMessage": "이 댓글을 완전히 삭제합니다.", + "NewBlog": "새 블로그", + "NewBlogPost": "새 블로그 게시물", + "NewMenu": "새 메뉴", + "NewMenuItem": "새 루트 메뉴 항목", + "NewPage": "새 페이지", + "NewTag": "새 태그", + "NoMenuItems": "아직 메뉴 항목이 없습니다!", + "OK": "확인", + "PageDeletionConfirmationMessage": "이 페이지를 삭제하시겠습니까?", + "PageId": "페이지", + "Pages": "페이지", + "PageSlugInformation": "슬러그는 URL에 사용됩니다. URL은 '/{{slug}}' 형식입니다.", + "BlogSlugInformation": "슬러그는 URL에 사용됩니다. URL은 '/{0}/{{slug}}' 형식입니다.", + "Permission:BlogManagement": "블로그 관리", + "Permission:BlogManagement.Create": "생성", + "Permission:BlogManagement.Delete": "삭제", + "Permission:BlogManagement.Features": "기능", + "Permission:BlogManagement.Update": "수정", + "Permission:BlogPostManagement": "블로그 게시물 관리", + "Permission:BlogPostManagement.Create": "생성", + "Permission:BlogPostManagement.Delete": "삭제", + "Permission:BlogPostManagement.Update": "수정", + "Permission:BlogPostManagement.Publish": "게시", + "Permission:CmsKit": "CmsKit 관리", + "Permission:Comments": "댓글 관리", + "Permission:Comments.Delete": "삭제", + "Permission:Comments.Update": "수정", + "Permission:Comments.SettingManagement": "설정 관리", + "Permission:Contents": "콘텐츠 관리", + "Permission:Contents.Create": "콘텐츠 생성", + "Permission:Contents.Delete": "콘텐츠 삭제", + "Permission:Contents.Update": "콘텐츠 수정", + "Permission:MediaDescriptorManagement": "미디어 관리", + "Permission:MediaDescriptorManagement:Create": "생성", + "Permission:MediaDescriptorManagement:Delete": "삭제", + "Permission:MenuItemManagement": "메뉴 항목 관리", + "Permission:MenuItemManagement.Create": "생성", + "Permission:MenuItemManagement.Delete": "삭제", + "Permission:MenuItemManagement.Update": "수정", + "Permission:MenuManagement": "메뉴 관리", + "Permission:MenuManagement.Create": "생성", + "Permission:MenuManagement.Delete": "삭제", + "Permission:MenuManagement.Update": "수정", + "Permission:Menus": "메뉴 관리", + "Permission:Menus.Create": "생성", + "Permission:Menus.Delete": "삭제", + "Permission:Menus.Update": "수정", + "Permission:PageManagement": "페이지 관리", + "Permission:PageManagement:Create": "생성", + "Permission:PageManagement:Delete": "삭제", + "Permission:PageManagement:Update": "수정", + "Permission:PageManagement:SetAsHomePage": "홈 페이지로 설정", + "Permission:TagManagement": "태그 관리", + "Permission:TagManagement.Create": "생성", + "Permission:TagManagement.Delete": "삭제", + "Permission:TagManagement.Update": "수정", + "Permission:GlobalResources": "전역 리소스", + "Permission:CmsKitPublic": "CmsKit 공개 기능", + "Permission:Comments.DeleteAll": "모두 삭제", + "PickYourReaction": "반응 선택", + "Rating": "평점", + "RatingUndoMessage": "평점이 취소됩니다.", + "Reactions": "반응", + "Read": "읽기", + "RepliesToThisComment": "이 댓글의 답글", + "Reply": "답글", + "ReplyTo": "답글 대상", + "SamplePageMessage": "Pro 모듈의 샘플 페이지", + "SaveChanges": "변경 사항 저장", + "Script": "스크립트", + "SelectLayout": "레이아웃 선택", + "SelectAll": "모두 선택", + "Send": "보내기", + "SendMessage": "메시지 보내기", + "SelectedAuthor": "작성자", + "ShortDescription": "간단한 설명", + "Slug": "슬러그", + "Source": "소스", + "SourceUrl": "소스 URL", + "Star": "별점", + "StartDate": "시작일", + "Style": "스타일", + "Subject": "제목", + "SubjectPlaceholder": "제목을 입력하세요.", + "Submit": "제출", + "Subscribe": "구독", + "SavedSuccessfully": "저장되었습니다!", + "TagDeletionConfirmationMessage": "태그 '{0}'을(를) 삭제하시겠습니까?", + "Tags": "태그", + "Text": "텍스트", + "ThankYou": "감사합니다.", + "Title": "제목", + "TotalRatings": "총 평점 수", + "Undo": "실행 취소", + "Update": "수정", + "UpdatePreferenceSuccessMessage": "환경 설정이 저장되었습니다.", + "UpdateYourEmailPreferences": "이메일 환경 설정 업데이트", + "UnMakeMainMenu": "주 메뉴 설정 해제", + "UploadFailedMessage": "업로드에 실패했습니다.", + "UserId": "사용자 ID", + "Username": "사용자 이름", + "YourComment": "내 댓글", + "YourEmailAddress": "이메일 주소", + "YourFullName": "전체 이름", + "YourMessage": "내 메시지", + "YourReply": "내 답글", + "MarkdownSupported": "Markdown을 지원합니다.", + "GlobalResources": "전역 리소스", + "CmsKit.BlogPost.Status.0": "초안", + "CmsKit.BlogPost.Status.1": "게시됨", + "CmsKit.BlogPost.Status.2": "검토 대기 중", + "BlogPostPublishConfirmationMessage": "블로그 게시물 \"{0}\"을(를) 게시하시겠습니까?", + "SuccessfullyPublished": "게시되었습니다!", + "Draft": "초안", + "Publish": "게시", + "BlogPostDraftConfirmationMessage": "블로그 게시물 \"{0}\"을(를) 초안으로 설정하시겠습니까?", + "BlogPostSendToReviewConfirmationMessage": "블로그 게시물 \"{0}\"을(를) 게시하기 위해 관리자 검토로 보내시겠습니까?", + "SaveAsDraft": "초안으로 저장", + "SendToReview": "검토 요청", + "SendToReviewToPublish": "게시 검토 요청", + "BlogPostSendToReviewSuccessMessage": "블로그 게시물 \"{0}\"이(가) 게시를 위한 관리자 검토로 전송되었습니다.", + "HasBlogPostWaitingForReviewMessage": "검토 대기 중인 블로그 게시물이 있습니다. 목록을 보려면 클릭하세요.", + "SelectAStatus": "상태 선택", + "Status": "상태", + "CmsKit.BlogPost.ScrollIndex": "블로그 게시물 빠른 탐색 모음", + "CmsKit.BlogPost.PreventXssFeature": "XSS 방지", + "Add": "추가", + "AddWidget": "위젯 추가", + "PleaseConfigureWidgets": "위젯을 구성하세요.", + "SelectAnAuthor": "작성자 선택", + "InThisDocument": "이 문서에서", + "GoToTop": "맨 위로 이동", + "SetAsHomePage": "홈 페이지 상태 변경", + "CompletedSettingAsHomePage": "홈 페이지로 설정됨", + "IsHomePage": "홈 페이지 여부", + "RemovedSettingAsHomePage": "홈 페이지 설정이 해제됨", + "Feature:CmsKitGroup": "CMS Kit", + "Feature:BlogEnable": "블로그 게시물", + "Feature:BlogEnableDescription": "애플리케이션에서 블로그와 게시물을 동적으로 생성할 수 있는 CMS Kit 블로그 게시물 시스템입니다.", + "Feature:CommentEnable": "댓글", + "Feature:CommentEnableDescription": "BlogPost와 같은 엔터티에 댓글을 작성할 수 있는 CMS Kit 댓글 시스템입니다.", + "Feature:GlobalResourceEnable": "전역 리소스", + "Feature:GlobalResourceEnableDescription": "전역 스타일과 스크립트를 관리할 수 있는 CMS Kit 전역 리소스 기능입니다.", + "Feature:MenuEnable": "메뉴", + "Feature:MenuEnableDescription": "애플리케이션 메뉴를 동적으로 추가하거나 제거할 수 있는 CMS Kit 동적 메뉴 시스템입니다.", + "Feature:PageEnable": "페이지", + "Feature:PageEnableDescription": "특정 URL을 사용하는 정적 페이지를 생성할 수 있는 CMS Kit 페이지 시스템입니다.", + "Feature:RatingEnable": "평점", + "Feature:RatingEnableDescription": "사용자가 BlogPost와 같은 엔터티에 평점을 매길 수 있는 CMS Kit 평점 시스템입니다.", + "Feature:ReactionEnable": "반응", + "Feature:ReactionEnableDescription": "사용자가 BlogPost, Comment 등의 엔터티에 반응을 남길 수 있는 CMS Kit 반응 시스템입니다.", + "Feature:TagEnable": "태그 지정", + "Feature:TagEnableDescription": "BlogPost와 같은 엔터티에 태그를 지정할 수 있는 CMS Kit 태그 시스템입니다.", + "Feature:MarkedItemEnable": "표시된 항목", + "Feature:MarkedItemEnableDescription": "사용자가 엔터티를 즐겨찾기로 표시할 수 있는 CMS Kit 표시 시스템입니다.", + "DeleteBlogPostMessage": "블로그를 삭제합니다. 계속하시겠습니까?", + "CaptchaCode": "CAPTCHA 코드", + "CommentTextRequired": "댓글은 필수입니다.", + "CaptchaCodeErrorMessage": "입력한 CAPTCHA 답변이 올바르지 않습니다. 다시 시도하세요.", + "CaptchaCodeMissingMessage": "CAPTCHA 코드가 누락되었습니다!", + "UnAllowedExternalUrlMessage": "허용되지 않은 외부 URL이 포함되어 있습니다. 외부 URL을 제거하고 다시 시도하세요.", + "URL": "URL", + "PopularTags": "인기 태그", + "RemoveCoverImageConfirmationMessage": "표지 이미지를 제거하시겠습니까?", + "RemoveCoverImage": "표지 이미지 제거", + "CssClass": "CSS 클래스", + "TagsHelpText": "태그는 쉼표로 구분해야 합니다(예: tag1, tag2, tag3).", + "ThisPartOfContentCouldntBeLoaded": "콘텐츠의 이 부분을 불러올 수 없습니다.", + "DuplicateCommentAttemptMessage": "중복 댓글 작성 시도가 감지되었습니다. 댓글이 이미 제출되었습니다.", + "NoBlogPostYet": "아직 블로그 게시물이 없습니다!", + "CmsKit:Comment": "댓글", + "CmsKitCommentOptions:RequireApprovement": "댓글 승인 필요", + "CmsKitCommentOptions:RequireApprovementDescription": "활성화하면 댓글을 게시하기 전에 승인이 필요합니다.", + "CommentFilter:ApproveState": "승인 상태", + "ApproveState": "승인 상태", + "CommentFilter:0": "전체", + "CommentFilter:1": "승인됨", + "CommentFilter:2": "승인 거부됨", + "CommentFilter:4": "대기 중", + "ApprovedSuccessfully": "승인되었습니다.", + "ApprovalRevokedSuccessfully": "승인이 취소되었습니다.", + "Approve": "승인", + "Disapproved": "승인 거부됨", + "CommentAlertMessage": "승인 대기 중인 댓글이 {0}개 있습니다.", + "Settings:Menu:CmsKit": "CMS", + "CommentsAwaitingApproval": "승인 대기 중인 댓글", + "JustNow": "방금", + "MinuteAgo": "1분 전", + "MinutesAgo": "{0}분 전", + "HourAgo": "1시간 전", + "HoursAgo": "{0}시간 전", + "YesterdayAt": "어제 {0}", + "DayAt": "{0} {1}", + "MonthDayAt": "{0} {1} {2}", + "FullDate": "{0} {1} {2}", + "Minute": "분", + "Hour": "시간", + "Day": "일", + "Week": "주", + "CommentSubmittedForApproval": "댓글이 승인 요청으로 제출되었습니다.", + "ChooseAnActionForBlog": "블로그 작업 선택", + "AssignBlogPostsToOtherBlog": "블로그 게시물을 다른 블로그에 할당", + "SelectAnBlogToAssign": "할당할 블로그 선택", + "DeleteAllBlogPostsOfThisBlog": "이 블로그의 모든 게시물 삭제", + "RequiredPermissionName": "필수 권한 이름", + "Enum:PageStatus:0": "초안", + "Enum:PageStatus:1": "게시", + "AllPosts": "모든 게시물", + "IsReadOnly": "읽기 전용" + } +} \ No newline at end of file diff --git a/modules/docs/app/VoloDocs.Web/Localization/Resources/VoloDocs/Web/ko.json b/modules/docs/app/VoloDocs.Web/Localization/Resources/VoloDocs/Web/ko.json new file mode 100644 index 0000000000..e4ddba2392 --- /dev/null +++ b/modules/docs/app/VoloDocs.Web/Localization/Resources/VoloDocs/Web/ko.json @@ -0,0 +1,10 @@ +{ + "culture": "ko", + "texts": { + "DocsTitle": "VoloDocs", + "WelcomeVoloDocs": "VoloDocs에 오신 것을 환영합니다!", + "NoProjectWarning": "아직 정의된 프로젝트가 없습니다!", + "CreateYourFirstProject": "첫 번째 프로젝트를 시작하려면 여기를 클릭하세요.", + "NoProject": "프로젝트가 없습니다!" + } +} \ No newline at end of file diff --git a/modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Localization/Resources/Docs/ApplicationContracts/ko.json b/modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Localization/Resources/Docs/ApplicationContracts/ko.json new file mode 100644 index 0000000000..4be5125365 --- /dev/null +++ b/modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Localization/Resources/Docs/ApplicationContracts/ko.json @@ -0,0 +1,74 @@ +{ + "culture": "ko", + "texts": { + "Permission:DocumentManagement": "문서 관리", + "Permission:Projects": "프로젝트", + "Permission:Edit": "편집", + "Permission:Delete": "삭제", + "Permission:Create": "생성", + "Permission:Documents": "문서", + "Menu:Documents": "문서", + "Menu:DocumentManagement": "문서", + "Menu:ProjectManagement": "프로젝트", + "CreateANewProject": "새 프로젝트 생성", + "Edit": "편집", + "Create": "생성", + "Pull": "가져오기", + "Projects": "프로젝트", + "Name": "이름", + "ShortName": "단축 이름", + "DocumentStoreType": "문서 저장소 유형", + "Format": "형식", + "ShortNameInfoText": "고유 URL에 사용됩니다.", + "DisplayName:Name": "이름", + "DisplayName:ShortName": "단축 이름", + "DisplayName:Format": "형식", + "DisplayName:DefaultDocumentName": "기본 문서 이름", + "DisplayName:NavigationDocumentName": "탐색 문서 이름", + "DisplayName:MinimumVersion": "최소 버전", + "DisplayName:MainWebsiteUrl": "메인 웹사이트 URL", + "DisplayName:LatestVersionBranchName": "최신 버전 브랜치 이름", + "DisplayName:GitHubRootUrl": "GitHub 루트 URL", + "DisplayName:GitHubAccessToken": "GitHub 액세스 토큰", + "DisplayName:GitHubUserAgent": "GitHub 사용자 에이전트", + "DisplayName:GithubVersionProviderSource": "GitHub 버전 공급자 소스", + "DisplayName:VersionBranchPrefix": "버전 브랜치 접두사", + "DisplayName:All": "모두 가져오기", + "DisplayName:LanguageCode": "언어 코드", + "DisplayName:Version": "버전", + "Documents": "문서", + "RemoveFromCache": "캐시에서 제거하고 재인덱싱", + "Reindex": "재인덱싱", + "ReindexCompleted": "재인덱싱 완료", + "RemovedFromCache": "캐시에서 제거하고 재인덱싱했습니다.", + "RemoveFromCacheConfirmation": "이 항목을 캐시에서 제거하시겠습니까?", + "ReIndexDocumentConfirmation": "문서 \"{0}\"을(를) 재인덱싱하시겠습니까?", + "DeleteFromDatabase": "데이터베이스에서 삭제", + "Deleted": "삭제됨", + "Search": "검색", + "StartDate": "시작일", + "EndDate": "종료일", + "CreationTime": "생성 시간", + "LastUpdateTime": "마지막 업데이트", + "LastSignificantUpdateTime": "마지막 주요 업데이트", + "Version": "버전", + "LanguageCode": "언어 코드", + "FileName": "파일 이름", + "LastCachedTime": "캐시 시간", + "Project": "프로젝트", + "AdvancedFilters": "고급 필터", + "RemoveCacheAndReIndexConfirmation": "문서 \"{0}\"을(를) 캐시에서 제거하고 재인덱싱합니다. 계속하시겠습니까?", + "GeneratePdf": "PDF 생성", + "Generating": "생성 중...", + "Language": "언어", + "ForceToGenerateNewPdf": "새 PDF 강제 생성", + "PdfGeneratedSuccessfully": "PDF가 생성되었습니다.", + "GenerateAndDownloadPdf": "PDF 생성 및 다운로드", + "PdfFileDeletionWarningMessage": "PDF 파일 \"{0}\"을(를) 삭제하시겠습니까?", + "ManagePdfFiles": "PDF 파일 관리", + "Permission:ManagePdfFiles": "PDF 파일 관리", + "PdfDeletedSuccessfully": "PDF 파일이 삭제되었습니다.", + "PdfGenerationStarted": "PDF 생성을 시작했습니다.", + "PdfGenerationStartedInfoMessage": "PDF 생성을 시작했습니다. 완료되면 PDF 파일 섹션에 파일이 추가되었는지 확인할 수 있습니다." + } +} \ No newline at end of file diff --git a/modules/docs/src/Volo.Docs.Common.Application.Contracts/Volo/Docs/Common/Localization/Resources/Docs/ApplicationContracts/ko.json b/modules/docs/src/Volo.Docs.Common.Application.Contracts/Volo/Docs/Common/Localization/Resources/Docs/ApplicationContracts/ko.json new file mode 100644 index 0000000000..e110342281 --- /dev/null +++ b/modules/docs/src/Volo.Docs.Common.Application.Contracts/Volo/Docs/Common/Localization/Resources/Docs/ApplicationContracts/ko.json @@ -0,0 +1,7 @@ +{ + "culture": "ko", + "texts": { + "Permission:DocumentManagement.Common": "문서 관리 공통", + "Permission:PdfDownload": "PDF 다운로드" + } +} \ No newline at end of file diff --git a/modules/docs/src/Volo.Docs.Domain/Volo.Docs.Domain.csproj b/modules/docs/src/Volo.Docs.Domain/Volo.Docs.Domain.csproj index 45f06aa595..0fb5d6bd7d 100644 --- a/modules/docs/src/Volo.Docs.Domain/Volo.Docs.Domain.csproj +++ b/modules/docs/src/Volo.Docs.Domain/Volo.Docs.Domain.csproj @@ -19,11 +19,11 @@ - + - - - + + + diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/DefaultElasticClientProvider.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/DefaultElasticClientProvider.cs index 8b4d82e5cd..86eb97c20d 100644 --- a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/DefaultElasticClientProvider.cs +++ b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/DefaultElasticClientProvider.cs @@ -1,7 +1,7 @@ using System; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Options; -using Nest; +using Elastic.Clients.Elasticsearch; using Volo.Abp.DependencyInjection; namespace Volo.Docs.Documents.FullSearch.Elastic @@ -17,11 +17,11 @@ namespace Volo.Docs.Documents.FullSearch.Elastic Options = options.Value; } - public virtual IElasticClient GetClient() + public virtual ElasticsearchClient GetClient() { var node = new Uri(Configuration["ElasticSearch:Url"]); - var settings = new ConnectionSettings(node).DefaultIndex(Options.IndexName); - return new ElasticClient(Options.Authenticate(settings)); + var settings = new ElasticsearchClientSettings(node).DefaultIndex(Options.IndexName); + return new ElasticsearchClient(Options.Authenticate(settings)); } } } diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/DocsElasticSearchOptions.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/DocsElasticSearchOptions.cs index 6a17a034c4..bf21c98596 100644 --- a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/DocsElasticSearchOptions.cs +++ b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/DocsElasticSearchOptions.cs @@ -1,5 +1,6 @@ using System; -using Nest; +using Elastic.Clients.Elasticsearch; +using Elastic.Transport; using Volo.Abp; namespace Volo.Docs.Documents.FullSearch.Elastic @@ -10,7 +11,7 @@ namespace Volo.Docs.Documents.FullSearch.Elastic public string IndexName { get; set; } - protected Action AuthenticationAction { get; set; } + protected Action AuthenticationAction { get; set; } public DocsElasticSearchOptions() { @@ -25,7 +26,7 @@ namespace Volo.Docs.Documents.FullSearch.Elastic AuthenticationAction = settings => { - settings.BasicAuthentication(username, password); + settings.Authentication(new BasicAuthentication(username, password)); }; return this; @@ -38,13 +39,13 @@ namespace Volo.Docs.Documents.FullSearch.Elastic AuthenticationAction = settings => { - settings.ApiKeyAuthentication(id, apiKey); + settings.Authentication(new Base64ApiKey(id, apiKey)); }; return this; } - public ConnectionSettings Authenticate(ConnectionSettings connectionSettings) + public ElasticsearchClientSettings Authenticate(ElasticsearchClientSettings connectionSettings) { AuthenticationAction?.Invoke(connectionSettings); return connectionSettings; diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/ElasticDocumentFullSearch.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/ElasticDocumentFullSearch.cs index a34e27cf20..5462f11045 100644 --- a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/ElasticDocumentFullSearch.cs +++ b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/ElasticDocumentFullSearch.cs @@ -3,10 +3,14 @@ using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; -using Elasticsearch.Net; +using Elastic.Clients.Elasticsearch; +using Elastic.Clients.Elasticsearch.Core.Search; +using Elastic.Clients.Elasticsearch.IndexManagement; +using Elastic.Clients.Elasticsearch.Mapping; +using Elastic.Clients.Elasticsearch.QueryDsl; +using Elastic.Transport.Products.Elasticsearch; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using Nest; using Volo.Abp; using Volo.Abp.Domain.Services; @@ -33,25 +37,28 @@ namespace Volo.Docs.Documents.FullSearch.Elastic var client = _clientProvider.GetClient(); - var existsResponse = await client.Indices.ExistsAsync(_options.IndexName, ct: cancellationToken); + var existsResponse = await client.Indices.ExistsAsync(_options.IndexName, cancellationToken); HandleError(existsResponse); if (!existsResponse.Exists) { - HandleError(await client.Indices.CreateAsync(_options.IndexName, c => c - .Map(m => + var properties = new Properties(); + properties.Add(d => d.Id, new KeywordProperty()); + properties.Add(d => d.ProjectId, new KeywordProperty()); + properties.Add(d => d.Name, new KeywordProperty()); + properties.Add(d => d.FileName, new KeywordProperty()); + properties.Add(d => d.Version, new KeywordProperty()); + properties.Add(d => d.LanguageCode, new KeywordProperty()); + properties.Add(d => d.Content, new TextProperty()); + + HandleError(await client.Indices.CreateAsync(new CreateIndexRequest(_options.IndexName) + { + Mappings = new TypeMapping { - return m - .Properties(p => p - .Keyword(x => x.Name(d => d.Id)) - .Keyword(x => x.Name(d => d.ProjectId)) - .Keyword(x => x.Name(d => d.Name)) - .Keyword(x => x.Name(d => d.FileName)) - .Keyword(x => x.Name(d => d.Version)) - .Keyword(x => x.Name(d => d.LanguageCode)) - .Text(x => x.Name(d => d.Content))); - }), cancellationToken)); + Properties = properties + } + }, cancellationToken)); } } @@ -60,24 +67,19 @@ namespace Volo.Docs.Documents.FullSearch.Elastic var client = _clientProvider.GetClient(); // exist by name, project id, language code and version - var existResponse = await client.SearchAsync(s => s - .Query(q => q - .Bool(b => b - .Must(m => m - .Term(t => t.ProjectId, NormalizeField(document.ProjectId)) - && m.Term(t => t.LanguageCode, NormalizeField(document.LanguageCode)) - && m.Term(t => t.Version, NormalizeField(document.Version)) - && m.Term(t => t.Name, document.Name) - ) - ) - ), cancellationToken); - - HandleError(existResponse); - - if (existResponse.Documents.Count != 0) + HandleError(await client.DeleteByQueryAsync(new DeleteByQueryRequest(_options.IndexName) { - HandleError(await client.DeleteManyAsync(existResponse.Documents, _options.IndexName, cancellationToken)); - } + Query = new BoolQuery + { + Must = new Query[] + { + new TermQuery { Field = "projectId", Value = NormalizeField(document.ProjectId) }, + new TermQuery { Field = "languageCode", Value = NormalizeField(document.LanguageCode) }, + new TermQuery { Field = "version", Value = NormalizeField(document.Version) }, + new TermQuery { Field = "name", Value = document.Name } + } + } + }, cancellationToken)); var esDocument = new EsDocument { @@ -90,7 +92,7 @@ namespace Volo.Docs.Documents.FullSearch.Elastic Version = NormalizeField(document.Version) }; - HandleError(await client.IndexAsync(esDocument, x => x.Index(_options.IndexName), cancellationToken)); + HandleError(await client.IndexAsync(esDocument, _options.IndexName, esDocument.Id, cancellationToken)); } public virtual async Task AddOrUpdateManyAsync(IEnumerable documents, CancellationToken cancellationToken = default) @@ -113,7 +115,7 @@ namespace Volo.Docs.Documents.FullSearch.Elastic public virtual async Task DeleteAsync(Guid id, CancellationToken cancellationToken = default) { HandleError(await _clientProvider.GetClient() - .DeleteAsync(DocumentPath.Id(NormalizeField(id)), x => x.Index(_options.IndexName), cancellationToken)); + .DeleteAsync(_options.IndexName, NormalizeField(id), cancellationToken)); } public virtual async Task DeleteAllAsync(CancellationToken cancellationToken = default) @@ -137,11 +139,11 @@ namespace Volo.Docs.Documents.FullSearch.Elastic { Query = new BoolQuery { - Filter = new QueryContainer[] + Filter = new Query[] { new BoolQuery { - Must = new QueryContainer[] + Must = new Query[] { new TermQuery { @@ -164,7 +166,7 @@ namespace Volo.Docs.Documents.FullSearch.Elastic { ValidateElasticSearchEnabled(); - FieldNameQueryBase query; + Query query; // if context starts with " or ends with " then we search for exact match if (context.StartsWith("\"") && context.EndsWith("\"")) { @@ -172,6 +174,7 @@ namespace Volo.Docs.Documents.FullSearch.Elastic query = new MatchPhraseQuery { + Field = "content", Query = context }; } @@ -179,27 +182,26 @@ namespace Volo.Docs.Documents.FullSearch.Elastic { query = new MatchQuery { + Field = "content", Query = context }; } - query.Field = "content"; - - var request = new SearchRequest + var request = new SearchRequest(_options.IndexName) { Size = maxResultCount ?? 10, From = skipCount ?? 0, Query = new BoolQuery { - Must = new QueryContainer[] + Must = new Query[] { query, }, - Filter = new QueryContainer[] + Filter = new Query[] { new BoolQuery { - Must = new QueryContainer[] + Must = new Query[] { new TermQuery { @@ -224,7 +226,7 @@ namespace Volo.Docs.Documents.FullSearch.Elastic { PreTags = new[] { "" }, PostTags = new[] { "" }, - Fields = new Dictionary + Fields = new Dictionary { { "content", new HighlightField() @@ -247,10 +249,10 @@ namespace Volo.Docs.Documents.FullSearch.Elastic } - if (hit.Highlight.ContainsKey("content")) + if (hit.Highlight != null && hit.Highlight.TryGetValue("content", out var highlights)) { doc.Highlight = new List(); - doc.Highlight.AddRange(hit.Highlight["content"]); + doc.Highlight.AddRange(highlights); } docs.Add(doc); @@ -259,12 +261,13 @@ namespace Volo.Docs.Documents.FullSearch.Elastic return new EsDocumentResult { EsDocuments = docs, TotalCount = response.Total }; } - protected virtual void HandleError(IElasticsearchResponse response) + protected virtual void HandleError(ElasticsearchResponse response) { - if (!response.ApiCall.Success) + if (!response.IsValidResponse) { - _logger.LogError(response.ApiCall.OriginalException, - "An error occurred in the elastic search api call."); + response.TryGetOriginalException(out var exception); + _logger.LogError(exception, + "An error occurred in the elastic search api call. {ElasticsearchServerError}", response.ElasticsearchServerError); } } diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/IElasticClientProvider.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/IElasticClientProvider.cs index e1424bfbd6..73c51904ef 100644 --- a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/IElasticClientProvider.cs +++ b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/FullSearch/Elastic/IElasticClientProvider.cs @@ -1,9 +1,9 @@ -using Nest; +using Elastic.Clients.Elasticsearch; namespace Volo.Docs.Documents.FullSearch.Elastic { public interface IElasticClientProvider { - IElasticClient GetClient(); + ElasticsearchClient GetClient(); } } \ No newline at end of file diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Localization/Domain/ko.json b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Localization/Domain/ko.json new file mode 100644 index 0000000000..7e6d22155b --- /dev/null +++ b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Localization/Domain/ko.json @@ -0,0 +1,51 @@ +{ + "culture": "ko", + "texts": { + "Documents": "문서", + "BackToWebsite": "웹사이트로 돌아가기", + "Contributors": "기여자", + "ShareOn": "공유", + "Version": "버전", + "Edit": "편집", + "LastEditTime": "마지막 편집", + "Delete": "삭제", + "ClearCache": "캐시 지우기", + "ClearCacheConfirmationMessage": "프로젝트 \"{0}\"의 모든 캐시를 지우시겠습니까?", + "ReIndexAllProjects": "모든 프로젝트 다시 인덱싱", + "ReIndexProject": "프로젝트 다시 인덱싱", + "ReIndexProjectConfirmationMessage": "프로젝트 \"{0}\"을(를) 다시 인덱싱하시겠습니까?", + "SuccessfullyReIndexProject": "다시 인덱싱했습니다: \"{0}\"", + "ReIndexAllProjectConfirmationMessage": "모든 프로젝트를 다시 인덱싱하시겠습니까?", + "SuccessfullyReIndexAllProject": "모든 프로젝트를 다시 인덱싱했습니다.", + "InThisDocument": "이 문서에서", + "GoToTop": "맨 위로 이동", + "Projects": "프로젝트", + "NoProjectWarning": "아직 프로젝트가 없습니다!", + "DocumentNotFound": "요청한 문서를 찾을 수 없습니다!", + "ProjectNotFound": "요청한 프로젝트를 찾을 수 없습니다!", + "NavigationDocumentNotFound": "이 버전에는 탐색 문서가 없습니다!", + "DocumentNotFoundInSelectedLanguage": "요청한 언어의 문서를 찾을 수 없어 기본 언어의 문서를 표시합니다.", + "FilterTopics": "주제 필터링", + "FullSearch": "문서에서 검색", + "Volo.Docs.Domain:010001": "Elasticsearch가 활성화되어 있지 않습니다.", + "MultipleVersionDocumentInfo": "이 문서에는 여러 버전이 있습니다. 가장 적합한 옵션을 선택하세요.", + "DocumentOptions": "문서 옵션", + "New": "신규", + "Upd": "업데이트", + "NewExplanation": "최근 2주 이내에 생성되었습니다.", + "UpdatedExplanation": "최근 2주 이내에 업데이트되었습니다.", + "Volo.Docs.Domain:010002": "단축 이름 {ShortName}이(가) 이미 존재합니다.", + "Preview": "미리 보기", + "Search": "검색", + "SearchResults": "검색 결과", + "SearchInTheAllDocuments": "모든 문서에서 검색", + "Next": "다음", + "Previous": "이전", + "ProjectDeletionWarningMessage": "프로젝트가 삭제됩니다.", + "Docs_Page_Title": "ABP 문서", + "Docs_Page_Description": "ABP 문서에서 포괄적인 가이드와 API 참조를 확인하여 개발 및 문제 해결에 활용할 수 있습니다.", + "GoogleTranslate": "Google 번역", + "DownloadPDF": "PDF 다운로드", + "PdfFileGeneratedSuccessfully": "PDF 파일이 생성되었습니다." + } +} diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Projects/Pdf/DocsProjectPdfGeneratorOptions.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Projects/Pdf/DocsProjectPdfGeneratorOptions.cs index 8b8678930d..0a4d085e1c 100644 --- a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Projects/Pdf/DocsProjectPdfGeneratorOptions.cs +++ b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Projects/Pdf/DocsProjectPdfGeneratorOptions.cs @@ -59,9 +59,9 @@ public class DocsProjectPdfGeneratorOptions "; HtmlStyle = @" - body { margin: 15px; line-height: 1.5; font-family: Arial, sans-serif;} - a { text-decoration: none; word-break: break-all; overflow-wrap: break-word;} - li { word-break: break-all; overflow-wrap: break-word; } + body { margin: 15px; line-height: 1.5; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif;} + a { text-decoration: none; overflow-wrap: break-word;} + li { overflow-wrap: break-word; } .page { page-break-after: always; margin-bottom: 30px; @@ -83,10 +83,11 @@ public class DocsProjectPdfGeneratorOptions padding: 2px 6px; border-radius: 4px; border: 1px solid #e2e8f0; - font-family: Consolas, monospace; + font-family: Consolas, 'Courier New', 'Liberation Mono', 'DejaVu Sans Mono', monospace; } pre { position: relative; + word-break: break-all; padding: 16px; border-radius: 8px; border: 1px solid #e2e8f0; @@ -103,9 +104,7 @@ public class DocsProjectPdfGeneratorOptions th, td { border: 1px solid #333; padding: 6px 10px; - word-break: break-all; overflow-wrap: break-word; - width: 100%; }"; CalculatePdfFileName = (project, version, languageCode) => $"{project.ShortName}-{version}-{languageCode}.zip"; diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Projects/Pdf/IText/HtmlIdTagWorkerFactory.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Projects/Pdf/IText/HtmlIdTagWorkerFactory.cs deleted file mode 100644 index 17483a7605..0000000000 --- a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Projects/Pdf/IText/HtmlIdTagWorkerFactory.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System.Collections.Generic; -using iText.Html2pdf.Attach; -using iText.Html2pdf.Attach.Impl; -using iText.Kernel.Pdf.Navigation; -using iText.StyledXmlParser.Node; - -namespace Volo.Docs.Projects.Pdf.IText; - -public class HtmlIdTagWorkerFactory : DefaultTagWorkerFactory -{ - private readonly iText.Kernel.Pdf.PdfDocument _pdfDocument; - private readonly Dictionary _pageDestinations = new(); - - public HtmlIdTagWorkerFactory(iText.Kernel.Pdf.PdfDocument pdfDocument) - { - _pdfDocument = pdfDocument; - } - - public override ITagWorker GetCustomTagWorker(IElementNode tag, ProcessorContext context) - { - var tagClass = tag.GetAttribute("class"); - if (tag.Name().Equals("div") && tagClass =="page") - { - var id = tag.GetAttribute("id"); - _pageDestinations[id] = _pdfDocument.GetNumberOfPages() + 1; - } - - return base.GetCustomTagWorker(tag, context); - } - - public void AddNamedDestinations() - { - foreach (var pageDestination in _pageDestinations) - { - var page = _pdfDocument.GetPage(pageDestination.Value); - var destination = PdfExplicitDestination.CreateFit(page); - _pdfDocument.AddNamedDestination(pageDestination.Key, destination.GetPdfObject()); - } - } -} \ No newline at end of file diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Projects/Pdf/IText/ITextHtmlToPdfRenderer.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Projects/Pdf/IText/ITextHtmlToPdfRenderer.cs deleted file mode 100644 index 308f26f086..0000000000 --- a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Projects/Pdf/IText/ITextHtmlToPdfRenderer.cs +++ /dev/null @@ -1,92 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Threading.Tasks; -using iText.Html2pdf; -using iText.Kernel.Pdf; -using iText.Kernel.Pdf.Action; -using iText.Layout.Font; -using Microsoft.Extensions.Options; -using Volo.Abp.DependencyInjection; -using Volo.Docs.Utils; - -namespace Volo.Docs.Projects.Pdf.IText; - -public class ITextHtmlToPdfRenderer : IHtmlToPdfRenderer, ITransientDependency -{ - protected IOptions Options { get; } - - public ITextHtmlToPdfRenderer(IOptions options) - { - Options = options; - } - - public virtual async Task RenderAsync(string title, string html, List documents) - { - var pdfStream = new MemoryStream(); - using (var pdfWriter = new PdfWriter(pdfStream)) - { - pdfWriter.SetCloseStream(false); - using (var pdfDocument = new iText.Kernel.Pdf.PdfDocument(pdfWriter)) - { - pdfDocument.GetDocumentInfo().SetTitle(title); - await CreatePdfFromHtmlAsync(html, pdfDocument); - await AddOutlinesToPdfAsync(pdfDocument, documents); - } - } - - pdfStream.Position = 0; - return pdfStream; - } - - protected virtual async Task CreatePdfFromHtmlAsync(string html, iText.Kernel.Pdf.PdfDocument pdfDocument) - { - var converter = new ConverterProperties(); - var fontProvider = await GetFontProviderAsync(); - if (fontProvider != null) - { - converter.SetFontProvider(fontProvider); - } - var tagWorkerFactory = new HtmlIdTagWorkerFactory(pdfDocument); - converter.SetTagWorkerFactory(tagWorkerFactory); - HtmlConverter.ConvertToDocument(html, pdfDocument, converter); - tagWorkerFactory.AddNamedDestinations(); - } - - protected virtual Task GetFontProviderAsync() - { - return Task.FromResult(null); - } - - protected virtual Task AddOutlinesToPdfAsync(iText.Kernel.Pdf.PdfDocument pdfDocument, List documents) - { - var pdfOutlines = pdfDocument.GetOutlines(false); - BuildPdfOutlines(pdfOutlines, documents); - - return Task.CompletedTask; - } - - protected virtual Task BuildPdfOutlines(PdfOutline parentOutline, List pdfDocumentNodes) - { - foreach (var pdfDocumentNode in pdfDocumentNodes) - { - if (pdfDocumentNode.IgnoreOnOutline) - { - continue; - } - - var outline = parentOutline.AddOutline(pdfDocumentNode.Title); - if (!pdfDocumentNode.Id.IsNullOrWhiteSpace()) - { - outline.AddAction(UrlHelper.IsExternalLink(pdfDocumentNode.Id) ? PdfAction.CreateURI(pdfDocumentNode.Id) : PdfAction.CreateGoTo(pdfDocumentNode.Id)); - } - - if (pdfDocumentNode.HasChildren) - { - BuildPdfOutlines(outline, pdfDocumentNode.Children); - } - } - - return Task.CompletedTask; - } -} diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Projects/Pdf/Markdig/AnchorLinkRenderer.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Projects/Pdf/Markdig/AnchorLinkRenderer.cs index 881b2915e3..6f9a6afc6e 100644 --- a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Projects/Pdf/Markdig/AnchorLinkRenderer.cs +++ b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Projects/Pdf/Markdig/AnchorLinkRenderer.cs @@ -4,6 +4,7 @@ using Markdig.Renderers; using Markdig.Renderers.Html.Inlines; using Markdig.Syntax.Inlines; using Volo.Docs.Utils; +using MarkdigHtmlRenderer = Markdig.Renderers.HtmlRenderer; namespace Volo.Docs.Projects.Pdf.Markdig; @@ -16,7 +17,7 @@ public class AnchorLinkRenderer : LinkInlineRenderer _document = document; } - protected override void Write(HtmlRenderer renderer, LinkInline link) + protected override void Write(MarkdigHtmlRenderer renderer, LinkInline link) { if (UrlHelper.IsExternalLink(link.Url) || link.Url.IsNullOrWhiteSpace() || link.IsImage) { diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Projects/Pdf/Markdig/AnchorLinkResolverExtension.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Projects/Pdf/Markdig/AnchorLinkResolverExtension.cs index 38405da4d7..83a150f327 100644 --- a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Projects/Pdf/Markdig/AnchorLinkResolverExtension.cs +++ b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Projects/Pdf/Markdig/AnchorLinkResolverExtension.cs @@ -1,6 +1,7 @@ using Markdig; using Markdig.Renderers; using Markdig.Renderers.Html.Inlines; +using MarkdigHtmlRenderer = Markdig.Renderers.HtmlRenderer; namespace Volo.Docs.Projects.Pdf.Markdig; @@ -19,7 +20,7 @@ public class AnchorLinkResolverExtension : IMarkdownExtension public void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer) { - if (renderer is HtmlRenderer htmlRenderer) + if (renderer is MarkdigHtmlRenderer htmlRenderer) { htmlRenderer.ObjectRenderers.Replace(new AnchorLinkRenderer(_document)); } diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Projects/Pdf/PdfSharpHtmlToPdfRenderer.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Projects/Pdf/PdfSharpHtmlToPdfRenderer.cs new file mode 100644 index 0000000000..772dc5cfe1 --- /dev/null +++ b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Projects/Pdf/PdfSharpHtmlToPdfRenderer.cs @@ -0,0 +1,513 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net.Http; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using HtmlAgilityPack; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; +using PdfSharp; +using PdfSharp.Drawing; +using PdfSharp.Fonts; +using PdfSharp.Pdf; +using SkiaSharp; +using TheArtOfDev.HtmlRenderer.Core; +using TheArtOfDev.HtmlRenderer.Core.Entities; +using TheArtOfDev.HtmlRenderer.PdfSharp; +using TheArtOfDev.HtmlRenderer.PdfSharp.FontResolution; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Threading; +using Volo.Docs.Utils; +using PdfSharpDocument = PdfSharp.Pdf.PdfDocument; + +namespace Volo.Docs.Projects.Pdf; + +public class PdfSharpHtmlToPdfRenderer : IHtmlToPdfRenderer, ITransientDependency +{ + private static readonly Regex HtmlEntityRegex = new(@"&(?:#[0-9]+|#x[0-9a-fA-F]+|[a-zA-Z][a-zA-Z0-9]*);", RegexOptions.Compiled); + + public ILogger Logger { get; set; } + + protected IHttpClientFactory HttpClientFactory { get; } + + public PdfSharpHtmlToPdfRenderer(IHttpClientFactory httpClientFactory) + { + HttpClientFactory = httpClientFactory; + Logger = NullLogger.Instance; + } + + public virtual Task RenderAsync(string title, string html, List documents) + { + using var pdfDocument = new PdfSharpDocument(); + pdfDocument.Info.Title = title; + + var config = CreatePdfGenerateConfig(); + var cssData = GetCssData(); + var elementPages = new Dictionary(); + var pendingLinks = new List(); + var images = new Dictionary(); + + var htmlDocument = new HtmlDocument(); + // HtmlRenderer draws a tab in code blocks as a missing glyph. + htmlDocument.LoadHtml(html.Replace("\t", " ")); + ReplaceUnsupportedImages(htmlDocument); + SplitMultiWordLinks(htmlDocument); + BreakLongWords(htmlDocument); + PreserveHtmlEntities(htmlDocument); + + // HtmlRenderer ignores "page-break-after", so every document is laid out separately to start on a new page. + foreach (var page in SplitIntoPages(htmlDocument)) + { + AddPages(pdfDocument, page, config, cssData, elementPages, pendingLinks, images); + } + + foreach (var pendingLink in pendingLinks) + { + var targetPageIndex = FindPageIndex(elementPages, pendingLink.AnchorId); + if (targetPageIndex.HasValue && targetPageIndex.Value != pendingLink.PageIndex) + { + pdfDocument.Pages[pendingLink.PageIndex].AddDocumentLink(pendingLink.Rectangle, targetPageIndex.Value + 1); + } + } + + AddOutlines(pdfDocument, pdfDocument.Outlines, documents, elementPages); + + var pdfStream = new MemoryStream(); + pdfDocument.Save(pdfStream, false); + pdfStream.Position = 0; + return Task.FromResult(pdfStream); + } + + protected virtual PdfGenerateConfig CreatePdfGenerateConfig() + { + var config = new PdfGenerateConfig + { + PageSize = PageSize.A4 + }; + config.SetMargins(36); + return config; + } + + protected virtual CssData GetCssData() + { + return null; + } + + protected virtual void ConfigureFontResolver() + { + // The strict strategy falls back to a Latin-only font when a style is missing (e.g. a CJK font without a bold face). + if (GlobalFontSettings.FontResolver is FontResolver fontResolver) + { + fontResolver.ResolveStrategy = FontResolveStrategy.Closest; + } + } + + protected virtual void ReplaceUnsupportedImages(HtmlDocument htmlDocument) + { + // PDFsharp can not draw SVG images, so they are rendered as links instead of an error icon. + foreach (var image in htmlDocument.DocumentNode.Descendants("img").ToList()) + { + var src = image.GetAttributeValue("src", string.Empty); + var path = src.Split('?')[0]; + if (!path.EndsWith(".svg", StringComparison.OrdinalIgnoreCase)) + { + continue; + } + + var alt = HtmlEntity.DeEntitize(image.GetAttributeValue("alt", string.Empty)); + var link = htmlDocument.CreateElement("a"); + link.SetAttributeValue("href", src); + link.AppendChild(htmlDocument.CreateTextNode(HtmlEntity.Entitize(alt.IsNullOrWhiteSpace() ? Path.GetFileName(path) : alt))); + image.ParentNode.ReplaceChild(link, image); + } + } + + protected virtual void SplitMultiWordLinks(HtmlDocument htmlDocument) + { + // HtmlRenderer only reports the first line of a link, so every word gets its own link to keep wrapped links clickable. + foreach (var link in htmlDocument.DocumentNode.Descendants("a").ToList()) + { + if (link.ChildNodes.Count != 1 || link.FirstChild.NodeType != HtmlNodeType.Text || link.Attributes.Contains("id") || link.Attributes.Contains("name")) + { + continue; + } + + var parts = SplitWords(link.FirstChild.InnerHtml); + if (parts.Count(part => !part.IsNullOrWhiteSpace()) <= 1) + { + continue; + } + + foreach (var part in parts) + { + if (part.IsNullOrWhiteSpace()) + { + link.ParentNode.InsertBefore(htmlDocument.CreateTextNode(part), link); + continue; + } + + var wordLink = link.CloneNode(false); + wordLink.AppendChild(htmlDocument.CreateTextNode(part)); + link.ParentNode.InsertBefore(wordLink, link); + } + + link.Remove(); + } + } + + protected virtual void BreakLongWords(HtmlDocument htmlDocument) + { + // HtmlRenderer does not support "overflow-wrap: break-word": a word wider than its line is clipped, and "word-break: break-all" breaks every word. + // So only the words that can not fit are allowed to break anywhere. + foreach (var textNode in htmlDocument.DocumentNode.Descendants().OfType().ToList()) + { + if (textNode.ParentNode.Name is "style" or "script" or "title" || textNode.Ancestors("pre").Any()) + { + continue; + } + + var maxWordLength = GetMaxWordLength(textNode); + var parts = SplitWords(textNode.Text); + if (!parts.Any(part => IsLongWord(part, maxWordLength))) + { + continue; + } + + foreach (var part in parts) + { + if (!IsLongWord(part, maxWordLength)) + { + textNode.ParentNode.InsertBefore(htmlDocument.CreateTextNode(part), textNode); + continue; + } + + var span = htmlDocument.CreateElement("span"); + span.SetAttributeValue("style", "word-break: break-all"); + span.AppendChild(htmlDocument.CreateTextNode(part)); + textNode.ParentNode.InsertBefore(span, textNode); + } + + textNode.Remove(); + } + } + + protected virtual int GetMaxWordLength(HtmlNode textNode) + { + // A line of the default style holds about 90 characters, but table columns are not equally wide and code uses a wider font. + var cell = textNode.Ancestors().FirstOrDefault(node => node.Name is "td" or "th"); + if (cell == null) + { + return 40; + } + + var columnCount = cell.ParentNode.ChildNodes + .Where(node => node.Name is "td" or "th") + .Sum(node => Math.Max(node.GetAttributeValue("colspan", 1), 1)); + var maxLength = Math.Max(45 / columnCount, 6); + + return textNode.Ancestors("code").Any() ? maxLength * 3 / 4 : maxLength; + } + + private static bool IsLongWord(string text, int maxLength) + { + return !text.IsNullOrWhiteSpace() && HtmlEntity.DeEntitize(text).Length > maxLength; + } + + protected virtual void PreserveHtmlEntities(HtmlDocument htmlDocument) + { + // HtmlRenderer splits "word-break: break-all" text into single characters before decoding it, so "&" would be printed as is. + foreach (var textNode in htmlDocument.DocumentNode.Descendants().OfType().ToList()) + { + if (textNode.ParentNode.Name is "style" or "script" or "title" || !HtmlEntityRegex.IsMatch(textNode.Text)) + { + continue; + } + + var index = 0; + foreach (Match entity in HtmlEntityRegex.Matches(textNode.Text)) + { + if (entity.Index > index) + { + textNode.ParentNode.InsertBefore(htmlDocument.CreateTextNode(textNode.Text.Substring(index, entity.Index - index)), textNode); + } + + var span = htmlDocument.CreateElement("span"); + span.SetAttributeValue("style", "word-break: normal"); + span.AppendChild(htmlDocument.CreateTextNode(entity.Value)); + textNode.ParentNode.InsertBefore(span, textNode); + index = entity.Index + entity.Length; + } + + if (index < textNode.Text.Length) + { + textNode.ParentNode.InsertBefore(htmlDocument.CreateTextNode(textNode.Text.Substring(index)), textNode); + } + + textNode.Remove(); + } + } + + protected virtual List SplitIntoPages(HtmlDocument htmlDocument) + { + var pageNodes = htmlDocument.DocumentNode.Descendants("div") + .Where(node => node.HasClass("page") && !node.Ancestors("div").Any(ancestor => ancestor.HasClass("page"))) + .ToList(); + + if (pageNodes.Count <= 1) + { + return [new PdfPageHtml(pageNodes.FirstOrDefault()?.Id, htmlDocument.DocumentNode.OuterHtml)]; + } + + // Every page is rendered with the rest of the layout, in place of the first page. + const string placeholder = "docs-pdf-page-placeholder"; + pageNodes[0].ParentNode.InsertBefore(htmlDocument.CreateComment($""), pageNodes[0]); + var pages = pageNodes.Select(node => (node.Id, node.OuterHtml)).ToList(); + pageNodes.ForEach(node => node.Remove()); + + var layout = htmlDocument.DocumentNode.OuterHtml; + return pages.Select(page => new PdfPageHtml(page.Id, layout.Replace($"", page.OuterHtml))).ToList(); + } + + protected virtual List SplitWords(string text) + { + var parts = new List(); + var start = 0; + for (var i = 1; i <= text.Length; i++) + { + if (i == text.Length || char.IsWhiteSpace(text[i]) != char.IsWhiteSpace(text[start])) + { + parts.Add(text.Substring(start, i - start)); + start = i; + } + } + + return parts; + } + + protected virtual void AddPages( + PdfSharpDocument pdfDocument, + PdfPageHtml page, + PdfGenerateConfig config, + CssData cssData, + Dictionary elementPages, + List pendingLinks, + Dictionary images) + { + var pageSize = PageSizeConverter.ToSize(config.PageSize); + if (config.PageOrientation == PageOrientation.Landscape) + { + pageSize = new XSize(pageSize.Height, pageSize.Width); + } + + var contentSize = new XSize( + pageSize.Width - config.MarginLeft - config.MarginRight, + pageSize.Height - config.MarginTop - config.MarginBottom); + + using var container = new HtmlContainer(); + ConfigureFontResolver(); + container.ImageLoad += (_, args) => LoadImage(args, images); + container.RenderError += (_, args) => Logger.LogWarning(args.Exception, "PDF rendering error: {Message}", args.Message); + container.Location = new XPoint(config.MarginLeft, config.MarginTop); + container.MaxSize = new XSize(contentSize.Width, 0); + container.SetHtml(page.Html, cssData); + container.PageSize = contentSize; + container.MarginTop = config.MarginTop; + container.MarginBottom = config.MarginBottom; + container.MarginLeft = config.MarginLeft; + container.MarginRight = config.MarginRight; + + using (var measure = XGraphics.CreateMeasureContext(contentSize, XGraphicsUnit.Point, XPageDirection.Downwards)) + { + container.PerformLayout(measure); + } + + var firstPageIndex = pdfDocument.PageCount; + for (var offset = 0.0; offset > -container.ActualSize.Height; offset -= contentSize.Height) + { + var pdfPage = pdfDocument.AddPage(); + pdfPage.Width = XUnit.FromPoint(pageSize.Width); + pdfPage.Height = XUnit.FromPoint(pageSize.Height); + using var graphics = XGraphics.FromPdfPage(pdfPage); + graphics.IntersectClip(new XRect(0, 0, pdfPage.Width.Point, pdfPage.Height.Point)); + container.ScrollOffset = new XPoint(0, offset); + container.PerformPaint(graphics); + } + + int GetPageIndex(XRect rectangle) + { + var index = firstPageIndex + (int)((rectangle.Top - config.MarginTop) / contentSize.Height); + return Math.Clamp(index, firstPageIndex, pdfDocument.PageCount - 1); + } + + double GetTopOnPage(XRect rectangle, int pageIndex) + { + return rectangle.Top - contentSize.Height * (pageIndex - firstPageIndex); + } + + var pageRectangle = page.Id.IsNullOrEmpty() ? null : container.GetElementRectangle(page.Id); + if (pageRectangle.HasValue) + { + elementPages.TryAdd(page.Id, GetPageIndex(pageRectangle.Value)); + } + + foreach (var link in container.GetLinks()) + { + var pageIndex = GetPageIndex(link.Rectangle); + var top = GetTopOnPage(link.Rectangle, pageIndex); + var rectangle = new PdfRectangle(new XRect( + link.Rectangle.Left, + pageSize.Height - top - link.Rectangle.Height, + link.Rectangle.Width, + link.Rectangle.Height)); + + if (!link.IsAnchor) + { + if (!link.Href.IsNullOrWhiteSpace()) + { + pdfDocument.Pages[pageIndex].AddWebLink(rectangle, link.Href); + } + + continue; + } + + // The Markdown converter writes "##id" for anchors in the same document. + var anchorId = link.AnchorId.TrimStart('#'); + if (anchorId.IsNullOrWhiteSpace()) + { + continue; + } + + var targetRectangle = container.GetElementRectangle(anchorId); + if (targetRectangle.HasValue) + { + var targetPageIndex = GetPageIndex(targetRectangle.Value); + var targetPoint = new XPoint(targetRectangle.Value.Left, pageSize.Height - GetTopOnPage(targetRectangle.Value, targetPageIndex)); + pdfDocument.Pages[pageIndex].AddDocumentLink(rectangle, targetPageIndex + 1, targetPoint); + continue; + } + + pendingLinks.Add(new PendingDocumentLink(pageIndex, rectangle, anchorId)); + } + } + + protected virtual void LoadImage(HtmlImageLoadEventArgs args, Dictionary images) + { + if (args.Src.IsNullOrWhiteSpace() || args.Src.StartsWith("data:image", StringComparison.OrdinalIgnoreCase)) + { + return; + } + + // Only remote images are loaded, so a document can not read files from the server. + if (!Uri.TryCreate(args.Src, UriKind.Absolute, out var uri) || (uri.Scheme != Uri.UriSchemeHttp && uri.Scheme != Uri.UriSchemeHttps)) + { + Logger.LogWarning("The image {ImageUrl} is not an HTTP(S) URL and is not added to the PDF file.", args.Src); + args.Handled = true; + args.Callback(); + return; + } + + if (!images.TryGetValue(args.Src, out var image)) + { + try + { + var bytes = AsyncHelper.RunSync(() => DownloadImageAsync(uri)); + image = CreateImage(bytes); + } + catch (Exception e) + { + Logger.LogWarning(e, "Could not load the image {ImageUrl} for the PDF file.", args.Src); + } + + images[args.Src] = image; + } + + // A failed image is not handed back to HtmlRenderer, so its own downloader can not load it without the limits above. + args.Handled = true; + if (image != null) + { + args.Callback(image); + } + else + { + args.Callback(); + } + } + + protected virtual async Task DownloadImageAsync(Uri uri) + { + var client = HttpClientFactory.CreateClient(); + client.Timeout = TimeSpan.FromSeconds(30); + client.MaxResponseContentBufferSize = 20 * 1024 * 1024; + return await client.GetByteArrayAsync(uri); + } + + protected virtual XImage CreateImage(byte[] bytes) + { + try + { + return XImage.FromStream(new MemoryStream(bytes)); + } + catch (Exception) + { + // PDFsharp reads PNG, JPEG and BMP only (and not every JPEG), so other images are converted to PNG. An animated GIF keeps its first frame. + using var bitmap = SKBitmap.Decode(bytes) ?? throw new NotSupportedException("The image format is not supported."); + using var data = bitmap.Encode(SKEncodedImageFormat.Png, 100); + return XImage.FromStream(new MemoryStream(data.ToArray())); + } + } + + protected virtual void AddOutlines( + PdfSharpDocument pdfDocument, + PdfOutlineCollection outlines, + List documents, + Dictionary elementPages) + { + foreach (var document in documents) + { + if (document.IgnoreOnOutline) + { + continue; + } + + var pageIndex = FindPageIndex(elementPages, document.Id); + var outline = pageIndex.HasValue + ? outlines.Add(document.Title, pdfDocument.Pages[pageIndex.Value]) + : outlines.Add(document.Title, null); + + if (!pageIndex.HasValue && UrlHelper.IsExternalLink(document.Id)) + { + var action = new PdfDictionary(pdfDocument); + action.Elements.SetName("/S", "/URI"); + action.Elements.SetString("/URI", document.Id); + outline.Elements["/A"] = action; + } + + if (document.HasChildren) + { + AddOutlines(pdfDocument, outline.Outlines, document.Children, elementPages); + } + } + } + + protected virtual int? FindPageIndex(Dictionary elementPages, string id) + { + if (id.IsNullOrWhiteSpace()) + { + return null; + } + + if (elementPages.TryGetValue(id, out var pageIndex)) + { + return pageIndex; + } + + var documentId = id.Split('#').FirstOrDefault(); + return documentId != null && elementPages.TryGetValue(documentId, out pageIndex) ? pageIndex : null; + } + + protected record PdfPageHtml(string Id, string Html); + + protected record PendingDocumentLink(int PageIndex, PdfRectangle Rectangle, string AnchorId); +} diff --git a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml index e031837165..91b9841a65 100644 --- a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml +++ b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml @@ -10,7 +10,6 @@ @using Volo.Abp.AspNetCore.Mvc.UI.Layout @using Volo.Abp.AspNetCore.Mvc.UI.Packages.Anchor @using Volo.Abp.AspNetCore.Mvc.UI.Packages.Clipboard -@using Volo.Abp.AspNetCore.Mvc.UI.Packages.MalihuCustomScrollbar @using Volo.Abp.AspNetCore.Mvc.UI.Packages.Popper @using Volo.Abp.AspNetCore.Mvc.UI.Packages.Prismjs @using Volo.Abp.AspNetCore.Mvc.UI.Theming @@ -38,7 +37,6 @@ @section styles { - @if (DocsUiOptions.Value.EnableEnlargeImage) @@ -64,7 +62,6 @@ } - @@ -306,7 +303,7 @@
-
ConfirmationIsEnabledForGetRequestsx
") + .ShouldBe("
ConfirmationIsEnabledForGetRequestsx
"); + renderer.BreakWords("
xConfirmation
") + .ShouldBe("
xConfirmation
"); + renderer.BreakWords("
AIManagement.WorkspaceAIManagement.Workspace
") + .ShouldBe("
AIManagement.WorkspaceAIManagement.Workspace
"); + } + + [Fact] + public void Should_Split_Multi_Word_Links_Only() + { + var renderer = CreateTestRenderer(); + + renderer.SplitLinks("Tips & Tricks").ShouldBe("Tips & Tricks"); + renderer.SplitLinks("Single").ShouldBe("Single"); + renderer.SplitLinks("Two words").ShouldBe("Two words"); + renderer.SplitLinks("Two words").ShouldBe("Two words"); + } + + [Fact] + public void Should_Replace_Svg_Images_With_Links() + { + CreateTestRenderer().ReplaceImages("\"Diagram\"") + .ShouldBe("Diagram"); + } + + [Fact] + public async Task Should_Not_Load_Local_Images() + { + var imagePath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N") + ".png"); + using (var bitmap = new SKBitmap(3, 3)) + using (var data = bitmap.Encode(SKEncodedImageFormat.Png, 100)) + { + await File.WriteAllBytesAsync(imagePath, data.ToArray()); + } + + try + { + var pdf = await RenderAsync( + $"

Text

", + [new PdfDocument { Title = "First", Id = "first" }]); + + var images = pdf.Pages[0].Resources.Elements.GetDictionary("/XObject")?.Elements.Values + .Select(x => (PdfDictionary)((PdfReference)x).Value) + .ToList() ?? []; + images.ShouldNotContain(x => x.Elements.GetInteger("/Width") == 3); + } + finally + { + File.Delete(imagePath); + } + } + + [Fact] + public async Task Should_Not_Download_A_Failed_Image_Again() + { + var gif = System.Convert.FromBase64String("R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"); + var port = GetFreePort(); + using var listener = new HttpListener(); + listener.Prefixes.Add($"http://localhost:{port}/"); + listener.Start(); + var requestCount = 0; + _ = Task.Run(async () => + { + while (listener.IsListening) + { + try + { + var context = await listener.GetContextAsync(); + Interlocked.Increment(ref requestCount); + await context.Response.OutputStream.WriteAsync(gif); + context.Response.Close(); + } + catch (HttpListenerException) + { + return; + } + } + }); + + var renderer = new FailingDownloadPdfSharpHtmlToPdfRenderer(GetRequiredService()); + var html = $"
"; + await using var stream = await renderer.RenderAsync("Test", html, [new PdfDocument { Title = "First", Id = "first" }]); + + requestCount.ShouldBe(0); + } + + [Fact] + public void Should_Convert_Gif_Images() + { + var gif = System.Convert.FromBase64String("R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"); + + var image = CreateTestRenderer().CreatePdfImage(gif); + + image.PixelWidth.ShouldBe(1); + image.PixelHeight.ShouldBe(1); + } + + private TestPdfSharpHtmlToPdfRenderer CreateTestRenderer() + { + return new TestPdfSharpHtmlToPdfRenderer(GetRequiredService()); + } + + private async Task RenderAsync(string content, List documents) + { + var html = $"{content}"; + await using var stream = await _htmlToPdfRenderer.RenderAsync("Test", html, documents); + return PdfReader.Open(stream, PdfDocumentOpenMode.Import); + } + + private static List GetOutlines(PdfSharp.Pdf.PdfDocument pdf) + { + var result = new List(); + AddOutlines(pdf, pdf.Outlines, string.Empty, result); + return result; + } + + private static void AddOutlines(PdfSharp.Pdf.PdfDocument pdf, PdfOutlineCollection outlines, string indent, List result) + { + foreach (var outline in outlines) + { + var destination = outline.Elements.GetArray("/Dest"); + var target = destination != null + ? GetPageNumber(pdf, destination.Elements[0]).ToString() + : outline.Elements.GetDictionary("/A")?.Elements.GetString("/URI"); + result.Add($"{indent}{outline.Title}:{target}"); + AddOutlines(pdf, outline.Outlines, indent + " ", result); + } + } + + private static List GetAnnotations(PdfSharp.Pdf.PdfDocument pdf, PdfPage page) + { + var annotations = page.Elements.GetArray("/Annots"); + if (annotations == null) + { + return []; + } + + return annotations.Elements + .Select(x => (PdfDictionary)((PdfReference)x).Value) + .Select(x => x.Elements.GetArray("/Dest") is { } destination + ? $"page:{GetPageNumber(pdf, destination.Elements[0])}" + : $"uri:{x.Elements.GetDictionary("/A")?.Elements.GetString("/URI")}") + .ToList(); + } + + private static int GetPageNumber(PdfSharp.Pdf.PdfDocument pdf, PdfItem pageReference) + { + return pdf.Pages.Cast().ToList().FindIndex(x => x.Reference == pageReference) + 1; + } + + private static int GetFreePort() + { + using var socket = new System.Net.Sockets.TcpListener(IPAddress.Loopback, 0); + socket.Start(); + return ((IPEndPoint)socket.LocalEndpoint).Port; + } + + [DisableConventionalRegistration] + private class FailingDownloadPdfSharpHtmlToPdfRenderer : PdfSharpHtmlToPdfRenderer + { + public FailingDownloadPdfSharpHtmlToPdfRenderer(IHttpClientFactory httpClientFactory) + : base(httpClientFactory) + { + } + + protected override Task DownloadImageAsync(Uri uri) + { + throw new HttpRequestException("The host does not allow this request."); + } + } + + [DisableConventionalRegistration] + private class TestPdfSharpHtmlToPdfRenderer : PdfSharpHtmlToPdfRenderer + { + public TestPdfSharpHtmlToPdfRenderer(IHttpClientFactory httpClientFactory) + : base(httpClientFactory) + { + } + + public string PreserveEntities(string html) + { + return Transform(html, PreserveHtmlEntities); + } + + public string SplitLinks(string html) + { + return Transform(html, SplitMultiWordLinks); + } + + public string BreakWords(string html) + { + return Transform(html, BreakLongWords); + } + + public string ReplaceImages(string html) + { + return Transform(html, ReplaceUnsupportedImages); + } + + private static string Transform(string html, Action action) + { + var htmlDocument = new HtmlDocument(); + htmlDocument.LoadHtml(html); + action(htmlDocument); + return htmlDocument.DocumentNode.OuterHtml; + } + + public XImage CreatePdfImage(byte[] image) + { + return CreateImage(image); + } + } +} diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/ko.json b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/ko.json new file mode 100644 index 0000000000..6603762f4d --- /dev/null +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/ko.json @@ -0,0 +1,17 @@ +{ + "culture": "ko", + "texts": { + "Features": "기능", + "NoFeatureFoundMessage": "사용 가능한 기능이 없습니다.", + "ManageHostFeatures": "호스트 기능 관리", + "ManageHostFeaturesText": "다음 버튼을 클릭하여 호스트 측 기능을 관리할 수 있습니다.", + "Permission:FeatureManagement": "기능 관리", + "Permission:FeatureManagement.ManageHostFeatures": "호스트 기능 관리", + "Volo.Abp.FeatureManagement:InvalidFeatureValue": "{0} 기능 값이 유효하지 않습니다!", + "Menu:FeatureManagement": "기능 관리", + "ResetToDefault": "기본값으로 재설정", + "ResetedToDefault": "기본값으로 재설정됨", + "AreYouSure": "계속하시겠습니까?", + "AreYouSureToResetToDefault": "기본값으로 재설정하시겠습니까?" + } +} diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo.Abp.FeatureManagement.Domain.csproj b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo.Abp.FeatureManagement.Domain.csproj index bbb2419515..5044a067b1 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo.Abp.FeatureManagement.Domain.csproj +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo.Abp.FeatureManagement.Domain.csproj @@ -18,8 +18,4 @@ - - - - diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/AbpFeatureManagementDomainModule.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/AbpFeatureManagementDomainModule.cs index 1c465817f2..21bd522145 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/AbpFeatureManagementDomainModule.cs +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/AbpFeatureManagementDomainModule.cs @@ -5,7 +5,6 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using Polly; using Volo.Abp.Caching; using Volo.Abp.Data; using Volo.Abp.DependencyInjection; diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/FeatureDynamicInitializer.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/FeatureDynamicInitializer.cs index d96b7b3800..0a209cbded 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/FeatureDynamicInitializer.cs +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/FeatureDynamicInitializer.cs @@ -6,7 +6,6 @@ using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; -using Polly; using Volo.Abp.DependencyInjection; using Volo.Abp.Features; using Volo.Abp.Threading; @@ -95,17 +94,8 @@ public class FeatureDynamicInitializer : ITransientDependency var staticFeatureSaver = ServiceProvider.GetRequiredService(); - await Policy - .Handle() - .WaitAndRetryAsync( - 8, - retryAttempt => TimeSpan.FromSeconds( - Volo.Abp.RandomHelper.GetRandom( - (int)Math.Pow(2, retryAttempt) * 8, - (int)Math.Pow(2, retryAttempt) * 12) - ) - ) - .ExecuteAsync(async _ => + await RetryHelper.ExecuteAsync( + async _ => { try { @@ -114,9 +104,20 @@ public class FeatureDynamicInitializer : ITransientDependency catch (Exception ex) { Logger.LogException(ex); - throw; // Polly will catch it + throw; // RetryHelper will catch it } - }, cancellationToken); + }, + new RetryOptions + { + MaxRetryCount = 8, + DelayFactory = retryAttempt => TimeSpan.FromSeconds( + Volo.Abp.RandomHelper.GetRandom( + (int)Math.Pow(2, retryAttempt) * 8, + (int)Math.Pow(2, retryAttempt) * 12) + ), + ShouldRetryOnException = _ => true + }, + cancellationToken); } protected virtual async Task PreCacheDynamicFeaturesAsync( diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/FeatureManagementStore.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/FeatureManagementStore.cs index d61738afb2..e03aa04932 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/FeatureManagementStore.cs +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/FeatureManagementStore.cs @@ -1,6 +1,8 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; using Volo.Abp.Caching; using Volo.Abp.DependencyInjection; using Volo.Abp.Features; @@ -11,6 +13,8 @@ namespace Volo.Abp.FeatureManagement; public class FeatureManagementStore : IFeatureManagementStore, ITransientDependency { + public ILogger Logger { get; set; } + protected IDistributedCache Cache { get; } protected IFeatureDefinitionManager FeatureDefinitionManager { get; } protected IFeatureValueRepository FeatureValueRepository { get; } @@ -26,6 +30,7 @@ public class FeatureManagementStore : IFeatureManagementStore, ITransientDepende GuidGenerator = guidGenerator; Cache = cache; FeatureDefinitionManager = featureDefinitionManager; + Logger = NullLogger.Instance; } [UnitOfWork] @@ -38,7 +43,7 @@ public class FeatureManagementStore : IFeatureManagementStore, ITransientDepende [UnitOfWork] public virtual async Task SetAsync(string name, string value, string providerName, string providerKey) { - var featureValue = await FeatureValueRepository.FindAsync(name, providerName, providerKey); + var featureValue = await FindAndDeleteDuplicatesAsync(name, providerName, providerKey); if (featureValue == null) { featureValue = new FeatureValue(GuidGenerator.Create(), name, value, providerName, providerKey); @@ -88,8 +93,10 @@ public class FeatureManagementStore : IFeatureManagementStore, ITransientDepende FeatureValueCacheItem currentCacheItem) { var featureDefinitions = await FeatureDefinitionManager.GetAllAsync(); - var featuresDictionary = (await FeatureValueRepository.GetListAsync(providerName, providerKey)) - .ToDictionary(s => s.Name, s => s.Value); + var featuresDictionary = await CreateFeatureValueDictionaryAsync( + await FeatureValueRepository.GetListAsync(providerName, providerKey), + providerName, + providerKey); var cacheItems = new List>(); @@ -113,6 +120,51 @@ public class FeatureManagementStore : IFeatureManagementStore, ITransientDepende await Cache.SetManyAsync(cacheItems, considerUow: true); } + protected virtual async Task FindAndDeleteDuplicatesAsync(string name, string providerName, string providerKey) + { + var featureValue = await FeatureValueRepository.FindAsync(name, providerName, providerKey); + if (featureValue == null) + { + return null; + } + + var duplicates = (await FeatureValueRepository.FindAllAsync(name, providerName, providerKey)) + .Where(x => x.Id != featureValue.Id); + foreach (var duplicate in duplicates) + { + await FeatureValueRepository.DeleteAsync(duplicate, true); + } + + return featureValue; + } + + protected virtual async Task> CreateFeatureValueDictionaryAsync( + List featureValues, + string providerName, + string providerKey) + { + var featuresDictionary = new Dictionary(); + + foreach (var featureValueGroup in featureValues.GroupBy(s => s.Name)) + { + if (featureValueGroup.Count() == 1) + { + featuresDictionary[featureValueGroup.Key] = featureValueGroup.First().Value; + continue; + } + + // FindAsync returns the same record that SetAsync updates, so reads and writes agree until the duplicates are deleted. + Logger.LogWarning( + "Found {Count} feature value records for Name = {Name}, ProviderName = {ProviderName}, ProviderKey = {ProviderKey}. The duplicates will be deleted the next time the feature value is saved.", + featureValueGroup.Count(), featureValueGroup.Key, providerName, providerKey); + + var featureValue = await FeatureValueRepository.FindAsync(featureValueGroup.Key, providerName, providerKey); + featuresDictionary[featureValueGroup.Key] = (featureValue ?? featureValueGroup.First()).Value; + } + + return featuresDictionary; + } + protected virtual string CalculateCacheKey(string name, string providerName, string providerKey) { return FeatureValueCacheItem.CalculateCacheKey(name, providerName, providerKey); diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.EntityFrameworkCore/Volo/Abp/FeatureManagement/EntityFrameworkCore/EfCoreFeatureValueRepository.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.EntityFrameworkCore/Volo/Abp/FeatureManagement/EntityFrameworkCore/EfCoreFeatureValueRepository.cs index 555682d56d..0c70e798cc 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.EntityFrameworkCore/Volo/Abp/FeatureManagement/EntityFrameworkCore/EfCoreFeatureValueRepository.cs +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.EntityFrameworkCore/Volo/Abp/FeatureManagement/EntityFrameworkCore/EfCoreFeatureValueRepository.cs @@ -4,7 +4,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; -using Polly; using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore; diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Web/Pages/FeatureManagement/feature-management-modal.css b/modules/feature-management/src/Volo.Abp.FeatureManagement.Web/Pages/FeatureManagement/feature-management-modal.css index 921a40b160..40563343a7 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.Web/Pages/FeatureManagement/feature-management-modal.css +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Web/Pages/FeatureManagement/feature-management-modal.css @@ -4,8 +4,12 @@ .custom-scroll-content { max-height: 400px; + overflow-y: auto; + scrollbar-width: thin; } .custom-scroll-container > .col-md-4 { max-height: 500px; + overflow-y: auto; + scrollbar-width: thin; } diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Web/Pages/FeatureManagement/feature-management-modal.js b/modules/feature-management/src/Volo.Abp.FeatureManagement.Web/Pages/FeatureManagement/feature-management-modal.js index 329908ed10..7b371c5c7b 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.Web/Pages/FeatureManagement/feature-management-modal.js +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Web/Pages/FeatureManagement/feature-management-modal.js @@ -100,15 +100,6 @@ var abp = abp || {}; }); }); }); - - $(function () { - $('.custom-scroll-content').mCustomScrollbar({ - theme: 'minimal-dark', - }); - $('.custom-scroll-container > .col-md-4').mCustomScrollbar({ - theme: 'minimal-dark', - }); - }); }; }; })(jQuery); diff --git a/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Volo/Abp/FeatureManagement/FeatureManagementStore_Tests.cs b/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Volo/Abp/FeatureManagement/FeatureManagementStore_Tests.cs index bec82eaada..c18067506f 100644 --- a/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Volo/Abp/FeatureManagement/FeatureManagementStore_Tests.cs +++ b/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Volo/Abp/FeatureManagement/FeatureManagementStore_Tests.cs @@ -141,4 +141,52 @@ public abstract class FeatureManagementStore_Tests : FeatureMana TestEditionIds.Regular.ToString())).ShouldBeNull(); } } + + [Fact] + public async Task GetOrNullAsync_Should_Not_Fail_When_Duplicate_Host_Values_Exist() + { + // Arrange + await InsertDuplicateHostFeatureValuesAsync(TestFeatureDefinitionProvider.SocialLogins); + + // Act & Assert + (await FeatureManagementStore.GetOrNullAsync(TestFeatureDefinitionProvider.UserCount, + TenantFeatureValueProvider.ProviderName, + null)).ShouldBeNull(); + + (await FeatureManagementStore.GetOrNullAsync(TestFeatureDefinitionProvider.SocialLogins, + TenantFeatureValueProvider.ProviderName, + null)).ShouldBe((await FeatureValueRepository.FindAsync(TestFeatureDefinitionProvider.SocialLogins, + TenantFeatureValueProvider.ProviderName, + null)).Value); + } + + [Fact] + public async Task SetAsync_Should_Remove_Duplicate_Host_Values() + { + // Arrange + await InsertDuplicateHostFeatureValuesAsync(TestFeatureDefinitionProvider.SocialLogins); + + // Act + await FeatureManagementStore.SetAsync(TestFeatureDefinitionProvider.SocialLogins, + false.ToString().ToUpperInvariant(), + TenantFeatureValueProvider.ProviderName, + null); + + // Assert + var featureValues = await FeatureValueRepository.FindAllAsync(TestFeatureDefinitionProvider.SocialLogins, + TenantFeatureValueProvider.ProviderName, + null); + featureValues.Count.ShouldBe(1); + featureValues[0].Value.ShouldBe(false.ToString().ToUpperInvariant()); + } + + private async Task InsertDuplicateHostFeatureValuesAsync(string name) + { + await FeatureValueRepository.InsertAsync(new FeatureValue(Guid.NewGuid(), name, + true.ToString().ToLowerInvariant(), TenantFeatureValueProvider.ProviderName, null)); + await FeatureValueRepository.InsertAsync(new FeatureValue(Guid.NewGuid(), name, + false.ToString().ToLowerInvariant(), TenantFeatureValueProvider.ProviderName, null)); + + (await FeatureValueRepository.FindAllAsync(name, TenantFeatureValueProvider.ProviderName, null)).Count.ShouldBe(2); + } } diff --git a/modules/identity/src/Volo.Abp.Identity.Blazor.MudBlazor/Pages/Identity/UserManagement.razor b/modules/identity/src/Volo.Abp.Identity.Blazor.MudBlazor/Pages/Identity/UserManagement.razor index 061a1e33b6..1759acf5d2 100644 --- a/modules/identity/src/Volo.Abp.Identity.Blazor.MudBlazor/Pages/Identity/UserManagement.razor +++ b/modules/identity/src/Volo.Abp.Identity.Blazor.MudBlazor/Pages/Identity/UserManagement.razor @@ -62,14 +62,18 @@ Label="@L["DisplayName:Name"]" /> - +
+ + +
- +
+ + +
- @@ -228,8 +229,9 @@ - diff --git a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/Localization/ko.json b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/Localization/ko.json new file mode 100644 index 0000000000..a46c0434fd --- /dev/null +++ b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/Localization/ko.json @@ -0,0 +1,143 @@ +{ + "culture": "ko", + "texts": { + "Menu:IdentityManagement": "ID 관리", + "Users": "사용자", + "NewUser": "새 사용자", + "UserName": "사용자 이름", + "Surname": "성", + "EmailAddress": "이메일 주소", + "PhoneNumber": "전화번호", + "UserInformations": "사용자 정보", + "DisplayName:IsDefault": "기본값", + "DisplayName:IsStatic": "정적", + "DisplayName:IsPublic": "공개", + "Roles": "역할", + "Password": "비밀번호", + "PersonalInfo": "내 프로필", + "PersonalSettings": "개인 설정", + "UserDeletionConfirmationMessage": "사용자 '{0}'을(를) 삭제합니다. 계속하시겠습니까?", + "RoleDeletionConfirmationMessage": "역할 '{0}'을(를) 삭제합니다. 계속하시겠습니까?", + "DisplayName:RoleName": "역할 이름", + "DisplayName:UserName": "사용자 이름", + "DisplayName:Name": "이름", + "DisplayName:Surname": "성", + "DisplayName:Password": "비밀번호", + "DisplayName:Email": "이메일 주소", + "DisplayName:PhoneNumber": "전화번호", + "DisplayName:TwoFactorEnabled": "2단계 인증", + "DisplayName:IsActive": "활성", + "DisplayName:LockoutEnabled": "계정 잠금", + "Description:LockoutEnabled": "로그인 실패 시 계정을 잠급니다.", + "NewRole": "새 역할", + "RoleName": "역할 이름", + "CreationTime": "생성 시간", + "Permissions": "권한", + "DisplayName:CurrentPassword": "현재 비밀번호", + "DisplayName:NewPassword": "새 비밀번호", + "DisplayName:NewPasswordConfirm": "새 비밀번호 확인", + "PasswordChangedMessage": "비밀번호가 변경되었습니다.", + "PersonalSettingsSavedMessage": "개인 설정이 저장되었습니다.", + "Volo.Abp.Identity:DefaultError": "알 수 없는 오류가 발생했습니다.", + "Volo.Abp.Identity:ConcurrencyFailure": "낙관적 동시성 검사에 실패했습니다. 작업 중인 엔터티가 다른 사용자에 의해 수정되었습니다. 변경 내용을 취소하고 다시 시도하십시오.", + "Volo.Abp.Identity:DuplicateEmail": "이메일 주소 '{0}'은(는) 이미 사용 중입니다.", + "Volo.Abp.Identity:DuplicateRoleName": "역할 이름 '{0}'은(는) 이미 사용 중입니다.", + "Volo.Abp.Identity:DuplicateUserName": "사용자 이름 '{0}'은(는) 이미 사용 중입니다.", + "Volo.Abp.Identity:InvalidEmail": "이메일 주소 '{0}'은(는) 유효하지 않습니다.", + "Volo.Abp.Identity:InvalidPasswordHasherCompatibilityMode": "제공된 PasswordHasherCompatibilityMode가 유효하지 않습니다.", + "Volo.Abp.Identity:InvalidPasswordHasherIterationCount": "반복 횟수는 양의 정수여야 합니다.", + "Volo.Abp.Identity:InvalidRoleName": "역할 이름 '{0}'은(는) 유효하지 않습니다.", + "Volo.Abp.Identity:InvalidToken": "토큰이 유효하지 않습니다.", + "Volo.Abp.Identity:InvalidUserName": "사용자 이름 '{0}'은(는) 유효하지 않습니다.", + "Volo.Abp.Identity:LoginAlreadyAssociated": "이 로그인 정보와 연결된 사용자가 이미 존재합니다.", + "Volo.Abp.Identity:PasswordMismatch": "비밀번호가 올바르지 않습니다.", + "Volo.Abp.Identity:PasswordRequiresDigit": "비밀번호에는 숫자('0'~'9')가 하나 이상 포함되어야 합니다.", + "Volo.Abp.Identity:PasswordRequiresLower": "비밀번호에는 소문자('a'~'z')가 하나 이상 포함되어야 합니다.", + "Volo.Abp.Identity:PasswordRequiresNonAlphanumeric": "비밀번호에는 영숫자가 아닌 문자가 하나 이상 포함되어야 합니다.", + "Volo.Abp.Identity:PasswordRequiresUpper": "비밀번호에는 대문자('A'~'Z')가 하나 이상 포함되어야 합니다.", + "Volo.Abp.Identity:PasswordTooShort": "비밀번호는 {0}자 이상이어야 합니다.", + "Volo.Abp.Identity:PasswordRequiresUniqueChars": "비밀번호에는 서로 다른 문자가 {0}개 이상 사용되어야 합니다.", + "Volo.Abp.Identity:PasswordInHistory": "최근 {0}개의 비밀번호와 동일한 비밀번호는 사용할 수 없습니다.", + "Volo.Abp.Identity:RoleNotFound": "역할 {0}이(가) 존재하지 않습니다.", + "Volo.Abp.Identity:UserAlreadyHasPassword": "사용자에게 이미 비밀번호가 설정되어 있습니다.", + "Volo.Abp.Identity:UserAlreadyInRole": "사용자가 이미 역할 '{0}'에 속해 있습니다.", + "Volo.Abp.Identity:UserLockedOut": "사용자가 잠겼습니다.", + "Volo.Abp.Identity:UserLockoutNotEnabled": "이 사용자는 잠금 기능이 활성화되어 있지 않습니다.", + "Volo.Abp.Identity:UserNameNotFound": "사용자 {0}이(가) 존재하지 않습니다.", + "Volo.Abp.Identity:UserNotInRole": "사용자가 역할 '{0}'에 속해 있지 않습니다.", + "Volo.Abp.Identity:PasswordConfirmationFailed": "비밀번호와 비밀번호 확인 값이 일치하지 않습니다.", + "Volo.Abp.Identity:NullSecurityStamp": "사용자 보안 스탬프는 null일 수 없습니다.", + "Volo.Abp.Identity:RecoveryCodeRedemptionFailed": "복구 코드를 사용하는 데 실패했습니다.", + "Volo.Abp.Identity:010001": "자신의 계정은 삭제할 수 없습니다!", + "Volo.Abp.Identity:010002": "사용자에게 {MaxUserMembershipCount}개를 초과하는 조직 단위를 설정할 수 없습니다!", + "Volo.Abp.Identity:010003": "외부 로그인을 사용하는 사용자의 비밀번호는 변경할 수 없습니다!", + "Volo.Abp.Identity:010004": "이름이 {0}인 조직 단위가 이미 존재합니다. 같은 수준에 동일한 이름의 조직 단위를 두 개 만들 수 없습니다.", + "Volo.Abp.Identity:010005": "정적 역할의 이름은 변경할 수 없습니다.", + "Volo.Abp.Identity:010006": "정적 역할은 삭제할 수 없습니다.", + "Volo.Abp.Identity:010007": "자신의 2단계 인증 설정은 변경할 수 없습니다.", + "Volo.Abp.Identity:010008": "2단계 인증 설정 변경은 허용되지 않습니다.", + "Volo.Abp.Identity:010009": "자신에게 위임할 수 없습니다.", + "Volo.Abp.Identity:010010": "상위 조직 단위('{ParentId}')가 존재하지 않거나 다른 테넌트에 속해 있습니다.", + "Volo.Abp.Identity:010021": "이름이 이미 존재합니다: '{0}'.", + "Volo.Abp.Identity:010022": "정적 클레임 유형은 업데이트할 수 없습니다.", + "Volo.Abp.Identity:010023": "정적 클레임 유형은 삭제할 수 없습니다.", + "Identity.OrganizationUnit.MaxUserMembershipCount": "사용자에게 허용되는 최대 조직 단위 멤버십 수", + "ThisUserIsNotActiveMessage": "이 사용자는 활성 상태가 아닙니다.", + "Permission:IdentityManagement": "ID 관리", + "Permission:RoleManagement": "역할 관리", + "Permission:Create": "생성", + "Permission:Edit": "편집", + "Permission:Delete": "삭제", + "Permission:ChangePermissions": "권한 변경", + "Permission:ManageRoles": "역할 관리", + "Permission:UserManagement": "사용자 관리", + "Permission:UserLookup": "사용자 조회", + "DisplayName:Abp.Identity.Password.RequiredLength": "필수 길이", + "DisplayName:Abp.Identity.Password.RequiredUniqueChars": "필수 고유 문자 수", + "DisplayName:Abp.Identity.Password.RequireNonAlphanumeric": "필수 영숫자 이외 문자", + "DisplayName:Abp.Identity.Password.RequireLowercase": "필수 소문자", + "DisplayName:Abp.Identity.Password.RequireUppercase": "필수 대문자", + "DisplayName:Abp.Identity.Password.RequireDigit": "필수 숫자", + "DisplayName:Abp.Identity.Password.ForceUsersToPeriodicallyChangePassword": "사용자의 정기적인 비밀번호 변경 강제", + "DisplayName:Abp.Identity.Password.PasswordChangePeriodDays": "비밀번호 변경 주기(일)", + "DisplayName:Abp.Identity.Password.EnablePreventPasswordReuse": "비밀번호 재사용 방지 활성화", + "DisplayName:Abp.Identity.Password.PreventPasswordReuseCount": "재사용할 수 없는 이전 비밀번호 수", + "DisplayName:Abp.Identity.Lockout.AllowedForNewUsers": "새 사용자에게 활성화", + "DisplayName:Abp.Identity.Lockout.LockoutDuration": "잠금 기간(초)", + "DisplayName:Abp.Identity.Lockout.MaxFailedAccessAttempts": "최대 접근 실패 횟수", + "DisplayName:Abp.Identity.SignIn.RequireConfirmedEmail": "로그인 시 이메일 인증 강제", + "DisplayName:Abp.Identity.SignIn.EnablePhoneNumberConfirmation": "사용자의 전화번호 인증 허용", + "DisplayName:Abp.Identity.SignIn.RequireConfirmedPhoneNumber": "로그인 시 전화번호 인증 강제", + "DisplayName:Abp.Identity.User.IsUserNameUpdateEnabled": "사용자의 사용자 이름 변경 허용", + "DisplayName:Abp.Identity.User.IsEmailUpdateEnabled": "사용자의 이메일 주소 변경 허용", + "Description:Abp.Identity.Password.RequiredLength": "비밀번호에 필요한 최소 길이입니다.", + "Description:Abp.Identity.Password.RequiredUniqueChars": "비밀번호에 포함되어야 하는 서로 다른 문자의 최소 개수입니다.", + "Description:Abp.Identity.Password.RequireNonAlphanumeric": "비밀번호에 영숫자가 아닌 문자가 포함되어야 하는지 여부입니다.", + "Description:Abp.Identity.Password.RequireLowercase": "비밀번호에 ASCII 소문자가 포함되어야 하는지 여부입니다.", + "Description:Abp.Identity.Password.RequireUppercase": "비밀번호에 ASCII 대문자가 포함되어야 하는지 여부입니다.", + "Description:Abp.Identity.Password.RequireDigit": "비밀번호에 숫자가 포함되어야 하는지 여부입니다.", + "Description:Abp.Identity.Password.ForceUsersToPeriodicallyChangePassword": "사용자가 정기적으로 비밀번호를 변경하도록 강제할지 여부입니다.", + "Description:Abp.Identity.Password.PasswordChangePeriodDays": "사용자 비밀번호가 유효한 기간(일)입니다.", + "Description:Abp.Identity.Password.EnablePreventPasswordReuse": "사용자가 이전 비밀번호를 재사용하지 못하도록 할지 여부입니다.", + "Description:Abp.Identity.Password.PreventPasswordReuseCount": "재사용할 수 없는 이전 비밀번호의 개수입니다.", + "Description:Abp.Identity.Lockout.AllowedForNewUsers": "새 사용자를 잠글 수 있는지 여부입니다.", + "Description:Abp.Identity.Lockout.LockoutDuration": "잠금이 발생했을 때 사용자가 잠기는 기간입니다.", + "Description:Abp.Identity.Lockout.MaxFailedAccessAttempts": "잠금이 활성화된 경우 사용자가 잠기기 전까지 허용되는 접근 실패 횟수입니다.", + "Description:Abp.Identity.SignIn.RequireConfirmedEmail": "사용자는 계정을 만들 수 있지만 이메일 주소를 인증하기 전에는 로그인할 수 없습니다.", + "Description:Abp.Identity.SignIn.EnablePhoneNumberConfirmation": "사용자가 전화번호를 인증할 수 있습니다. SMS 연동이 필요합니다.", + "Description:Abp.Identity.SignIn.RequireConfirmedPhoneNumber": "사용자는 계정을 만들 수 있지만 전화번호를 인증하기 전에는 로그인할 수 없습니다.", + "Description:Abp.Identity.User.IsUserNameUpdateEnabled": "사용자가 사용자 이름을 변경할 수 있는지 여부입니다.", + "Description:Abp.Identity.User.IsEmailUpdateEnabled": "사용자가 이메일 주소를 변경할 수 있는지 여부입니다.", + "DisplayName:Abp.Identity.SignIn.RequireEmailVerificationToRegister": "등록 시 이메일 인증 강제", + "Description:Abp.Identity.SignIn.RequireEmailVerificationToRegister": "이메일 주소를 인증하지 않으면 사용자 계정이 생성되지 않습니다.", + "Details": "세부 정보", + "CreatedBy": "생성자", + "ModifiedBy": "수정자", + "ModificationTime": "수정 시간", + "PasswordUpdateTime": "비밀번호 변경 시간", + "LockoutEndTime": "잠금 종료 시간", + "FailedAccessCount": "접근 실패 횟수", + "UserResourcePermissionProviderKeyLookupService": "사용자", + "RoleResourcePermissionProviderKeyLookupService": "역할" + } +} diff --git a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/CreateModal.cshtml b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/CreateModal.cshtml index d1c845e550..f3216de2fe 100644 --- a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/CreateModal.cshtml +++ b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/CreateModal.cshtml @@ -1,4 +1,5 @@ @page +@using Localization.Resources.AbpUi @using Microsoft.AspNetCore.Mvc.Localization @using Microsoft.Extensions.Localization @using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Modal @@ -10,6 +11,7 @@ @using Volo.Abp.Identity @model CreateModalModel @inject IHtmlLocalizer L +@inject IHtmlLocalizer UiL @inject IStringLocalizerFactory StringLocalizerFactory @{ @@ -30,7 +32,7 @@
- +
diff --git a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/EditModal.cshtml b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/EditModal.cshtml index b60978f32e..bef5e53a1e 100644 --- a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/EditModal.cshtml +++ b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/EditModal.cshtml @@ -1,4 +1,5 @@ @page +@using Localization.Resources.AbpUi @using Microsoft.AspNetCore.Mvc.Localization @using Microsoft.Extensions.Localization @using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Modal @@ -10,6 +11,7 @@ @using Volo.Abp.Identity @model EditModalModel @inject IHtmlLocalizer L +@inject IHtmlLocalizer UiL @inject IStringLocalizerFactory StringLocalizerFactory @{ Layout = null; @@ -30,7 +32,7 @@
-
diff --git a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/index.js b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/index.js index fa63b96af4..9445cd33c8 100644 --- a/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/index.js +++ b/modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/index.js @@ -11,12 +11,9 @@ return; } - if(passwordInput.attr("type") === "password") { - passwordInput.attr("type", "text"); - } - else { - passwordInput.attr("type", "password"); - } + var isRevealing = passwordInput.attr("type") === "password"; + passwordInput.attr("type", isRevealing ? "text" : "password"); + button.attr("aria-pressed", isRevealing); var icon = button.find("i"); if(icon) { diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Localization/Resources/ko.json b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Localization/Resources/ko.json new file mode 100644 index 0000000000..949706d2b0 --- /dev/null +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Localization/Resources/ko.json @@ -0,0 +1,17 @@ +{ + "culture": "ko", + "texts": { + "Volo.IdentityServer:DuplicateIdentityResourceName": "ID 리소스 이름이 이미 존재합니다: {Name}", + "Volo.IdentityServer:DuplicateApiResourceName": "API 리소스 이름이 이미 존재합니다: {Name}", + "Volo.IdentityServer:DuplicateApiScopeName": "API 범위 이름이 이미 존재합니다: {Name}", + "Volo.IdentityServer:DuplicateClientId": "클라이언트 ID가 이미 존재합니다: {ClientId}", + "UserLockedOut": "잘못된 로그인 시도로 인해 사용자 계정이 잠겼습니다. 잠시 후 다시 시도해 주세요.", + "InvalidUserNameOrPassword": "사용자 이름 또는 비밀번호가 올바르지 않습니다!", + "LoginIsNotAllowed": "로그인할 수 없습니다! 계정이 비활성 상태이거나 이메일 또는 전화번호 확인이 필요합니다.", + "InvalidUsername": "사용자 이름 또는 비밀번호가 올바르지 않습니다!", + "InvalidAuthenticatorCode": "인증 코드가 올바르지 않습니다!", + "InvalidRecoveryCode": "복구 코드가 올바르지 않습니다!", + "TheTargetUserIsNotLinkedToYou": "대상 사용자가 현재 사용자와 연결되어 있지 않습니다!", + "ClientResourcePermissionProviderKeyLookupService": "클라이언트" + } +} diff --git a/modules/openiddict/src/Volo.Abp.OpenIddict.Domain.Shared/Volo/Abp/OpenIddict/Localization/OpenIddict/ko.json b/modules/openiddict/src/Volo.Abp.OpenIddict.Domain.Shared/Volo/Abp/OpenIddict/Localization/OpenIddict/ko.json new file mode 100644 index 0000000000..5142cfcf44 --- /dev/null +++ b/modules/openiddict/src/Volo.Abp.OpenIddict.Domain.Shared/Volo/Abp/OpenIddict/Localization/OpenIddict/ko.json @@ -0,0 +1,16 @@ +{ + "culture": "ko", + "texts": { + "TheOpenIDConnectRequestCannotBeRetrieved": "OpenID Connect 요청을 가져올 수 없습니다.", + "TheUserDetailsCannotBbeRetrieved": "사용자 세부 정보를 가져올 수 없습니다.", + "TheApplicationDetailsCannotBeFound": "애플리케이션 세부 정보를 찾을 수 없습니다.", + "DetailsConcerningTheCallingClientApplicationCannotBeFound": "호출한 클라이언트 애플리케이션의 세부 정보를 찾을 수 없습니다.", + "TheSpecifiedGrantTypeIsNotImplemented": "지정된 권한 부여 유형 {0}은(는) 구현되어 있지 않습니다.", + "Authorization": "권한 부여", + "DoYouWantToGrantAccessToYourData": "{0}에게 데이터 접근 권한을 부여하시겠습니까?", + "ScopesRequested": "요청된 범위", + "Accept": "허용", + "Deny": "거부", + "ApplicationResourcePermissionProviderKeyLookupService": "클라이언트" + } +} diff --git a/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain.Shared/Volo/Abp/PermissionManagement/Localization/Domain/ko.json b/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain.Shared/Volo/Abp/PermissionManagement/Localization/Domain/ko.json new file mode 100644 index 0000000000..eea6682bd4 --- /dev/null +++ b/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain.Shared/Volo/Abp/PermissionManagement/Localization/Domain/ko.json @@ -0,0 +1,29 @@ +{ + "culture": "ko", + "texts": { + "Permissions": "권한", + "OnlyProviderPermissons": "이 프로바이더만", + "All": "모두", + "SelectAllInAllTabs": "모든 권한 부여", + "SelectAllInThisTab": "모두 선택", + "SaveWithoutAnyPermissionsWarningMessage": "권한을 하나도 부여하지 않고 저장하시겠습니까?", + "PermissionGroup": "권한 그룹", + "Filter": "필터", + "ResourcePermissions": "권한", + "ResourcePermissionTarget": "대상", + "ResourcePermissionPermissions": "권한", + "AddResourcePermission": "권한 추가", + "ResourcePermissionDeletionConfirmationMessage": "모든 권한을 삭제하시겠습니까?", + "UpdateResourcePermission": "권한 업데이트", + "GrantAllResourcePermissions": "모두 부여", + "NoResourceProviderKeyLookupServiceFound": "프로바이더 키 조회 서비스를 찾을 수 없습니다.", + "NoResourcePermissionFound": "정의된 권한이 없습니다.", + "UpdatePermission": "권한 업데이트", + "NoPermissionsAssigned": "할당된 권한이 없습니다.", + "SelectProvider": "프로바이더 선택", + "SearchProviderKey": "프로바이더 키 검색", + "Provider": "프로바이더", + "ErrorLoadingPermissions": "권한을 불러오는 중 오류가 발생했습니다.", + "PleaseSelectProviderAndPermissions": "프로바이더와 권한을 선택해 주세요." + } +} \ No newline at end of file diff --git a/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo.Abp.PermissionManagement.Domain.csproj b/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo.Abp.PermissionManagement.Domain.csproj index ea6d7ea44a..d66cc859cf 100644 --- a/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo.Abp.PermissionManagement.Domain.csproj +++ b/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo.Abp.PermissionManagement.Domain.csproj @@ -23,8 +23,4 @@ - - - - diff --git a/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/AbpPermissionManagementDomainModule.cs b/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/AbpPermissionManagementDomainModule.cs index 1f7eb88bd8..2f65a89994 100644 --- a/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/AbpPermissionManagementDomainModule.cs +++ b/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/AbpPermissionManagementDomainModule.cs @@ -6,7 +6,6 @@ using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using Polly; using Volo.Abp.Authorization; using Volo.Abp.Authorization.Permissions; using Volo.Abp.Caching; diff --git a/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/PermissionDynamicInitializer.cs b/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/PermissionDynamicInitializer.cs index ef3cf355bb..4b4d4686e8 100644 --- a/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/PermissionDynamicInitializer.cs +++ b/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/PermissionDynamicInitializer.cs @@ -6,7 +6,6 @@ using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; -using Polly; using Volo.Abp.Authorization.Permissions; using Volo.Abp.DependencyInjection; using Volo.Abp.Threading; @@ -95,17 +94,8 @@ public class PermissionDynamicInitializer : ITransientDependency var staticPermissionSaver = ServiceProvider.GetRequiredService(); - await Policy - .Handle() - .WaitAndRetryAsync( - 8, - retryAttempt => TimeSpan.FromSeconds( - Volo.Abp.RandomHelper.GetRandom( - (int)Math.Pow(2, retryAttempt) * 8, - (int)Math.Pow(2, retryAttempt) * 12) - ) - ) - .ExecuteAsync(async _ => + await RetryHelper.ExecuteAsync( + async _ => { try { @@ -115,9 +105,20 @@ public class PermissionDynamicInitializer : ITransientDependency { Logger.LogException(ex); - throw; // Polly will catch it + throw; // RetryHelper will catch it } - }, cancellationToken); + }, + new RetryOptions + { + MaxRetryCount = 8, + DelayFactory = retryAttempt => TimeSpan.FromSeconds( + Volo.Abp.RandomHelper.GetRandom( + (int)Math.Pow(2, retryAttempt) * 8, + (int)Math.Pow(2, retryAttempt) * 12) + ), + ShouldRetryOnException = _ => true + }, + cancellationToken); } protected virtual async Task PreCacheDynamicPermissionsAsync( diff --git a/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/PermissionManagementProvider.cs b/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/PermissionManagementProvider.cs index b96fed734e..bbff5e49fe 100644 --- a/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/PermissionManagementProvider.cs +++ b/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/PermissionManagementProvider.cs @@ -78,12 +78,10 @@ public abstract class PermissionManagementProvider : IPermissionManagementProvid protected virtual async Task RevokeAsync(string name, string providerKey) { - var permissionGrant = await PermissionGrantRepository.FindAsync(name, Name, providerKey); - if (permissionGrant == null) + var permissionGrants = await PermissionGrantRepository.GetListAsync(new[] { name }, Name, providerKey); + foreach (var permissionGrant in permissionGrants) { - return; + await PermissionGrantRepository.DeleteAsync(permissionGrant, true); } - - await PermissionGrantRepository.DeleteAsync(permissionGrant, true); } } diff --git a/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/ResourcePermissionManagementProvider.cs b/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/ResourcePermissionManagementProvider.cs index c579307c86..af9576ea11 100644 --- a/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/ResourcePermissionManagementProvider.cs +++ b/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/ResourcePermissionManagementProvider.cs @@ -81,12 +81,10 @@ public abstract class ResourcePermissionManagementProvider : IResourcePermission protected virtual async Task RevokeAsync(string name, string resourceName,string resourceKey, string providerKey) { - var resourcePermissionGrants = await ResourcePermissionGrantRepository.FindAsync(name, resourceName, resourceKey, Name, providerKey); - if (resourcePermissionGrants == null) + var resourcePermissionGrants = await ResourcePermissionGrantRepository.GetListAsync(new[] { name }, resourceName, resourceKey, Name, providerKey); + foreach (var resourcePermissionGrant in resourcePermissionGrants) { - return; + await ResourcePermissionGrantRepository.DeleteAsync(resourcePermissionGrant, true); } - - await ResourcePermissionGrantRepository.DeleteAsync(resourcePermissionGrants, true); } } diff --git a/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/ResourcePermissionManager.cs b/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/ResourcePermissionManager.cs index 5e8c8a0454..28c3a56386 100644 --- a/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/ResourcePermissionManager.cs +++ b/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/ResourcePermissionManager.cs @@ -375,8 +375,8 @@ public class ResourcePermissionManager : IResourcePermissionManager, ISingletonD throw new AbpException($"The resource permission management provider '{providerName}' is not available in the current context."); } - var permissionGrant = await ResourcePermissionGrantRepository.FindAsync(name, resourceName, resourceKey, providerName, providerKey); - if (permissionGrant != null) + var permissionGrants = await ResourcePermissionGrantRepository.GetListAsync(new[] { name }, resourceName, resourceKey, providerName, providerKey); + foreach (var permissionGrant in permissionGrants) { await ResourcePermissionGrantRepository.DeleteAsync(permissionGrant, true); } diff --git a/modules/permission-management/src/Volo.Abp.PermissionManagement.Web/Pages/AbpPermissionManagement/permission-management-modal.js b/modules/permission-management/src/Volo.Abp.PermissionManagement.Web/Pages/AbpPermissionManagement/permission-management-modal.js index 47cacfd2db..ac3c3b9fdf 100644 --- a/modules/permission-management/src/Volo.Abp.PermissionManagement.Web/Pages/AbpPermissionManagement/permission-management-modal.js +++ b/modules/permission-management/src/Volo.Abp.PermissionManagement.Web/Pages/AbpPermissionManagement/permission-management-modal.js @@ -295,15 +295,6 @@ var abp = abp || {}; }); }); - $(function () { - $('.custom-scroll-content').mCustomScrollbar({ - theme: 'minimal-dark', - }); - $('.custom-scroll-container > .col-4').mCustomScrollbar({ - theme: 'minimal-dark', - }); - }); - initSelectAllInThisTab(); setSelectAllInAllTabs(); diff --git a/modules/permission-management/test/Volo.Abp.PermissionManagement.Domain.Tests/Volo/Abp/PermissionManagement/PermissionManagementProvider_Tests.cs b/modules/permission-management/test/Volo.Abp.PermissionManagement.Domain.Tests/Volo/Abp/PermissionManagement/PermissionManagementProvider_Tests.cs index 8ea3ebf672..68629f4309 100644 --- a/modules/permission-management/test/Volo.Abp.PermissionManagement.Domain.Tests/Volo/Abp/PermissionManagement/PermissionManagementProvider_Tests.cs +++ b/modules/permission-management/test/Volo.Abp.PermissionManagement.Domain.Tests/Volo/Abp/PermissionManagement/PermissionManagementProvider_Tests.cs @@ -75,4 +75,19 @@ public class PermissionManagementProvider_Tests : PermissionTestBase "Test")).ShouldBeNull(); } + [Fact] + public async Task SetAsync_Should_Revoke_Duplicate_Host_Grants() + { + await _permissionGrantRepository.InsertAsync(new PermissionGrant(Guid.NewGuid(), "MyPermission1", "Test", "Test")); + await _permissionGrantRepository.InsertAsync(new PermissionGrant(Guid.NewGuid(), "MyPermission1", "Test", "Test")); + (await _permissionGrantRepository.GetListAsync(new[] { "MyPermission1" }, "Test", "Test")).Count.ShouldBe(2); + + await _permissionManagementProvider.SetAsync("MyPermission1", + "Test", + false); + + (await _permissionGrantRepository.FindAsync("MyPermission1", + "Test", + "Test")).ShouldBeNull(); + } } diff --git a/modules/permission-management/test/Volo.Abp.PermissionManagement.Domain.Tests/Volo/Abp/PermissionManagement/ResourcePermissionManagementProvider_Tests.cs b/modules/permission-management/test/Volo.Abp.PermissionManagement.Domain.Tests/Volo/Abp/PermissionManagement/ResourcePermissionManagementProvider_Tests.cs index 9651c3f313..4f6a4318a9 100644 --- a/modules/permission-management/test/Volo.Abp.PermissionManagement.Domain.Tests/Volo/Abp/PermissionManagement/ResourcePermissionManagementProvider_Tests.cs +++ b/modules/permission-management/test/Volo.Abp.PermissionManagement.Domain.Tests/Volo/Abp/PermissionManagement/ResourcePermissionManagementProvider_Tests.cs @@ -87,4 +87,39 @@ public class ResourcePermissionManagementProvider_Tests : PermissionTestBase "Test", "Test")).ShouldBeNull(); } + + [Fact] + public async Task SetAsync_Should_Revoke_Duplicate_Host_Grants() + { + for (var i = 0; i < 2; i++) + { + await _resourcePermissionGrantRepository.InsertAsync( + new ResourcePermissionGrant( + Guid.NewGuid(), + "MyPermission1", + TestEntityResource.ResourceName, + TestEntityResource.ResourceKey1, + "Test", + "Test" + ) + ); + } + (await _resourcePermissionGrantRepository.GetListAsync(new[] { "MyPermission1" }, + TestEntityResource.ResourceName, + TestEntityResource.ResourceKey1, + "Test", + "Test")).Count.ShouldBe(2); + + await _resourcePermissionManagementProvider.SetAsync("MyPermission1", + TestEntityResource.ResourceName, + TestEntityResource.ResourceKey1, + "Test", + false); + + (await _resourcePermissionGrantRepository.FindAsync("MyPermission1", + TestEntityResource.ResourceName, + TestEntityResource.ResourceKey1, + "Test", + "Test")).ShouldBeNull(); + } } diff --git a/modules/permission-management/test/Volo.Abp.PermissionManagement.Domain.Tests/Volo/Abp/PermissionManagement/ResourcePermissionManager_Tests.cs b/modules/permission-management/test/Volo.Abp.PermissionManagement.Domain.Tests/Volo/Abp/PermissionManagement/ResourcePermissionManager_Tests.cs index dc5cb4f4bd..4a3e69fe99 100644 --- a/modules/permission-management/test/Volo.Abp.PermissionManagement.Domain.Tests/Volo/Abp/PermissionManagement/ResourcePermissionManager_Tests.cs +++ b/modules/permission-management/test/Volo.Abp.PermissionManagement.Domain.Tests/Volo/Abp/PermissionManagement/ResourcePermissionManager_Tests.cs @@ -341,6 +341,41 @@ public class ResourcePermissionManager_Tests : PermissionTestBase "Test")).ShouldBeNull(); } + [Fact] + public async Task DeleteByNameAsync_Should_Delete_Duplicate_Host_Grants() + { + for (var i = 0; i < 2; i++) + { + await _resourcePermissionGrantRepository.InsertAsync(new ResourcePermissionGrant( + Guid.NewGuid(), + "MyResourcePermission1", + TestEntityResource.ResourceName, + TestEntityResource.ResourceKey1, + "Test", + "Test") + ); + } + (await _resourcePermissionGrantRepository.GetListAsync(new[] { "MyResourcePermission1" }, + TestEntityResource.ResourceName, + TestEntityResource.ResourceKey1, + "Test", + "Test")).Count.ShouldBe(2); + + await _resourcePermissionManager.DeleteAsync( + "MyResourcePermission1", + TestEntityResource.ResourceName, + TestEntityResource.ResourceKey1, + "Test", + "Test"); + + (await _resourcePermissionGrantRepository.FindAsync( + "MyResourcePermission1", + TestEntityResource.ResourceName, + TestEntityResource.ResourceKey1, + "Test", + "Test")).ShouldBeNull(); + } + [Fact] public async Task GetProviderKeyLookupServicesAsync_Should_Not_Return_Unavailable_Services() { diff --git a/modules/setting-management/src/Volo.Abp.SettingManagement.Domain.Shared/Volo/Abp/SettingManagement/Localization/Resources/AbpSettingManagement/ko.json b/modules/setting-management/src/Volo.Abp.SettingManagement.Domain.Shared/Volo/Abp/SettingManagement/Localization/Resources/AbpSettingManagement/ko.json new file mode 100644 index 0000000000..b5b2366535 --- /dev/null +++ b/modules/setting-management/src/Volo.Abp.SettingManagement.Domain.Shared/Volo/Abp/SettingManagement/Localization/Resources/AbpSettingManagement/ko.json @@ -0,0 +1,43 @@ +{ + "culture": "ko", + "texts": { + "Settings": "설정", + "SavedSuccessfully": "성공적으로 저장되었습니다.", + "Permission:SettingManagement": "설정 관리", + "Permission:Emailing": "이메일", + "Permission:EmailingTest": "이메일 테스트", + "Permission:TimeZone": "시간대", + "SendTestEmail": "테스트 이메일 보내기", + "SenderEmailAddress": "발신자 이메일 주소", + "TargetEmailAddress": "수신자 이메일 주소", + "Subject": "제목", + "Body": "본문", + "TestEmailSubject": "테스트 이메일 {0}", + "TestEmailBody": "테스트 이메일 본문 메시지입니다.", + "SentSuccessfully": "성공적으로 전송되었습니다.", + "MailSendingFailed": "이메일 전송에 실패했습니다. 이메일 설정을 확인한 후 다시 시도해 주세요.", + "Send": "보내기", + "Menu:Settings": "설정", + "Menu:Emailing": "이메일", + "Menu:TimeZone": "시간대", + "DisplayName:Timezone": "시간대", + "TimezoneHelpText": "이 기능을 사용하면 서버의 기본 시간대를 설정할 수 있으며, 사용자는 각자 자신의 시간대를 선택할 수 있습니다. 사용자의 시간대가 서버 시간대와 다르면 모든 시간이 이에 맞게 조정됩니다. 예를 들어 서버가 Europe/London(00:00)으로 설정되어 있고 사용자가 Europe/Paris(+01:00)에 있는 경우, 해당 사용자의 시간은 1시간 조정됩니다. '기본 시간대'를 선택하면 서버 또는 브라우저의 시간대가 자동으로 사용됩니다.", + "DefaultTimeZone": "기본 시간대", + "SmtpHost": "호스트", + "SmtpPort": "포트", + "SmtpUserName": "사용자 이름", + "SmtpPassword": "비밀번호", + "SmtpDomain": "도메인", + "SmtpEnableSsl": "SSL 사용", + "SmtpUseDefaultCredentials": "기본 자격 증명 사용", + "DefaultFromAddress": "기본 발신자 주소", + "DefaultFromDisplayName": "기본 발신자 표시 이름", + "Feature:SettingManagementGroup": "설정 관리", + "Feature:SettingManagementEnable": "설정 관리 사용", + "Feature:SettingManagementEnableDescription": "애플리케이션에서 설정 관리 시스템을 사용합니다.", + "Feature:AllowChangingEmailSettings": "이메일 설정 변경 허용", + "Feature:AllowChangingEmailSettingsDescription": "이메일 설정 변경을 허용합니다.", + "SmtpPasswordPlaceholder": "비밀번호를 변경하려면 값을 입력하세요.", + "NoSettingsAvailable": "표시할 설정이 없습니다." + } +} diff --git a/modules/setting-management/src/Volo.Abp.SettingManagement.Domain/Volo.Abp.SettingManagement.Domain.csproj b/modules/setting-management/src/Volo.Abp.SettingManagement.Domain/Volo.Abp.SettingManagement.Domain.csproj index 9c781497c2..d3f6b15980 100644 --- a/modules/setting-management/src/Volo.Abp.SettingManagement.Domain/Volo.Abp.SettingManagement.Domain.csproj +++ b/modules/setting-management/src/Volo.Abp.SettingManagement.Domain/Volo.Abp.SettingManagement.Domain.csproj @@ -22,8 +22,4 @@ - - - - diff --git a/modules/setting-management/src/Volo.Abp.SettingManagement.Domain/Volo/Abp/SettingManagement/AbpSettingManagementDomainModule.cs b/modules/setting-management/src/Volo.Abp.SettingManagement.Domain/Volo/Abp/SettingManagement/AbpSettingManagementDomainModule.cs index a5d2ba832e..84e7a24e8a 100644 --- a/modules/setting-management/src/Volo.Abp.SettingManagement.Domain/Volo/Abp/SettingManagement/AbpSettingManagementDomainModule.cs +++ b/modules/setting-management/src/Volo.Abp.SettingManagement.Domain/Volo/Abp/SettingManagement/AbpSettingManagementDomainModule.cs @@ -5,7 +5,6 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using Polly; using Volo.Abp.Caching; using Volo.Abp.Data; using Volo.Abp.DependencyInjection; diff --git a/modules/setting-management/src/Volo.Abp.SettingManagement.Domain/Volo/Abp/SettingManagement/SettingDynamicInitializer.cs b/modules/setting-management/src/Volo.Abp.SettingManagement.Domain/Volo/Abp/SettingManagement/SettingDynamicInitializer.cs index af9858353c..438ba2332d 100644 --- a/modules/setting-management/src/Volo.Abp.SettingManagement.Domain/Volo/Abp/SettingManagement/SettingDynamicInitializer.cs +++ b/modules/setting-management/src/Volo.Abp.SettingManagement.Domain/Volo/Abp/SettingManagement/SettingDynamicInitializer.cs @@ -6,7 +6,6 @@ using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; -using Polly; using Volo.Abp.DependencyInjection; using Volo.Abp.Settings; using Volo.Abp.Threading; @@ -96,17 +95,8 @@ public class SettingDynamicInitializer : ITransientDependency var staticSettingSaver = ServiceProvider.GetRequiredService(); - await Policy - .Handle() - .WaitAndRetryAsync( - 8, - retryAttempt => TimeSpan.FromSeconds( - Volo.Abp.RandomHelper.GetRandom( - (int)Math.Pow(2, retryAttempt) * 8, - (int)Math.Pow(2, retryAttempt) * 12) - ) - ) - .ExecuteAsync(async _ => + await RetryHelper.ExecuteAsync( + async _ => { try { @@ -115,9 +105,20 @@ public class SettingDynamicInitializer : ITransientDependency catch (Exception ex) { Logger.LogException(ex); - throw; // Polly will catch it + throw; // RetryHelper will catch it } - }, cancellationToken); + }, + new RetryOptions + { + MaxRetryCount = 8, + DelayFactory = retryAttempt => TimeSpan.FromSeconds( + Volo.Abp.RandomHelper.GetRandom( + (int)Math.Pow(2, retryAttempt) * 8, + (int)Math.Pow(2, retryAttempt) * 12) + ), + ShouldRetryOnException = _ => true + }, + cancellationToken); } protected virtual async Task PreCacheDynamicSettingsAsync( diff --git a/modules/setting-management/src/Volo.Abp.SettingManagement.Domain/Volo/Abp/SettingManagement/SettingManagementStore.cs b/modules/setting-management/src/Volo.Abp.SettingManagement.Domain/Volo/Abp/SettingManagement/SettingManagementStore.cs index 09f90c8919..20626026af 100644 --- a/modules/setting-management/src/Volo.Abp.SettingManagement.Domain/Volo/Abp/SettingManagement/SettingManagementStore.cs +++ b/modules/setting-management/src/Volo.Abp.SettingManagement.Domain/Volo/Abp/SettingManagement/SettingManagementStore.cs @@ -1,6 +1,8 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; using Volo.Abp.Caching; using Volo.Abp.DependencyInjection; using Volo.Abp.Guids; @@ -11,6 +13,8 @@ namespace Volo.Abp.SettingManagement; public class SettingManagementStore : ISettingManagementStore, ITransientDependency { + public ILogger Logger { get; set; } + protected IDistributedCache Cache { get; } protected ISettingDefinitionManager SettingDefinitionManager { get; } protected ISettingRepository SettingRepository { get; } @@ -26,6 +30,7 @@ public class SettingManagementStore : ISettingManagementStore, ITransientDepende GuidGenerator = guidGenerator; Cache = cache; SettingDefinitionManager = settingDefinitionManager; + Logger = NullLogger.Instance; } [UnitOfWork] @@ -37,7 +42,7 @@ public class SettingManagementStore : ISettingManagementStore, ITransientDepende [UnitOfWork] public virtual async Task SetAsync(string name, string value, string providerName, string providerKey) { - var setting = await SettingRepository.FindAsync(name, providerName, providerKey); + var setting = await FindAndDeleteDuplicatesAsync(name, providerName, providerKey); if (setting == null) { setting = new Setting(GuidGenerator.Create(), name, value, providerName, providerKey); @@ -55,16 +60,22 @@ public class SettingManagementStore : ISettingManagementStore, ITransientDepende public virtual async Task> GetListAsync(string providerName, string providerKey) { var settings = await SettingRepository.GetListAsync(providerName, providerKey); - return settings.Select(s => new SettingValue(s.Name, s.Value)).ToList(); + return (await CreateSettingValueDictionaryAsync(settings, providerName, providerKey)) + .Select(s => new SettingValue(s.Key, s.Value)) + .ToList(); } [UnitOfWork] public virtual async Task DeleteAsync(string name, string providerName, string providerKey) { - var setting = await SettingRepository.FindAsync(name, providerName, providerKey); - if (setting != null) + var settings = await SettingRepository.GetListAsync(new[] { name }, providerName, providerKey); + if (settings.Any()) { - await SettingRepository.DeleteAsync(setting, true); + foreach (var setting in settings) + { + await SettingRepository.DeleteAsync(setting, true); + } + await Cache.RemoveAsync(CalculateCacheKey(name, providerName, providerKey), considerUow: true); } } @@ -93,8 +104,10 @@ public class SettingManagementStore : ISettingManagementStore, ITransientDepende SettingCacheItem currentCacheItem) { var settingDefinitions = await SettingDefinitionManager.GetAllAsync(); - var settingsDictionary = (await SettingRepository.GetListAsync(providerName, providerKey)) - .ToDictionary(s => s.Name, s => s.Value); + var settingsDictionary = await CreateSettingValueDictionaryAsync( + await SettingRepository.GetListAsync(providerName, providerKey), + providerName, + providerKey); var cacheItems = new List>(); @@ -179,8 +192,10 @@ public class SettingManagementStore : ISettingManagementStore, ITransientDepende var settingNames = new HashSet(notCacheKeys.Select(GetSettingNameFormCacheKeyOrNull)); var settingDefinitions = (await SettingDefinitionManager.GetAllAsync()).Where(x => settingNames.Contains(x.Name)); - var settingsDictionary = (await SettingRepository.GetListAsync(settingNames.ToArray(), providerName, providerKey)) - .ToDictionary(s => s.Name, s => s.Value); + var settingsDictionary = await CreateSettingValueDictionaryAsync( + await SettingRepository.GetListAsync(settingNames.ToArray(), providerName, providerKey), + providerName, + providerKey); var cacheItems = new List>(); @@ -201,6 +216,51 @@ public class SettingManagementStore : ISettingManagementStore, ITransientDepende } + protected virtual async Task FindAndDeleteDuplicatesAsync(string name, string providerName, string providerKey) + { + var setting = await SettingRepository.FindAsync(name, providerName, providerKey); + if (setting == null) + { + return null; + } + + var duplicates = (await SettingRepository.GetListAsync(new[] { name }, providerName, providerKey)) + .Where(x => x.Id != setting.Id); + foreach (var duplicate in duplicates) + { + await SettingRepository.DeleteAsync(duplicate, true); + } + + return setting; + } + + protected virtual async Task> CreateSettingValueDictionaryAsync( + List settings, + string providerName, + string providerKey) + { + var settingsDictionary = new Dictionary(); + + foreach (var settingGroup in settings.GroupBy(s => s.Name)) + { + if (settingGroup.Count() == 1) + { + settingsDictionary[settingGroup.Key] = settingGroup.First().Value; + continue; + } + + // FindAsync returns the same record that SetAsync updates, so reads and writes agree until the duplicates are deleted. + Logger.LogWarning( + "Found {Count} setting records for Name = {Name}, ProviderName = {ProviderName}, ProviderKey = {ProviderKey}. The duplicates will be deleted the next time the setting is saved.", + settingGroup.Count(), settingGroup.Key, providerName, providerKey); + + var setting = await SettingRepository.FindAsync(settingGroup.Key, providerName, providerKey); + settingsDictionary[settingGroup.Key] = (setting ?? settingGroup.First()).Value; + } + + return settingsDictionary; + } + protected virtual string CalculateCacheKey(string name, string providerName, string providerKey) { return SettingCacheItem.CalculateCacheKey(name, providerName, providerKey); diff --git a/modules/setting-management/test/Volo.Abp.SettingManagement.EntityFrameworkCore.Tests/Volo/Abp/SettingManagement/EntityFrameworkCore/DuplicateSettingRecords_Tests.cs b/modules/setting-management/test/Volo.Abp.SettingManagement.EntityFrameworkCore.Tests/Volo/Abp/SettingManagement/EntityFrameworkCore/DuplicateSettingRecords_Tests.cs new file mode 100644 index 0000000000..b0174beaca --- /dev/null +++ b/modules/setting-management/test/Volo.Abp.SettingManagement.EntityFrameworkCore.Tests/Volo/Abp/SettingManagement/EntityFrameworkCore/DuplicateSettingRecords_Tests.cs @@ -0,0 +1,6 @@ +namespace Volo.Abp.SettingManagement.EntityFrameworkCore; + +public class DuplicateSettingRecords_Tests : DuplicateSettingRecords_Tests +{ + +} diff --git a/modules/setting-management/test/Volo.Abp.SettingManagement.MongoDB.Tests/Volo/Abp/SettingManagement/MongoDB/DuplicateSettingRecords_Tests.cs b/modules/setting-management/test/Volo.Abp.SettingManagement.MongoDB.Tests/Volo/Abp/SettingManagement/MongoDB/DuplicateSettingRecords_Tests.cs new file mode 100644 index 0000000000..35ddd7afb0 --- /dev/null +++ b/modules/setting-management/test/Volo.Abp.SettingManagement.MongoDB.Tests/Volo/Abp/SettingManagement/MongoDB/DuplicateSettingRecords_Tests.cs @@ -0,0 +1,9 @@ +using Xunit; + +namespace Volo.Abp.SettingManagement.MongoDB; + +[Collection(MongoTestCollection.Name)] +public class DuplicateSettingRecords_Tests : DuplicateSettingRecords_Tests +{ + +} diff --git a/modules/setting-management/test/Volo.Abp.SettingManagement.TestBase/Volo/Abp/SettingManagement/DuplicateSettingRecords_Tests.cs b/modules/setting-management/test/Volo.Abp.SettingManagement.TestBase/Volo/Abp/SettingManagement/DuplicateSettingRecords_Tests.cs new file mode 100644 index 0000000000..b9b1f299de --- /dev/null +++ b/modules/setting-management/test/Volo.Abp.SettingManagement.TestBase/Volo/Abp/SettingManagement/DuplicateSettingRecords_Tests.cs @@ -0,0 +1,89 @@ +using System; +using System.Linq; +using System.Threading.Tasks; +using Shouldly; +using Volo.Abp.Modularity; +using Volo.Abp.Settings; +using Xunit; + +namespace Volo.Abp.SettingManagement; + +public abstract class DuplicateSettingRecords_Tests : SettingManagementTestBase + where TStartupModule : IAbpModule +{ + protected ISettingManagementStore SettingManagementStore { get; } + protected ISettingRepository SettingRepository { get; } + + protected DuplicateSettingRecords_Tests() + { + SettingManagementStore = GetRequiredService(); + SettingRepository = GetRequiredService(); + } + + [Fact] + public async Task GetOrNullAsync_Should_Not_Fail_When_Duplicate_Global_Settings_Exist() + { + await InsertDuplicateGlobalSettingAsync("MySetting1", "43"); + + var value = await SettingManagementStore.GetOrNullAsync("MySetting2", GlobalSettingValueProvider.ProviderName, null); + value.ShouldBe("default-store-value"); + + var duplicatedValue = await SettingManagementStore.GetOrNullAsync("MySetting1", GlobalSettingValueProvider.ProviderName, null); + duplicatedValue.ShouldBe((await SettingRepository.FindAsync("MySetting1", GlobalSettingValueProvider.ProviderName, null)).Value); + } + + [Fact] + public async Task GetListAsync_Should_Not_Fail_When_Duplicate_Global_Settings_Exist() + { + await InsertDuplicateGlobalSettingAsync("MySetting1", "43"); + + var result = await SettingManagementStore.GetListAsync( + new[] { "MySetting1", "MySetting2" }, + GlobalSettingValueProvider.ProviderName, + null); + + result.First(x => x.Name == "MySetting1").Value.ShouldBe((await SettingRepository.FindAsync("MySetting1", GlobalSettingValueProvider.ProviderName, null)).Value); + result.First(x => x.Name == "MySetting2").Value.ShouldBe("default-store-value"); + } + + [Fact] + public async Task GetListAsync_By_Provider_Should_Return_One_Value_Per_Setting_When_Duplicate_Global_Settings_Exist() + { + await InsertDuplicateGlobalSettingAsync("MySetting1", "43"); + + var result = await SettingManagementStore.GetListAsync(GlobalSettingValueProvider.ProviderName, null); + + result.Count(x => x.Name == "MySetting1").ShouldBe(1); + result.Single(x => x.Name == "MySetting1").Value.ShouldBe((await SettingRepository.FindAsync("MySetting1", GlobalSettingValueProvider.ProviderName, null)).Value); + } + + [Fact] + public async Task SetAsync_Should_Remove_Duplicate_Global_Settings() + { + await InsertDuplicateGlobalSettingAsync("MySetting1", "43"); + + await SettingManagementStore.SetAsync("MySetting1", "44", GlobalSettingValueProvider.ProviderName, null); + + var settings = await SettingRepository.GetListAsync(new[] { "MySetting1" }, GlobalSettingValueProvider.ProviderName, null); + settings.Count.ShouldBe(1); + settings[0].Value.ShouldBe("44"); + (await SettingManagementStore.GetOrNullAsync("MySetting1", GlobalSettingValueProvider.ProviderName, null)).ShouldBe("44"); + } + + [Fact] + public async Task DeleteAsync_Should_Remove_Duplicate_Global_Settings() + { + await InsertDuplicateGlobalSettingAsync("MySetting1", "43"); + + await SettingManagementStore.DeleteAsync("MySetting1", GlobalSettingValueProvider.ProviderName, null); + + (await SettingRepository.GetListAsync(new[] { "MySetting1" }, GlobalSettingValueProvider.ProviderName, null)).ShouldBeEmpty(); + (await SettingManagementStore.GetOrNullAsync("MySetting1", GlobalSettingValueProvider.ProviderName, null)).ShouldBeNull(); + } + + private async Task InsertDuplicateGlobalSettingAsync(string name, string value) + { + await SettingRepository.InsertAsync(new Setting(Guid.NewGuid(), name, value, GlobalSettingValueProvider.ProviderName)); + (await SettingRepository.GetListAsync(new[] { name }, GlobalSettingValueProvider.ProviderName, null)).Count.ShouldBe(2); + } +} diff --git a/modules/tenant-management/src/Volo.Abp.TenantManagement.Blazor.MudBlazor/Pages/TenantManagement/TenantManagement.razor b/modules/tenant-management/src/Volo.Abp.TenantManagement.Blazor.MudBlazor/Pages/TenantManagement/TenantManagement.razor index e2211914f4..26e7969ade 100644 --- a/modules/tenant-management/src/Volo.Abp.TenantManagement.Blazor.MudBlazor/Pages/TenantManagement/TenantManagement.razor +++ b/modules/tenant-management/src/Volo.Abp.TenantManagement.Blazor.MudBlazor/Pages/TenantManagement/TenantManagement.razor @@ -48,14 +48,18 @@ Required="true" RequiredError="@L["ThisFieldIsRequired."]" InputType="InputType.Email" /> - +
+ + +
diff --git a/modules/tenant-management/src/Volo.Abp.TenantManagement.Blazor/Pages/TenantManagement/TenantManagement.razor b/modules/tenant-management/src/Volo.Abp.TenantManagement.Blazor/Pages/TenantManagement/TenantManagement.razor index 49e4c64822..57b9b7844f 100644 --- a/modules/tenant-management/src/Volo.Abp.TenantManagement.Blazor/Pages/TenantManagement/TenantManagement.razor +++ b/modules/tenant-management/src/Volo.Abp.TenantManagement.Blazor/Pages/TenantManagement/TenantManagement.razor @@ -77,8 +77,9 @@ - diff --git a/modules/tenant-management/src/Volo.Abp.TenantManagement.Domain.Shared/Volo/Abp/TenantManagement/Localization/Resources/ko.json b/modules/tenant-management/src/Volo.Abp.TenantManagement.Domain.Shared/Volo/Abp/TenantManagement/Localization/Resources/ko.json new file mode 100644 index 0000000000..13bfe0999b --- /dev/null +++ b/modules/tenant-management/src/Volo.Abp.TenantManagement.Domain.Shared/Volo/Abp/TenantManagement/Localization/Resources/ko.json @@ -0,0 +1,23 @@ +{ + "culture": "ko", + "texts": { + "Volo.Abp.TenantManagement:DuplicateTenantName": "테넌트 이름이 이미 존재합니다: {Name}", + "Menu:TenantManagement": "테넌트 관리", + "Tenants": "테넌트", + "NewTenant": "새 테넌트", + "TenantName": "테넌트 이름", + "DisplayName:TenantName": "테넌트 이름", + "TenantDeletionConfirmationMessage": "테넌트 '{0}'이(가) 삭제됩니다. 계속하시겠습니까?", + "ConnectionStrings": "연결 문자열", + "DisplayName:DefaultConnectionString": "기본 연결 문자열", + "DisplayName:UseSharedDatabase": "공유 데이터베이스 사용", + "Permission:TenantManagement": "테넌트 관리", + "Permission:Create": "생성", + "Permission:Edit": "편집", + "Permission:Delete": "삭제", + "Permission:ManageConnectionStrings": "연결 문자열 관리", + "Permission:ManageFeatures": "기능", + "DisplayName:AdminEmailAddress": "관리자 이메일 주소", + "DisplayName:AdminPassword": "관리자 비밀번호" + } +} diff --git a/modules/tenant-management/src/Volo.Abp.TenantManagement.Web/Pages/TenantManagement/Tenants/Create.js b/modules/tenant-management/src/Volo.Abp.TenantManagement.Web/Pages/TenantManagement/Tenants/Create.js index b19f44be46..8a8c8bc859 100644 --- a/modules/tenant-management/src/Volo.Abp.TenantManagement.Web/Pages/TenantManagement/Tenants/Create.js +++ b/modules/tenant-management/src/Volo.Abp.TenantManagement.Web/Pages/TenantManagement/Tenants/Create.js @@ -6,12 +6,9 @@ $(document).ready(function () { return; } - if (passwordInput.attr("type") === "password") { - passwordInput.attr("type", "text"); - } - else { - passwordInput.attr("type", "password"); - } + let isRevealing = passwordInput.attr("type") === "password"; + passwordInput.attr("type", isRevealing ? "text" : "password"); + button.attr("aria-pressed", isRevealing); let icon = button.find("i"); if (icon) { diff --git a/modules/tenant-management/src/Volo.Abp.TenantManagement.Web/Pages/TenantManagement/Tenants/CreateModal.cshtml b/modules/tenant-management/src/Volo.Abp.TenantManagement.Web/Pages/TenantManagement/Tenants/CreateModal.cshtml index bcbda372e2..bb4ec71f3c 100644 --- a/modules/tenant-management/src/Volo.Abp.TenantManagement.Web/Pages/TenantManagement/Tenants/CreateModal.cshtml +++ b/modules/tenant-management/src/Volo.Abp.TenantManagement.Web/Pages/TenantManagement/Tenants/CreateModal.cshtml @@ -1,4 +1,5 @@ @page +@using Localization.Resources.AbpUi @using Microsoft.AspNetCore.Mvc.Localization @using Microsoft.Extensions.Localization @using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Modal @@ -10,6 +11,7 @@ @using Volo.Abp.TenantManagement; @model CreateModalModel @inject IHtmlLocalizer L +@inject IHtmlLocalizer UiL @inject IStringLocalizerFactory StringLocalizerFactory @{ Layout = null; @@ -27,7 +29,7 @@ *
-
diff --git a/modules/virtual-file-explorer/src/Volo.Abp.VirtualFileExplorer.Contracts/Volo/Abp/VirtualFileExplorer/Localization/Resources/ko.json b/modules/virtual-file-explorer/src/Volo.Abp.VirtualFileExplorer.Contracts/Volo/Abp/VirtualFileExplorer/Localization/Resources/ko.json new file mode 100644 index 0000000000..8b53474d20 --- /dev/null +++ b/modules/virtual-file-explorer/src/Volo.Abp.VirtualFileExplorer.Contracts/Volo/Abp/VirtualFileExplorer/Localization/Resources/ko.json @@ -0,0 +1,16 @@ +{ + "culture": "ko", + "texts": { + "VirtualFileExplorer": "가상 파일 탐색기", + "VirtualFileType": "가상 파일 형식", + "Menu:VirtualFileExplorer": "가상 파일 탐색기", + "LastUpdateTime": "마지막 업데이트 시간", + "VirtualFileName": "가상 파일 이름", + "FileContent": "파일 내용", + "Size": "크기", + "BackToRoot": "루트로 돌아가기", + "EmptyFileInfoList": "가상 파일이 없습니다.", + "Permission:AbpVirtualFileExplorer": "가상 파일 탐색기", + "Permission:AbpVirtualFileExplorer:View": "보기" + } +} diff --git a/npm/ng-packs/package.json b/npm/ng-packs/package.json index 76f35c9965..54ad3084b7 100644 --- a/npm/ng-packs/package.json +++ b/npm/ng-packs/package.json @@ -51,29 +51,29 @@ "@abp/ng.theme.lepton-x": "~5.7.0", "@abp/ng.schematics": "~10.7.0", "@abp/utils": "~10.7.0", - "@angular-devkit/build-angular": "~22.0.0", - "@angular-devkit/core": "~22.0.0", - "@angular-devkit/schematics": "~22.0.0", - "@angular-devkit/schematics-cli": "~22.0.0", - "@angular-eslint/eslint-plugin": "~22.0.0", - "@angular-eslint/eslint-plugin-template": "~22.0.0", - "@angular-eslint/template-parser": "~22.0.0", - "@angular/animations": "~22.0.0", - "@angular/aria": "~22.0.0", - "@angular/build": "~22.0.0", - "@angular/cli": "~22.0.0", - "@angular/common": "~22.0.0", - "@angular/compiler": "~22.0.0", - "@angular/compiler-cli": "~22.0.0", - "@angular/core": "~22.0.0", - "@angular/forms": "~22.0.0", - "@angular/language-service": "~22.0.0", - "@angular/localize": "~22.0.0", - "@angular/platform-browser": "~22.0.0", - "@angular/platform-browser-dynamic": "~22.0.0", - "@angular/platform-server": "~22.0.0", - "@angular/router": "~22.0.0", - "@angular/ssr": "~22.0.0", + "@angular-devkit/build-angular": "~22.1.0", + "@angular-devkit/core": "~22.1.0", + "@angular-devkit/schematics": "~22.1.0", + "@angular-devkit/schematics-cli": "~22.1.0", + "@angular-eslint/eslint-plugin": "~22.1.0", + "@angular-eslint/eslint-plugin-template": "~22.1.0", + "@angular-eslint/template-parser": "~22.1.0", + "@angular/animations": "~22.1.0", + "@angular/aria": "~22.1.0", + "@angular/build": "~22.1.0", + "@angular/cli": "~22.1.0", + "@angular/common": "~22.1.0", + "@angular/compiler": "~22.1.0", + "@angular/compiler-cli": "~22.1.0", + "@angular/core": "~22.1.0", + "@angular/forms": "~22.1.0", + "@angular/language-service": "~22.1.0", + "@angular/localize": "~22.1.0", + "@angular/platform-browser": "~22.1.0", + "@angular/platform-browser-dynamic": "~22.1.0", + "@angular/platform-server": "~22.1.0", + "@angular/router": "~22.1.0", + "@angular/ssr": "~22.1.0", "@fortawesome/fontawesome-free": "^6.0.0", "@ng-bootstrap/ng-bootstrap": "~20.0.0", "@ngneat/spectator": "~19.6.2", @@ -91,7 +91,7 @@ "@nx/web": "~22.7.5", "@nx/workspace": "~22.7.5", "@popperjs/core": "~2.11.0", - "@schematics/angular": "~22.0.0", + "@schematics/angular": "~22.1.0", "@swc-node/register": "~1.11.1", "@swc/cli": "~0.7.10", "@swc/core": "~1.15.8", @@ -129,7 +129,7 @@ "just-compare": "^2.0.0", "lerna": "^4.0.0", "lint-staged": "^13.0.0", - "ng-packagr": "~22.0.0", + "ng-packagr": "~22.1.0", "ng-zorro-antd": "~21.1.0", "nx": "~22.7.5", "postcss": "^8.0.0", diff --git a/npm/ng-packs/packages/core/src/lib/directives/permission.directive.ts b/npm/ng-packs/packages/core/src/lib/directives/permission.directive.ts index b12782288d..d9ad09c780 100644 --- a/npm/ng-packs/packages/core/src/lib/directives/permission.directive.ts +++ b/npm/ng-packs/packages/core/src/lib/directives/permission.directive.ts @@ -52,7 +52,9 @@ export class PermissionDirective implements OnDestroy, OnChanges, AfterViewInit if (!this.rendered) { this.cdrSubject.next(); } else { - this.cdRef.detectChanges(); + // Defer via queue — sync detectChanges during ApplicationRef.tick + // (e.g. post-login permission/config refresh) can contribute to NG0101. + this.queue.add(() => this.cdRef.detectChanges()); } } else { this.cdRef.markForCheck(); diff --git a/npm/ng-packs/packages/core/src/lib/proxy/volo/abp/http/modeling/models.ts b/npm/ng-packs/packages/core/src/lib/proxy/volo/abp/http/modeling/models.ts index 670666a1c9..b91d15ee4e 100644 --- a/npm/ng-packs/packages/core/src/lib/proxy/volo/abp/http/modeling/models.ts +++ b/npm/ng-packs/packages/core/src/lib/proxy/volo/abp/http/modeling/models.ts @@ -82,6 +82,8 @@ export interface PropertyApiDescriptionModel { maxLength?: number; minimum?: string; maximum?: string; + minimumIsExclusive?: boolean; + maximumIsExclusive?: boolean; regex?: string; } diff --git a/npm/ng-packs/packages/feature-management/package.json b/npm/ng-packs/packages/feature-management/package.json index ad591c932a..fbd7c0d936 100644 --- a/npm/ng-packs/packages/feature-management/package.json +++ b/npm/ng-packs/packages/feature-management/package.json @@ -11,7 +11,7 @@ "tslib": "^2.0.0" }, "peerDependencies": { - "@angular/aria": "~21.2.0" + "@angular/aria": "~22.1.0" }, "publishConfig": { "access": "public" diff --git a/npm/ng-packs/packages/permission-management/package.json b/npm/ng-packs/packages/permission-management/package.json index 65c026a7c2..7745f0bee3 100644 --- a/npm/ng-packs/packages/permission-management/package.json +++ b/npm/ng-packs/packages/permission-management/package.json @@ -11,7 +11,7 @@ "tslib": "^2.0.0" }, "peerDependencies": { - "@angular/aria": "~21.2.0" + "@angular/aria": "~22.1.0" }, "publishConfig": { "access": "public" diff --git a/npm/ng-packs/packages/schematics/package.json b/npm/ng-packs/packages/schematics/package.json index e03eb26ebc..c0a0f8019c 100644 --- a/npm/ng-packs/packages/schematics/package.json +++ b/npm/ng-packs/packages/schematics/package.json @@ -4,16 +4,16 @@ "author": "", "schematics": "./collection.json", "dependencies": { - "@angular-devkit/core": "~22.0.0", - "@angular-devkit/schematics": "~22.0.0", - "@angular/cli": "~22.0.0", + "@angular-devkit/core": "~22.1.0", + "@angular-devkit/schematics": "~22.1.0", + "@angular/cli": "~22.1.0", "got": "^11.5.2", "jsonc-parser": "^2.3.0", "should-quote": "^1.0.0", "typescript": "~6.0.3" }, "devDependencies": { - "@schematics/angular": "~22.0.0", + "@schematics/angular": "~22.1.0", "@types/jest": "29.4.4", "@types/node": "20.2.5", "jest": "29.4.3", diff --git a/npm/ng-packs/packages/setting-management/package.json b/npm/ng-packs/packages/setting-management/package.json index 9dbfecb71b..183cec556b 100644 --- a/npm/ng-packs/packages/setting-management/package.json +++ b/npm/ng-packs/packages/setting-management/package.json @@ -12,7 +12,7 @@ "tslib": "^2.0.0" }, "peerDependencies": { - "@angular/aria": "~21.2.0" + "@angular/aria": "~22.1.0" }, "publishConfig": { "access": "public" diff --git a/npm/ng-packs/packages/theme-shared/src/lib/components/breadcrumb/breadcrumb.component.html b/npm/ng-packs/packages/theme-shared/src/lib/components/breadcrumb/breadcrumb.component.html index b23fdc598e..1eabd84821 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/components/breadcrumb/breadcrumb.component.html +++ b/npm/ng-packs/packages/theme-shared/src/lib/components/breadcrumb/breadcrumb.component.html @@ -1 +1 @@ - + diff --git a/npm/ng-packs/packages/theme-shared/src/lib/components/breadcrumb/breadcrumb.component.ts b/npm/ng-packs/packages/theme-shared/src/lib/components/breadcrumb/breadcrumb.component.ts index b8a86342b1..884eb9db99 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/components/breadcrumb/breadcrumb.component.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/components/breadcrumb/breadcrumb.component.ts @@ -6,7 +6,7 @@ import { SubscriptionService, TreeNode, } from '@abp/ng.core'; -import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit, inject } from '@angular/core'; +import { ChangeDetectionStrategy, Component, OnInit, inject, signal } from '@angular/core'; import { Router } from '@angular/router'; import { map, startWith } from 'rxjs/operators'; import { eThemeSharedRouteNames } from '../../enums/route-names'; @@ -20,14 +20,13 @@ import { BreadcrumbItemsComponent } from '../breadcrumb-items/breadcrumb-items.c imports: [BreadcrumbItemsComponent], }) export class BreadcrumbComponent implements OnInit { - readonly cdRef = inject(ChangeDetectorRef); private router = inject(Router); private routes = inject(RoutesService); private subscription = inject(SubscriptionService); private routerEvents = inject(RouterEvents); private routeCultureUrl = inject(RouteBasedCultureUrlService); - segments: Partial[] = []; + readonly segments = signal[]>([]); ngOnInit(): void { this.subscription.addOne( @@ -38,18 +37,18 @@ export class BreadcrumbComponent implements OnInit { ), ), route => { - this.segments = []; + const next: Partial[] = []; if (route) { let node = { parent: route } as TreeNode; while (node.parent) { node = node.parent; const { parent, children, isLeaf, ...segment } = node; - if (!isAdministration(segment)) this.segments.unshift(segment); + if (!isAdministration(segment)) next.unshift(segment); } - - this.cdRef.detectChanges(); } + + this.segments.set(next); }, ); } diff --git a/npm/ng-packs/packages/theme-shared/src/lib/services/toaster.service.ts b/npm/ng-packs/packages/theme-shared/src/lib/services/toaster.service.ts index b6db6e7716..f1f3a5c114 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/services/toaster.service.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/services/toaster.service.ts @@ -1,4 +1,4 @@ -import { ApplicationRef, ComponentRef, inject, Injectable } from '@angular/core'; +import { ComponentRef, inject, Injectable } from '@angular/core'; import { ContentProjectionService, LocalizationParam, @@ -12,7 +12,6 @@ import { Toaster } from '../models'; providedIn: 'root', }) export class ToasterService implements ToasterContract { - private readonly appRef = inject(ApplicationRef); private readonly contentProjectionService = inject(ContentProjectionService); private lastId = -1; @@ -37,8 +36,9 @@ export class ToasterService implements ToasterContract { } this.containerComponentRef.instance.setToasts(this.toasts); + // Only refresh the projected toast host. Calling ApplicationRef.tick() here + // races with zone-driven CD and throws NG0101 (recursive tick). this.containerComponentRef.changeDetectorRef.detectChanges(); - this.appRef.tick(); } /** diff --git a/npm/ng-packs/packages/theme-shared/src/lib/tests/breadcrumb.component.spec.ts b/npm/ng-packs/packages/theme-shared/src/lib/tests/breadcrumb.component.spec.ts index 6ad217d3b8..ce1463e2cf 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/tests/breadcrumb.component.spec.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/tests/breadcrumb.component.spec.ts @@ -135,7 +135,7 @@ describe('BreadcrumbComponent', () => { const breadcrumb = spectator.fixture.debugElement.query(By.directive(BreadcrumbComponent)) .componentInstance as BreadcrumbComponent; - expect(breadcrumb.segments.map(segment => segment.path)).toEqual([ + expect(breadcrumb.segments().map(segment => segment.path)).toEqual([ '/identity', '/identity/users', ]); diff --git a/npm/packs/aspnetcore.mvc.ui.theme.shared/package.json b/npm/packs/aspnetcore.mvc.ui.theme.shared/package.json index b00d3571de..41840f27b4 100644 --- a/npm/packs/aspnetcore.mvc.ui.theme.shared/package.json +++ b/npm/packs/aspnetcore.mvc.ui.theme.shared/package.json @@ -19,7 +19,6 @@ "@abp/jquery-validation-unobtrusive": "~10.7.0", "@abp/lodash": "~10.7.0", "@abp/luxon": "~10.7.0", - "@abp/malihu-custom-scrollbar-plugin": "~10.7.0", "@abp/moment": "~10.7.0", "@abp/select2": "~10.7.0", "@abp/sweetalert2": "~10.7.0", diff --git a/npm/packs/blogging/package.json b/npm/packs/blogging/package.json index c069a1a581..43dba3ba47 100644 --- a/npm/packs/blogging/package.json +++ b/npm/packs/blogging/package.json @@ -6,7 +6,7 @@ }, "dependencies": { "@abp/aspnetcore.mvc.ui.theme.shared": "~10.7.0", - "@abp/owl.carousel": "~10.7.0", + "@abp/swiper": "~10.7.0", "@abp/prismjs": "~10.7.0", "@abp/tui-editor": "~10.7.0" }, diff --git a/npm/packs/bootstrap-datepicker/abp.resourcemapping.js b/npm/packs/bootstrap-datepicker/abp.resourcemapping.js index 2db70fc044..ee879d3b39 100644 --- a/npm/packs/bootstrap-datepicker/abp.resourcemapping.js +++ b/npm/packs/bootstrap-datepicker/abp.resourcemapping.js @@ -1,6 +1,6 @@ module.exports = { mappings: { - "@node_modules/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js": "@libs/bootstrap-datepicker/", + "@node_modules/@abp/bootstrap-datepicker/src/bootstrap-datepicker.js": "@libs/bootstrap-datepicker/", "@node_modules/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css": "@libs/bootstrap-datepicker/", "@node_modules/bootstrap-datepicker/dist/css/bootstrap-datepicker.css.map": "@libs/bootstrap-datepicker/", "@node_modules/bootstrap-datepicker/dist/locales/*.*": "@libs/bootstrap-datepicker/locales/" diff --git a/npm/packs/bootstrap-datepicker/package.json b/npm/packs/bootstrap-datepicker/package.json index 4c685a6b12..87e8fe44f4 100644 --- a/npm/packs/bootstrap-datepicker/package.json +++ b/npm/packs/bootstrap-datepicker/package.json @@ -10,7 +10,8 @@ "access": "public" }, "dependencies": { - "bootstrap-datepicker": "^1.10.1" + "bootstrap-datepicker": "1.10.1", + "jquery": "~4.0.0" }, "gitHead": "bb4ea17d5996f01889134c138d00b6c8f858a431", "homepage": "https://abp.io", diff --git a/npm/packs/bootstrap-datepicker/src/bootstrap-datepicker.js b/npm/packs/bootstrap-datepicker/src/bootstrap-datepicker.js new file mode 100644 index 0000000000..1772135e28 --- /dev/null +++ b/npm/packs/bootstrap-datepicker/src/bootstrap-datepicker.js @@ -0,0 +1,2048 @@ +/*! + * Datepicker for Bootstrap v1.10.1 (https://github.com/uxsolutions/bootstrap-datepicker) + * + * Licensed under the Apache License v2.0 (https://www.apache.org/licenses/LICENSE-2.0) + * + * Patched copy: uses Function.prototype.bind instead of the jQuery.proxy API deprecated in jQuery 4. + */ + +(function(factory){ + if (typeof define === 'function' && define.amd) { + define(['jquery'], factory); + } else if (typeof exports === 'object') { + factory(require('jquery')); + } else { + factory(jQuery); + } +}(function($, undefined){ + function UTCDate(){ + return new Date(Date.UTC.apply(Date, arguments)); + } + function UTCToday(){ + var today = new Date(); + return UTCDate(today.getFullYear(), today.getMonth(), today.getDate()); + } + function isUTCEquals(date1, date2) { + return ( + date1.getUTCFullYear() === date2.getUTCFullYear() && + date1.getUTCMonth() === date2.getUTCMonth() && + date1.getUTCDate() === date2.getUTCDate() + ); + } + function alias(method, deprecationMsg){ + return function(){ + if (deprecationMsg !== undefined) { + $.fn.datepicker.deprecated(deprecationMsg); + } + + return this[method].apply(this, arguments); + }; + } + function isValidDate(d) { + return d && !isNaN(d.getTime()); + } + + var DateArray = (function(){ + var extras = { + get: function(i){ + return this.slice(i)[0]; + }, + contains: function(d){ + // Array.indexOf is not cross-browser; + // $.inArray doesn't work with Dates + var val = d && d.valueOf(); + for (var i=0, l=this.length; i < l; i++) + // Use date arithmetic to allow dates with different times to match + if (0 <= this[i].valueOf() - val && this[i].valueOf() - val < 1000*60*60*24) + return i; + return -1; + }, + remove: function(i){ + this.splice(i,1); + }, + replace: function(new_array){ + if (!new_array) + return; + if (!Array.isArray(new_array)) + new_array = [new_array]; + this.clear(); + this.push.apply(this, new_array); + }, + clear: function(){ + this.length = 0; + }, + copy: function(){ + var a = new DateArray(); + a.replace(this); + return a; + } + }; + + return function(){ + var a = []; + a.push.apply(a, arguments); + $.extend(a, extras); + return a; + }; + })(); + + + // Picker object + + var Datepicker = function(element, options){ + $.data(element, 'datepicker', this); + + this._events = []; + this._secondaryEvents = []; + + this._process_options(options); + + this.dates = new DateArray(); + this.viewDate = this.o.defaultViewDate; + this.focusDate = null; + + this.element = $(element); + this.isInput = this.element.is('input'); + this.inputField = this.isInput ? this.element : this.element.find('input'); + this.component = this.element.hasClass('date') ? this.element.find('.add-on, .input-group-addon, .input-group-append, .input-group-prepend, .btn') : false; + if (this.component && this.component.length === 0){ + this.component = false; + } + + if (this.o.isInline === null){ + this.isInline = !this.component && !this.isInput; + } else { + this.isInline = this.o.isInline; + } + + this.picker = $(DPGlobal.template); + + // Checking templates and inserting + if (this._check_template(this.o.templates.leftArrow)) { + this.picker.find('.prev').html(this.o.templates.leftArrow); + } + + if (this._check_template(this.o.templates.rightArrow)) { + this.picker.find('.next').html(this.o.templates.rightArrow); + } + + this._buildEvents(); + this._attachEvents(); + + if (this.isInline){ + this.picker.addClass('datepicker-inline').appendTo(this.element); + } + else { + this.picker.addClass('datepicker-dropdown dropdown-menu'); + } + + if (this.o.rtl){ + this.picker.addClass('datepicker-rtl'); + } + + if (this.o.calendarWeeks) { + this.picker.find('.datepicker-days .datepicker-switch, thead .datepicker-title, tfoot .today, tfoot .clear') + .attr('colspan', function(i, val){ + return Number(val) + 1; + }); + } + + this._process_options({ + startDate: this._o.startDate, + endDate: this._o.endDate, + daysOfWeekDisabled: this.o.daysOfWeekDisabled, + daysOfWeekHighlighted: this.o.daysOfWeekHighlighted, + datesDisabled: this.o.datesDisabled + }); + + this._allow_update = false; + this.setViewMode(this.o.startView); + this._allow_update = true; + + this.fillDow(); + this.fillMonths(); + + this.update(); + + if (this.isInline){ + this.show(); + } + }; + + Datepicker.prototype = { + constructor: Datepicker, + + _resolveViewName: function(view){ + $.each(DPGlobal.viewModes, function(i, viewMode){ + if (view === i || $.inArray(view, viewMode.names) !== -1){ + view = i; + return false; + } + }); + + return view; + }, + + _resolveDaysOfWeek: function(daysOfWeek){ + if (!Array.isArray(daysOfWeek)) + daysOfWeek = daysOfWeek.split(/[,\s]*/); + return $.map(daysOfWeek, Number); + }, + + _check_template: function(tmp){ + try { + // If empty + if (tmp === undefined || tmp === "") { + return false; + } + // If no html, everything ok + if ((tmp.match(/[<>]/g) || []).length <= 0) { + return true; + } + // Checking if html is fine + var jDom = $(tmp); + return jDom.length > 0; + } + catch (ex) { + return false; + } + }, + + _process_options: function(opts){ + // Store raw options for reference + this._o = $.extend({}, this._o, opts); + // Processed options + var o = this.o = $.extend({}, this._o); + + // Check if "de-DE" style date is available, if not language should + // fallback to 2 letter code eg "de" + var lang = o.language; + if (!dates[lang]){ + lang = lang.split('-')[0]; + if (!dates[lang]) + lang = defaults.language; + } + o.language = lang; + + // Retrieve view index from any aliases + o.startView = this._resolveViewName(o.startView); + o.minViewMode = this._resolveViewName(o.minViewMode); + o.maxViewMode = this._resolveViewName(o.maxViewMode); + + // Check view is between min and max + o.startView = Math.max(this.o.minViewMode, Math.min(this.o.maxViewMode, o.startView)); + + // true, false, or Number > 0 + if (o.multidate !== true){ + o.multidate = Number(o.multidate) || false; + if (o.multidate !== false) + o.multidate = Math.max(0, o.multidate); + } + o.multidateSeparator = String(o.multidateSeparator); + + o.weekStart %= 7; + o.weekEnd = (o.weekStart + 6) % 7; + + var format = DPGlobal.parseFormat(o.format); + if (o.startDate !== -Infinity){ + if (!!o.startDate){ + if (o.startDate instanceof Date) + o.startDate = this._local_to_utc(this._zero_time(o.startDate)); + else + o.startDate = DPGlobal.parseDate(o.startDate, format, o.language, o.assumeNearbyYear); + } + else { + o.startDate = -Infinity; + } + } + if (o.endDate !== Infinity){ + if (!!o.endDate){ + if (o.endDate instanceof Date) + o.endDate = this._local_to_utc(this._zero_time(o.endDate)); + else + o.endDate = DPGlobal.parseDate(o.endDate, format, o.language, o.assumeNearbyYear); + } + else { + o.endDate = Infinity; + } + } + + o.daysOfWeekDisabled = this._resolveDaysOfWeek(o.daysOfWeekDisabled||[]); + o.daysOfWeekHighlighted = this._resolveDaysOfWeek(o.daysOfWeekHighlighted||[]); + + o.datesDisabled = o.datesDisabled||[]; + if (!Array.isArray(o.datesDisabled)) { + o.datesDisabled = o.datesDisabled.split(','); + } + o.datesDisabled = $.map(o.datesDisabled, function(d){ + return DPGlobal.parseDate(d, format, o.language, o.assumeNearbyYear); + }); + + var plc = String(o.orientation).toLowerCase().split(/\s+/g), + _plc = o.orientation.toLowerCase(); + plc = $.grep(plc, function(word){ + return /^auto|left|right|top|bottom$/.test(word); + }); + o.orientation = {x: 'auto', y: 'auto'}; + if (!_plc || _plc === 'auto') + ; // no action + else if (plc.length === 1){ + switch (plc[0]){ + case 'top': + case 'bottom': + o.orientation.y = plc[0]; + break; + case 'left': + case 'right': + o.orientation.x = plc[0]; + break; + } + } + else { + _plc = $.grep(plc, function(word){ + return /^left|right$/.test(word); + }); + o.orientation.x = _plc[0] || 'auto'; + + _plc = $.grep(plc, function(word){ + return /^top|bottom$/.test(word); + }); + o.orientation.y = _plc[0] || 'auto'; + } + if (o.defaultViewDate instanceof Date || typeof o.defaultViewDate === 'string') { + o.defaultViewDate = DPGlobal.parseDate(o.defaultViewDate, format, o.language, o.assumeNearbyYear); + } else if (o.defaultViewDate) { + var year = o.defaultViewDate.year || new Date().getFullYear(); + var month = o.defaultViewDate.month || 0; + var day = o.defaultViewDate.day || 1; + o.defaultViewDate = UTCDate(year, month, day); + } else { + o.defaultViewDate = UTCToday(); + } + }, + _applyEvents: function(evs){ + for (var i=0, el, ch, ev; i < evs.length; i++){ + el = evs[i][0]; + if (evs[i].length === 2){ + ch = undefined; + ev = evs[i][1]; + } else if (evs[i].length === 3){ + ch = evs[i][1]; + ev = evs[i][2]; + } + el.on(ev, ch); + } + }, + _unapplyEvents: function(evs){ + for (var i=0, el, ev, ch; i < evs.length; i++){ + el = evs[i][0]; + if (evs[i].length === 2){ + ch = undefined; + ev = evs[i][1]; + } else if (evs[i].length === 3){ + ch = evs[i][1]; + ev = evs[i][2]; + } + el.off(ev, ch); + } + }, + _buildEvents: function(){ + var events = { + keyup: (function(e){ + if ($.inArray(e.keyCode, [27, 37, 39, 38, 40, 32, 13, 9]) === -1) + this.update(); + }).bind(this), + keydown: this.keydown.bind(this), + paste: this.paste.bind(this) + }; + + if (this.o.showOnFocus === true) { + events.focus = this.show.bind(this); + } + + if (this.isInput) { // single input + this._events = [ + [this.element, events] + ]; + } + // component: input + button + else if (this.component && this.inputField.length) { + this._events = [ + // For components that are not readonly, allow keyboard nav + [this.inputField, events], + [this.component, { + click: this.show.bind(this) + }] + ]; + } + else { + this._events = [ + [this.element, { + click: this.show.bind(this), + keydown: this.keydown.bind(this) + }] + ]; + } + this._events.push( + // Component: listen for blur on element descendants + [this.element, '*', { + blur: (function(e){ + this._focused_from = e.target; + }).bind(this) + }], + // Input: listen for blur on element + [this.element, { + blur: (function(e){ + this._focused_from = e.target; + }).bind(this) + }] + ); + + if (this.o.immediateUpdates) { + // Trigger input updates immediately on changed year/month + this._events.push([this.element, { + 'changeYear changeMonth': (function(e){ + this.update(e.date); + }).bind(this) + }]); + } + + this._secondaryEvents = [ + [this.picker, { + click: this.click.bind(this) + }], + [this.picker, '.prev, .next', { + click: this.navArrowsClick.bind(this) + }], + [this.picker, '.day:not(.disabled)', { + click: this.dayCellClick.bind(this) + }], + [$(window), { + resize: this.place.bind(this) + }], + [$(document), { + 'mousedown touchstart': (function(e){ + // Clicked outside the datepicker, hide it + if (!( + this.element.is(e.target) || + this.element.find(e.target).length || + this.picker.is(e.target) || + this.picker.find(e.target).length || + this.isInline + )){ + this.hide(); + } + }).bind(this) + }] + ]; + }, + _attachEvents: function(){ + this._detachEvents(); + this._applyEvents(this._events); + }, + _detachEvents: function(){ + this._unapplyEvents(this._events); + }, + _attachSecondaryEvents: function(){ + this._detachSecondaryEvents(); + this._applyEvents(this._secondaryEvents); + }, + _detachSecondaryEvents: function(){ + this._unapplyEvents(this._secondaryEvents); + }, + _trigger: function(event, altdate){ + var date = altdate || this.dates.get(-1), + local_date = this._utc_to_local(date); + + this.element.trigger({ + type: event, + date: local_date, + viewMode: this.viewMode, + dates: $.map(this.dates, this._utc_to_local), + format: (function(ix, format){ + if (arguments.length === 0){ + ix = this.dates.length - 1; + format = this.o.format; + } else if (typeof ix === 'string'){ + format = ix; + ix = this.dates.length - 1; + } + format = format || this.o.format; + var date = this.dates.get(ix); + return DPGlobal.formatDate(date, format, this.o.language); + }).bind(this) + }); + }, + + show: function(){ + if (this.inputField.is(':disabled') || (this.inputField.prop('readonly') && this.o.enableOnReadonly === false)) + return; + if (!this.isInline) + this.picker.appendTo(this.o.container); + this.place(); + this.picker.show(); + this._attachSecondaryEvents(); + this._trigger('show'); + if ((window.navigator.msMaxTouchPoints || 'ontouchstart' in document) && this.o.disableTouchKeyboard) { + $(this.element).blur(); + } + return this; + }, + + hide: function(){ + if (this.isInline || !this.picker.is(':visible')) + return this; + this.focusDate = null; + this.picker.hide().detach(); + this._detachSecondaryEvents(); + this.setViewMode(this.o.startView); + + if (this.o.forceParse && this.inputField.val()) + this.setValue(); + this._trigger('hide'); + return this; + }, + + destroy: function(){ + this.hide(); + this._detachEvents(); + this._detachSecondaryEvents(); + this.picker.remove(); + delete this.element.data().datepicker; + if (!this.isInput){ + delete this.element.data().date; + } + return this; + }, + + paste: function(e){ + var dateString; + if (e.originalEvent.clipboardData && e.originalEvent.clipboardData.types + && $.inArray('text/plain', e.originalEvent.clipboardData.types) !== -1) { + dateString = e.originalEvent.clipboardData.getData('text/plain'); + } else if (window.clipboardData) { + dateString = window.clipboardData.getData('Text'); + } else { + return; + } + this.setDate(dateString); + this.update(); + e.preventDefault(); + }, + + _utc_to_local: function(utc){ + if (!utc) { + return utc; + } + + var local = new Date(utc.getTime() + (utc.getTimezoneOffset() * 60000)); + + if (local.getTimezoneOffset() !== utc.getTimezoneOffset()) { + local = new Date(utc.getTime() + (local.getTimezoneOffset() * 60000)); + } + + return local; + }, + _local_to_utc: function(local){ + return local && new Date(local.getTime() - (local.getTimezoneOffset()*60000)); + }, + _zero_time: function(local){ + return local && new Date(local.getFullYear(), local.getMonth(), local.getDate()); + }, + _zero_utc_time: function(utc){ + return utc && UTCDate(utc.getUTCFullYear(), utc.getUTCMonth(), utc.getUTCDate()); + }, + + getDates: function(){ + return $.map(this.dates, this._utc_to_local); + }, + + getUTCDates: function(){ + return $.map(this.dates, function(d){ + return new Date(d); + }); + }, + + getDate: function(){ + return this._utc_to_local(this.getUTCDate()); + }, + + getUTCDate: function(){ + var selected_date = this.dates.get(-1); + if (selected_date !== undefined) { + return new Date(selected_date); + } else { + return null; + } + }, + + clearDates: function(){ + this.inputField.val(''); + this._trigger('changeDate'); + this.update(); + if (this.o.autoclose) { + this.hide(); + } + }, + + setDates: function(){ + var args = Array.isArray(arguments[0]) ? arguments[0] : arguments; + this.update.apply(this, args); + this._trigger('changeDate'); + this.setValue(); + return this; + }, + + setUTCDates: function(){ + var args = Array.isArray(arguments[0]) ? arguments[0] : arguments; + this.setDates.apply(this, $.map(args, this._utc_to_local)); + return this; + }, + + setDate: alias('setDates'), + setUTCDate: alias('setUTCDates'), + remove: alias('destroy', 'Method `remove` is deprecated and will be removed in version 2.0. Use `destroy` instead'), + + setValue: function(){ + var formatted = this.getFormattedDate(); + this.inputField.val(formatted); + return this; + }, + + getFormattedDate: function(format){ + if (format === undefined) + format = this.o.format; + + var lang = this.o.language; + return $.map(this.dates, function(d){ + return DPGlobal.formatDate(d, format, lang); + }).join(this.o.multidateSeparator); + }, + + getStartDate: function(){ + return this.o.startDate; + }, + + setStartDate: function(startDate){ + this._process_options({startDate: startDate}); + this.update(); + this.updateNavArrows(); + return this; + }, + + getEndDate: function(){ + return this.o.endDate; + }, + + setEndDate: function(endDate){ + this._process_options({endDate: endDate}); + this.update(); + this.updateNavArrows(); + return this; + }, + + setDaysOfWeekDisabled: function(daysOfWeekDisabled){ + this._process_options({daysOfWeekDisabled: daysOfWeekDisabled}); + this.update(); + return this; + }, + + setDaysOfWeekHighlighted: function(daysOfWeekHighlighted){ + this._process_options({daysOfWeekHighlighted: daysOfWeekHighlighted}); + this.update(); + return this; + }, + + setDatesDisabled: function(datesDisabled){ + this._process_options({datesDisabled: datesDisabled}); + this.update(); + return this; + }, + + place: function(){ + if (this.isInline) + return this; + var calendarWidth = this.picker.outerWidth(), + calendarHeight = this.picker.outerHeight(), + visualPadding = 10, + container = $(this.o.container), + windowWidth = container.width(), + scrollTop = this.o.container === 'body' ? $(document).scrollTop() : container.scrollTop(), + appendOffset = container.offset(); + + var parentsZindex = [0]; + this.element.parents().each(function(){ + var itemZIndex = $(this).css('z-index'); + if (itemZIndex !== 'auto' && Number(itemZIndex) !== 0) parentsZindex.push(Number(itemZIndex)); + }); + var zIndex = Math.max.apply(Math, parentsZindex) + this.o.zIndexOffset; + var offset = this.component ? this.component.parent().offset() : this.element.offset(); + var height = this.component ? this.component.outerHeight(true) : this.element.outerHeight(false); + var width = this.component ? this.component.outerWidth(true) : this.element.outerWidth(false); + var left = offset.left - appendOffset.left; + var top = offset.top - appendOffset.top; + + if (this.o.container !== 'body') { + top += scrollTop; + } + + this.picker.removeClass( + 'datepicker-orient-top datepicker-orient-bottom '+ + 'datepicker-orient-right datepicker-orient-left' + ); + + if (this.o.orientation.x !== 'auto'){ + this.picker.addClass('datepicker-orient-' + this.o.orientation.x); + if (this.o.orientation.x === 'right') + left -= calendarWidth - width; + } + // auto x orientation is best-placement: if it crosses a window + // edge, fudge it sideways + else { + if (offset.left < 0) { + // component is outside the window on the left side. Move it into visible range + this.picker.addClass('datepicker-orient-left'); + left -= offset.left - visualPadding; + } else if (left + calendarWidth > windowWidth) { + // the calendar passes the widow right edge. Align it to component right side + this.picker.addClass('datepicker-orient-right'); + left += width - calendarWidth; + } else { + if (this.o.rtl) { + // Default to right + this.picker.addClass('datepicker-orient-right'); + } else { + // Default to left + this.picker.addClass('datepicker-orient-left'); + } + } + } + + // auto y orientation is best-situation: top or bottom, no fudging, + // decision based on which shows more of the calendar + var yorient = this.o.orientation.y, + top_overflow; + if (yorient === 'auto'){ + top_overflow = -scrollTop + top - calendarHeight; + yorient = top_overflow < 0 ? 'bottom' : 'top'; + } + + this.picker.addClass('datepicker-orient-' + yorient); + if (yorient === 'top') + top -= calendarHeight + parseInt(this.picker.css('padding-top')); + else + top += height; + + if (this.o.rtl) { + var right = windowWidth - (left + width); + this.picker.css({ + top: top, + right: right, + zIndex: zIndex + }); + } else { + this.picker.css({ + top: top, + left: left, + zIndex: zIndex + }); + } + return this; + }, + + _allow_update: true, + update: function(){ + if (!this._allow_update) + return this; + + var oldDates = this.dates.copy(), + dates = [], + fromArgs = false; + if (arguments.length){ + $.each(arguments, (function(i, date){ + if (date instanceof Date) + date = this._local_to_utc(date); + dates.push(date); + }).bind(this)); + fromArgs = true; + } else { + dates = this.isInput + ? this.element.val() + : this.element.data('date') || this.inputField.val(); + if (dates && this.o.multidate) + dates = dates.split(this.o.multidateSeparator); + else + dates = [dates]; + delete this.element.data().date; + } + + dates = $.map(dates, (function(date){ + return DPGlobal.parseDate(date, this.o.format, this.o.language, this.o.assumeNearbyYear); + }).bind(this)); + dates = $.grep(dates, (function(date){ + return ( + !this.dateWithinRange(date) || + !date + ); + }).bind(this), true); + this.dates.replace(dates); + + if (this.o.updateViewDate) { + if (this.dates.length) + this.viewDate = new Date(this.dates.get(-1)); + else if (this.viewDate < this.o.startDate) + this.viewDate = new Date(this.o.startDate); + else if (this.viewDate > this.o.endDate) + this.viewDate = new Date(this.o.endDate); + else + this.viewDate = this.o.defaultViewDate; + } + + if (fromArgs){ + // setting date by clicking + this.setValue(); + this.element.change(); + } + else if (this.dates.length){ + // setting date by typing + if (String(oldDates) !== String(this.dates) && fromArgs) { + this._trigger('changeDate'); + this.element.change(); + } + } + if (!this.dates.length && oldDates.length) { + this._trigger('clearDate'); + this.element.change(); + } + + this.fill(); + return this; + }, + + fillDow: function(){ + if (this.o.showWeekDays) { + var dowCnt = this.o.weekStart, + html = ''; + if (this.o.calendarWeeks){ + html += ' '; + } + while (dowCnt < this.o.weekStart + 7){ + html += ''+dates[this.o.language].daysMin[(dowCnt++)%7]+''; + } + html += ''; + this.picker.find('.datepicker-days thead').append(html); + } + }, + + fillMonths: function(){ + var localDate = this._utc_to_local(this.viewDate); + var html = ''; + var focused; + for (var i = 0; i < 12; i++){ + focused = localDate && localDate.getMonth() === i ? ' focused' : ''; + html += '' + dates[this.o.language].monthsShort[i] + ''; + } + this.picker.find('.datepicker-months td').html(html); + }, + + setRange: function(range){ + if (!range || !range.length) + delete this.range; + else + this.range = $.map(range, function(d){ + return d.valueOf(); + }); + this.fill(); + }, + + getClassNames: function(date){ + var cls = [], + year = this.viewDate.getUTCFullYear(), + month = this.viewDate.getUTCMonth(), + today = UTCToday(); + if (date.getUTCFullYear() < year || (date.getUTCFullYear() === year && date.getUTCMonth() < month)){ + cls.push('old'); + } else if (date.getUTCFullYear() > year || (date.getUTCFullYear() === year && date.getUTCMonth() > month)){ + cls.push('new'); + } + if (this.focusDate && date.valueOf() === this.focusDate.valueOf()) + cls.push('focused'); + // Compare internal UTC date with UTC today, not local today + if (this.o.todayHighlight && isUTCEquals(date, today)) { + cls.push('today'); + } + if (this.dates.contains(date) !== -1) + cls.push('active'); + if (!this.dateWithinRange(date)){ + cls.push('disabled'); + } + if (this.dateIsDisabled(date)){ + cls.push('disabled', 'disabled-date'); + } + if ($.inArray(date.getUTCDay(), this.o.daysOfWeekHighlighted) !== -1){ + cls.push('highlighted'); + } + + if (this.range){ + if (date > this.range[0] && date < this.range[this.range.length-1]){ + cls.push('range'); + } + if ($.inArray(date.valueOf(), this.range) !== -1){ + cls.push('selected'); + } + if (date.valueOf() === this.range[0]){ + cls.push('range-start'); + } + if (date.valueOf() === this.range[this.range.length-1]){ + cls.push('range-end'); + } + } + return cls; + }, + + _fill_yearsView: function(selector, cssClass, factor, year, startYear, endYear, beforeFn){ + var html = ''; + var step = factor / 10; + var view = this.picker.find(selector); + var startVal = Math.floor(year / factor) * factor; + var endVal = startVal + step * 9; + var focusedVal = Math.floor(this.viewDate.getFullYear() / step) * step; + var selected = $.map(this.dates, function(d){ + return Math.floor(d.getUTCFullYear() / step) * step; + }); + + var classes, tooltip, before; + for (var currVal = startVal - step; currVal <= endVal + step; currVal += step) { + classes = [cssClass]; + tooltip = null; + + if (currVal === startVal - step) { + classes.push('old'); + } else if (currVal === endVal + step) { + classes.push('new'); + } + if ($.inArray(currVal, selected) !== -1) { + classes.push('active'); + } + if (currVal < startYear || currVal > endYear) { + classes.push('disabled'); + } + if (currVal === focusedVal) { + classes.push('focused'); + } + + if (beforeFn !== $.noop) { + before = beforeFn(new Date(currVal, 0, 1)); + if (before === undefined) { + before = {}; + } else if (typeof before === 'boolean') { + before = {enabled: before}; + } else if (typeof before === 'string') { + before = {classes: before}; + } + if (before.enabled === false) { + classes.push('disabled'); + } + if (before.classes) { + classes = classes.concat(before.classes.split(/\s+/)); + } + if (before.tooltip) { + tooltip = before.tooltip; + } + } + + html += '' + currVal + ''; + } + + view.find('.datepicker-switch').text(startVal + '-' + endVal); + view.find('td').html(html); + }, + + fill: function(){ + var d = new Date(this.viewDate), + year = d.getUTCFullYear(), + month = d.getUTCMonth(), + startYear = this.o.startDate !== -Infinity ? this.o.startDate.getUTCFullYear() : -Infinity, + startMonth = this.o.startDate !== -Infinity ? this.o.startDate.getUTCMonth() : -Infinity, + endYear = this.o.endDate !== Infinity ? this.o.endDate.getUTCFullYear() : Infinity, + endMonth = this.o.endDate !== Infinity ? this.o.endDate.getUTCMonth() : Infinity, + todaytxt = dates[this.o.language].today || dates['en'].today || '', + cleartxt = dates[this.o.language].clear || dates['en'].clear || '', + titleFormat = dates[this.o.language].titleFormat || dates['en'].titleFormat, + todayDate = UTCToday(), + titleBtnVisible = (this.o.todayBtn === true || this.o.todayBtn === 'linked') && todayDate >= this.o.startDate && todayDate <= this.o.endDate && !this.weekOfDateIsDisabled(todayDate), + tooltip, + before; + if (isNaN(year) || isNaN(month)) + return; + this.picker.find('.datepicker-days .datepicker-switch') + .text(DPGlobal.formatDate(d, titleFormat, this.o.language)); + this.picker.find('tfoot .today') + .text(todaytxt) + .css('display', titleBtnVisible ? 'table-cell' : 'none'); + this.picker.find('tfoot .clear') + .text(cleartxt) + .css('display', this.o.clearBtn === true ? 'table-cell' : 'none'); + this.picker.find('thead .datepicker-title') + .text(this.o.title) + .css('display', typeof this.o.title === 'string' && this.o.title !== '' ? 'table-cell' : 'none'); + this.updateNavArrows(); + this.fillMonths(); + var prevMonth = UTCDate(year, month, 0), + day = prevMonth.getUTCDate(); + prevMonth.setUTCDate(day - (prevMonth.getUTCDay() - this.o.weekStart + 7)%7); + var nextMonth = new Date(prevMonth); + if (prevMonth.getUTCFullYear() < 100){ + nextMonth.setUTCFullYear(prevMonth.getUTCFullYear()); + } + nextMonth.setUTCDate(nextMonth.getUTCDate() + 42); + nextMonth = nextMonth.valueOf(); + var html = []; + var weekDay, clsName; + while (prevMonth.valueOf() < nextMonth){ + weekDay = prevMonth.getUTCDay(); + if (weekDay === this.o.weekStart){ + html.push(''); + if (this.o.calendarWeeks){ + // ISO 8601: First week contains first thursday. + // ISO also states week starts on Monday, but we can be more abstract here. + var + // Start of current week: based on weekstart/current date + ws = new Date(+prevMonth + (this.o.weekStart - weekDay - 7) % 7 * 864e5), + // Thursday of this week + th = new Date(Number(ws) + (7 + 4 - ws.getUTCDay()) % 7 * 864e5), + // First Thursday of year, year from thursday + yth = new Date(Number(yth = UTCDate(th.getUTCFullYear(), 0, 1)) + (7 + 4 - yth.getUTCDay()) % 7 * 864e5), + // Calendar week: ms between thursdays, div ms per day, div 7 days + calWeek = (th - yth) / 864e5 / 7 + 1; + html.push(''+ calWeek +''); + } + } + clsName = this.getClassNames(prevMonth); + clsName.push('day'); + + var content = prevMonth.getUTCDate(); + + if (this.o.beforeShowDay !== $.noop){ + before = this.o.beforeShowDay(this._utc_to_local(prevMonth)); + if (before === undefined) + before = {}; + else if (typeof before === 'boolean') + before = {enabled: before}; + else if (typeof before === 'string') + before = {classes: before}; + if (before.enabled === false) + clsName.push('disabled'); + if (before.classes) + clsName = clsName.concat(before.classes.split(/\s+/)); + if (before.tooltip) + tooltip = before.tooltip; + if (before.content) + content = before.content; + } + + //Check if uniqueSort exists (supported by jquery >=1.12 and >=2.2) + //Fallback to unique function for older jquery versions + if (typeof $.uniqueSort === "function") { + clsName = $.uniqueSort(clsName); + } else { + clsName = $.unique(clsName); + } + + html.push('' + content + ''); + tooltip = null; + if (weekDay === this.o.weekEnd){ + html.push(''); + } + prevMonth.setUTCDate(prevMonth.getUTCDate() + 1); + } + this.picker.find('.datepicker-days tbody').html(html.join('')); + + var monthsTitle = dates[this.o.language].monthsTitle || dates['en'].monthsTitle || 'Months'; + var months = this.picker.find('.datepicker-months') + .find('.datepicker-switch') + .text(this.o.maxViewMode < 2 ? monthsTitle : year) + .end() + .find('tbody span').removeClass('active'); + + $.each(this.dates, function(i, d){ + if (d.getUTCFullYear() === year) + months.eq(d.getUTCMonth()).addClass('active'); + }); + + if (year < startYear || year > endYear){ + months.addClass('disabled'); + } + if (year === startYear){ + months.slice(0, startMonth).addClass('disabled'); + } + if (year === endYear){ + months.slice(endMonth+1).addClass('disabled'); + } + + if (this.o.beforeShowMonth !== $.noop){ + var that = this; + $.each(months, function(i, month){ + var moDate = new Date(year, i, 1); + var before = that.o.beforeShowMonth(moDate); + if (before === undefined) + before = {}; + else if (typeof before === 'boolean') + before = {enabled: before}; + else if (typeof before === 'string') + before = {classes: before}; + if (before.enabled === false && !$(month).hasClass('disabled')) + $(month).addClass('disabled'); + if (before.classes) + $(month).addClass(before.classes); + if (before.tooltip) + $(month).prop('title', before.tooltip); + }); + } + + // Generating decade/years picker + this._fill_yearsView( + '.datepicker-years', + 'year', + 10, + year, + startYear, + endYear, + this.o.beforeShowYear + ); + + // Generating century/decades picker + this._fill_yearsView( + '.datepicker-decades', + 'decade', + 100, + year, + startYear, + endYear, + this.o.beforeShowDecade + ); + + // Generating millennium/centuries picker + this._fill_yearsView( + '.datepicker-centuries', + 'century', + 1000, + year, + startYear, + endYear, + this.o.beforeShowCentury + ); + }, + + updateNavArrows: function(){ + if (!this._allow_update) + return; + + var d = new Date(this.viewDate), + year = d.getUTCFullYear(), + month = d.getUTCMonth(), + startYear = this.o.startDate !== -Infinity ? this.o.startDate.getUTCFullYear() : -Infinity, + startMonth = this.o.startDate !== -Infinity ? this.o.startDate.getUTCMonth() : -Infinity, + endYear = this.o.endDate !== Infinity ? this.o.endDate.getUTCFullYear() : Infinity, + endMonth = this.o.endDate !== Infinity ? this.o.endDate.getUTCMonth() : Infinity, + prevIsDisabled, + nextIsDisabled, + factor = 1; + switch (this.viewMode){ + case 4: + factor *= 10; + /* falls through */ + case 3: + factor *= 10; + /* falls through */ + case 2: + factor *= 10; + /* falls through */ + case 1: + prevIsDisabled = Math.floor(year / factor) * factor <= startYear; + nextIsDisabled = Math.floor(year / factor) * factor + factor > endYear; + break; + case 0: + prevIsDisabled = year <= startYear && month <= startMonth; + nextIsDisabled = year >= endYear && month >= endMonth; + break; + } + + this.picker.find('.prev').toggleClass('disabled', prevIsDisabled); + this.picker.find('.next').toggleClass('disabled', nextIsDisabled); + }, + + click: function(e){ + e.preventDefault(); + e.stopPropagation(); + + var target, dir, day, year, month; + target = $(e.target); + + // Clicked on the switch + if (target.hasClass('datepicker-switch') && this.viewMode !== this.o.maxViewMode){ + this.setViewMode(this.viewMode + 1); + } + + // Clicked on today button + if (target.hasClass('today') && !target.hasClass('day')){ + this.setViewMode(0); + this._setDate(UTCToday(), this.o.todayBtn === 'linked' ? null : 'view'); + } + + // Clicked on clear button + if (target.hasClass('clear')){ + this.clearDates(); + } + + if (!target.hasClass('disabled')){ + // Clicked on a month, year, decade, century + if (target.hasClass('month') + || target.hasClass('year') + || target.hasClass('decade') + || target.hasClass('century')) { + this.viewDate.setUTCDate(1); + + day = 1; + if (this.viewMode === 1){ + month = target.parent().find('span').index(target); + year = this.viewDate.getUTCFullYear(); + this.viewDate.setUTCMonth(month); + } else { + month = 0; + year = Number(target.text()); + this.viewDate.setUTCFullYear(year); + } + + this._trigger(DPGlobal.viewModes[this.viewMode - 1].e, this.viewDate); + + if (this.viewMode === this.o.minViewMode){ + this._setDate(UTCDate(year, month, day)); + } else { + this.setViewMode(this.viewMode - 1); + this.fill(); + } + } + } + + if (this.picker.is(':visible') && this._focused_from){ + this._focused_from.focus(); + } + delete this._focused_from; + }, + + dayCellClick: function(e){ + var $target = $(e.currentTarget); + var timestamp = $target.data('date'); + var date = new Date(timestamp); + + if (this.o.updateViewDate) { + if (date.getUTCFullYear() !== this.viewDate.getUTCFullYear()) { + this._trigger('changeYear', this.viewDate); + } + + if (date.getUTCMonth() !== this.viewDate.getUTCMonth()) { + this._trigger('changeMonth', this.viewDate); + } + } + this._setDate(date); + }, + + // Clicked on prev or next + navArrowsClick: function(e){ + var $target = $(e.currentTarget); + var dir = $target.hasClass('prev') ? -1 : 1; + if (this.viewMode !== 0){ + dir *= DPGlobal.viewModes[this.viewMode].navStep * 12; + } + this.viewDate = this.moveMonth(this.viewDate, dir); + this._trigger(DPGlobal.viewModes[this.viewMode].e, this.viewDate); + this.fill(); + }, + + _toggle_multidate: function(date){ + var ix = this.dates.contains(date); + if (!date){ + this.dates.clear(); + } + + if (ix !== -1){ + if (this.o.multidate === true || this.o.multidate > 1 || this.o.toggleActive){ + this.dates.remove(ix); + } + } else if (this.o.multidate === false) { + this.dates.clear(); + this.dates.push(date); + } + else { + this.dates.push(date); + } + + if (typeof this.o.multidate === 'number') + while (this.dates.length > this.o.multidate) + this.dates.remove(0); + }, + + _setDate: function(date, which){ + if (!which || which === 'date') + this._toggle_multidate(date && new Date(date)); + if ((!which && this.o.updateViewDate) || which === 'view') + this.viewDate = date && new Date(date); + + this.fill(); + this.setValue(); + if (!which || which !== 'view') { + this._trigger('changeDate'); + } + this.inputField.trigger('change'); + if (this.o.autoclose && (!which || which === 'date')){ + this.hide(); + } + }, + + moveDay: function(date, dir){ + var newDate = new Date(date); + newDate.setUTCDate(date.getUTCDate() + dir); + + return newDate; + }, + + moveWeek: function(date, dir){ + return this.moveDay(date, dir * 7); + }, + + moveMonth: function(date, dir){ + if (!isValidDate(date)) + return this.o.defaultViewDate; + if (!dir) + return date; + var new_date = new Date(date.valueOf()), + day = new_date.getUTCDate(), + month = new_date.getUTCMonth(), + mag = Math.abs(dir), + new_month, test; + dir = dir > 0 ? 1 : -1; + if (mag === 1){ + test = dir === -1 + // If going back one month, make sure month is not current month + // (eg, Mar 31 -> Feb 31 == Feb 28, not Mar 02) + ? function(){ + return new_date.getUTCMonth() === month; + } + // If going forward one month, make sure month is as expected + // (eg, Jan 31 -> Feb 31 == Feb 28, not Mar 02) + : function(){ + return new_date.getUTCMonth() !== new_month; + }; + new_month = month + dir; + new_date.setUTCMonth(new_month); + // Dec -> Jan (12) or Jan -> Dec (-1) -- limit expected date to 0-11 + new_month = (new_month + 12) % 12; + } + else { + // For magnitudes >1, move one month at a time... + for (var i=0; i < mag; i++) + // ...which might decrease the day (eg, Jan 31 to Feb 28, etc)... + new_date = this.moveMonth(new_date, dir); + // ...then reset the day, keeping it in the new month + new_month = new_date.getUTCMonth(); + new_date.setUTCDate(day); + test = function(){ + return new_month !== new_date.getUTCMonth(); + }; + } + // Common date-resetting loop -- if date is beyond end of month, make it + // end of month + while (test()){ + new_date.setUTCDate(--day); + new_date.setUTCMonth(new_month); + } + return new_date; + }, + + moveYear: function(date, dir){ + return this.moveMonth(date, dir*12); + }, + + moveAvailableDate: function(date, dir, fn){ + do { + date = this[fn](date, dir); + + if (!this.dateWithinRange(date)) + return false; + + fn = 'moveDay'; + } + while (this.dateIsDisabled(date)); + + return date; + }, + + weekOfDateIsDisabled: function(date){ + return $.inArray(date.getUTCDay(), this.o.daysOfWeekDisabled) !== -1; + }, + + dateIsDisabled: function(date){ + return ( + this.weekOfDateIsDisabled(date) || + $.grep(this.o.datesDisabled, function(d){ + return isUTCEquals(date, d); + }).length > 0 + ); + }, + + dateWithinRange: function(date){ + return date >= this.o.startDate && date <= this.o.endDate; + }, + + keydown: function(e){ + if (!this.picker.is(':visible')){ + if (e.keyCode === 40 || e.keyCode === 27) { // allow down to re-show picker + this.show(); + e.stopPropagation(); + } + return; + } + var dateChanged = false, + dir, newViewDate, + focusDate = this.focusDate || this.viewDate; + switch (e.keyCode){ + case 27: // escape + if (this.focusDate){ + this.focusDate = null; + this.viewDate = this.dates.get(-1) || this.viewDate; + this.fill(); + } + else + this.hide(); + e.preventDefault(); + e.stopPropagation(); + break; + case 37: // left + case 38: // up + case 39: // right + case 40: // down + if (!this.o.keyboardNavigation || this.o.daysOfWeekDisabled.length === 7) + break; + dir = e.keyCode === 37 || e.keyCode === 38 ? -1 : 1; + if (this.viewMode === 0) { + if (e.ctrlKey){ + newViewDate = this.moveAvailableDate(focusDate, dir, 'moveYear'); + + if (newViewDate) + this._trigger('changeYear', this.viewDate); + } else if (e.shiftKey){ + newViewDate = this.moveAvailableDate(focusDate, dir, 'moveMonth'); + + if (newViewDate) + this._trigger('changeMonth', this.viewDate); + } else if (e.keyCode === 37 || e.keyCode === 39){ + newViewDate = this.moveAvailableDate(focusDate, dir, 'moveDay'); + } else if (!this.weekOfDateIsDisabled(focusDate)){ + newViewDate = this.moveAvailableDate(focusDate, dir, 'moveWeek'); + } + } else if (this.viewMode === 1) { + if (e.keyCode === 38 || e.keyCode === 40) { + dir = dir * 4; + } + newViewDate = this.moveAvailableDate(focusDate, dir, 'moveMonth'); + } else if (this.viewMode === 2) { + if (e.keyCode === 38 || e.keyCode === 40) { + dir = dir * 4; + } + newViewDate = this.moveAvailableDate(focusDate, dir, 'moveYear'); + } + if (newViewDate){ + this.focusDate = this.viewDate = newViewDate; + this.setValue(); + this.fill(); + e.preventDefault(); + } + break; + case 13: // enter + if (!this.o.forceParse) + break; + focusDate = this.focusDate || this.dates.get(-1) || this.viewDate; + if (this.o.keyboardNavigation) { + this._toggle_multidate(focusDate); + dateChanged = true; + } + this.focusDate = null; + this.viewDate = this.dates.get(-1) || this.viewDate; + this.setValue(); + this.fill(); + if (this.picker.is(':visible')){ + e.preventDefault(); + e.stopPropagation(); + if (this.o.autoclose) + this.hide(); + } + break; + case 9: // tab + this.focusDate = null; + this.viewDate = this.dates.get(-1) || this.viewDate; + this.fill(); + this.hide(); + break; + } + if (dateChanged){ + if (this.dates.length) + this._trigger('changeDate'); + else + this._trigger('clearDate'); + this.inputField.trigger('change'); + } + }, + + setViewMode: function(viewMode){ + this.viewMode = viewMode; + this.picker + .children('div') + .hide() + .filter('.datepicker-' + DPGlobal.viewModes[this.viewMode].clsName) + .show(); + this.updateNavArrows(); + this._trigger('changeViewMode', new Date(this.viewDate)); + } + }; + + var DateRangePicker = function(element, options){ + $.data(element, 'datepicker', this); + this.element = $(element); + this.inputs = $.map(options.inputs, function(i){ + return i.jquery ? i[0] : i; + }); + delete options.inputs; + + this.keepEmptyValues = options.keepEmptyValues; + delete options.keepEmptyValues; + + this._dateUpdatedHandler = this.dateUpdated.bind(this); + datepickerPlugin.call($(this.inputs), options) + .on('changeDate', this._dateUpdatedHandler); + + this.pickers = $.map(this.inputs, function(i){ + return $.data(i, 'datepicker'); + }); + this.updateDates(); + }; + DateRangePicker.prototype = { + updateDates: function(){ + this.dates = $.map(this.pickers, function(i){ + return i.getUTCDate(); + }); + this.updateRanges(); + }, + updateRanges: function(){ + var range = $.map(this.dates, function(d){ + return d.valueOf(); + }); + $.each(this.pickers, function(i, p){ + p.setRange(range); + }); + }, + clearDates: function(){ + $.each(this.pickers, function(i, p){ + p.clearDates(); + }); + }, + dateUpdated: function(e){ + // `this.updating` is a workaround for preventing infinite recursion + // between `changeDate` triggering and `setUTCDate` calling. Until + // there is a better mechanism. + if (this.updating) + return; + this.updating = true; + + var dp = $.data(e.target, 'datepicker'); + + if (dp === undefined) { + return; + } + + var new_date = dp.getUTCDate(), + keep_empty_values = this.keepEmptyValues, + i = $.inArray(e.target, this.inputs), + j = i - 1, + k = i + 1, + l = this.inputs.length; + if (i === -1) + return; + + $.each(this.pickers, function(i, p){ + if (!p.getUTCDate() && (p === dp || !keep_empty_values)) + p.setUTCDate(new_date); + }); + + if (new_date < this.dates[j]){ + // Date being moved earlier/left + while (j >= 0 && new_date < this.dates[j] && (this.pickers[j].element.val() || "").length > 0) { + this.pickers[j--].setUTCDate(new_date); + } + } else if (new_date > this.dates[k]){ + // Date being moved later/right + while (k < l && new_date > this.dates[k] && (this.pickers[k].element.val() || "").length > 0) { + this.pickers[k++].setUTCDate(new_date); + } + } + this.updateDates(); + + delete this.updating; + }, + destroy: function(){ + $.map(this.pickers, function(p){ p.destroy(); }); + $(this.inputs).off('changeDate', this._dateUpdatedHandler); + delete this.element.data().datepicker; + }, + remove: alias('destroy', 'Method `remove` is deprecated and will be removed in version 2.0. Use `destroy` instead') + }; + + function opts_from_el(el, prefix){ + // Derive options from element data-attrs + var data = $(el).data(), + out = {}, inkey, + replace = new RegExp('^' + prefix.toLowerCase() + '([A-Z])'); + prefix = new RegExp('^' + prefix.toLowerCase()); + function re_lower(_,a){ + return a.toLowerCase(); + } + for (var key in data) + if (prefix.test(key)){ + inkey = key.replace(replace, re_lower); + out[inkey] = data[key]; + } + return out; + } + + function opts_from_locale(lang){ + // Derive options from locale plugins + var out = {}; + // Check if "de-DE" style date is available, if not language should + // fallback to 2 letter code eg "de" + if (!dates[lang]){ + lang = lang.split('-')[0]; + if (!dates[lang]) + return; + } + var d = dates[lang]; + $.each(locale_opts, function(i,k){ + if (k in d) + out[k] = d[k]; + }); + return out; + } + + var old = $.fn.datepicker; + var datepickerPlugin = function(option){ + var args = Array.apply(null, arguments); + args.shift(); + var internal_return; + this.each(function(){ + var $this = $(this), + data = $this.data('datepicker'), + options = typeof option === 'object' && option; + if (!data){ + var elopts = opts_from_el(this, 'date'), + // Preliminary otions + xopts = $.extend({}, defaults, elopts, options), + locopts = opts_from_locale(xopts.language), + // Options priority: js args, data-attrs, locales, defaults + opts = $.extend({}, defaults, locopts, elopts, options); + if ($this.hasClass('input-daterange') || opts.inputs){ + $.extend(opts, { + inputs: opts.inputs || $this.find('input').toArray() + }); + data = new DateRangePicker(this, opts); + } + else { + data = new Datepicker(this, opts); + } + $this.data('datepicker', data); + } + if (typeof option === 'string' && typeof data[option] === 'function'){ + internal_return = data[option].apply(data, args); + } + }); + + if ( + internal_return === undefined || + internal_return instanceof Datepicker || + internal_return instanceof DateRangePicker + ) + return this; + + if (this.length > 1) + throw new Error('Using only allowed for the collection of a single element (' + option + ' function)'); + else + return internal_return; + }; + $.fn.datepicker = datepickerPlugin; + + var defaults = $.fn.datepicker.defaults = { + assumeNearbyYear: false, + autoclose: false, + beforeShowDay: $.noop, + beforeShowMonth: $.noop, + beforeShowYear: $.noop, + beforeShowDecade: $.noop, + beforeShowCentury: $.noop, + calendarWeeks: false, + clearBtn: false, + toggleActive: false, + daysOfWeekDisabled: [], + daysOfWeekHighlighted: [], + datesDisabled: [], + endDate: Infinity, + forceParse: true, + format: 'mm/dd/yyyy', + isInline: null, + keepEmptyValues: false, + keyboardNavigation: true, + language: 'en', + minViewMode: 0, + maxViewMode: 4, + multidate: false, + multidateSeparator: ',', + orientation: "auto", + rtl: false, + startDate: -Infinity, + startView: 0, + todayBtn: false, + todayHighlight: false, + updateViewDate: true, + weekStart: 0, + disableTouchKeyboard: false, + enableOnReadonly: true, + showOnFocus: true, + zIndexOffset: 10, + container: 'body', + immediateUpdates: false, + title: '', + templates: { + leftArrow: '«', + rightArrow: '»' + }, + showWeekDays: true + }; + var locale_opts = $.fn.datepicker.locale_opts = [ + 'format', + 'rtl', + 'weekStart' + ]; + $.fn.datepicker.Constructor = Datepicker; + var dates = $.fn.datepicker.dates = { + en: { + days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"], + daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], + daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"], + months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"], + monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], + today: "Today", + clear: "Clear", + titleFormat: "MM yyyy" + } + }; + + var DPGlobal = { + viewModes: [ + { + names: ['days', 'month'], + clsName: 'days', + e: 'changeMonth' + }, + { + names: ['months', 'year'], + clsName: 'months', + e: 'changeYear', + navStep: 1 + }, + { + names: ['years', 'decade'], + clsName: 'years', + e: 'changeDecade', + navStep: 10 + }, + { + names: ['decades', 'century'], + clsName: 'decades', + e: 'changeCentury', + navStep: 100 + }, + { + names: ['centuries', 'millennium'], + clsName: 'centuries', + e: 'changeMillennium', + navStep: 1000 + } + ], + validParts: /dd?|DD?|mm?|MM?|yy(?:yy)?/g, + nonpunctuation: /[^ -\/:-@\u5e74\u6708\u65e5\[-`{-~\t\n\r]+/g, + parseFormat: function(format){ + if (typeof format.toValue === 'function' && typeof format.toDisplay === 'function') + return format; + // IE treats \0 as a string end in inputs (truncating the value), + // so it's a bad format delimiter, anyway + var separators = format.replace(this.validParts, '\0').split('\0'), + parts = format.match(this.validParts); + if (!separators || !separators.length || !parts || parts.length === 0){ + throw new Error("Invalid date format."); + } + return {separators: separators, parts: parts}; + }, + parseDate: function(date, format, language, assumeNearby){ + if (!date) + return undefined; + if (date instanceof Date) + return date; + if (typeof format === 'string') + format = DPGlobal.parseFormat(format); + if (format.toValue) + return format.toValue(date, format, language); + var fn_map = { + d: 'moveDay', + m: 'moveMonth', + w: 'moveWeek', + y: 'moveYear' + }, + dateAliases = { + yesterday: '-1d', + today: '+0d', + tomorrow: '+1d' + }, + parts, part, dir, i, fn; + if (date in dateAliases){ + date = dateAliases[date]; + } + if (/^[\-+]\d+[dmwy]([\s,]+[\-+]\d+[dmwy])*$/i.test(date)){ + parts = date.match(/([\-+]\d+)([dmwy])/gi); + date = new Date(); + for (i=0; i < parts.length; i++){ + part = parts[i].match(/([\-+]\d+)([dmwy])/i); + dir = Number(part[1]); + fn = fn_map[part[2].toLowerCase()]; + date = Datepicker.prototype[fn](date, dir); + } + return Datepicker.prototype._zero_utc_time(date); + } + + parts = date && date.match(this.nonpunctuation) || []; + + function applyNearbyYear(year, threshold){ + if (threshold === true) + threshold = 10; + + // if year is 2 digits or less, than the user most likely is trying to get a recent century + if (year < 100){ + year += 2000; + // if the new year is more than threshold years in advance, use last century + if (year > ((new Date()).getFullYear()+threshold)){ + year -= 100; + } + } + + return year; + } + + var parsed = {}, + setters_order = ['yyyy', 'yy', 'M', 'MM', 'm', 'mm', 'd', 'dd'], + setters_map = { + yyyy: function(d,v){ + return d.setUTCFullYear(assumeNearby ? applyNearbyYear(v, assumeNearby) : v); + }, + m: function(d,v){ + if (isNaN(d)) + return d; + v -= 1; + while (v < 0) v += 12; + v %= 12; + d.setUTCMonth(v); + while (d.getUTCMonth() !== v) + d.setUTCDate(d.getUTCDate()-1); + return d; + }, + d: function(d,v){ + return d.setUTCDate(v); + } + }, + val, filtered; + setters_map['yy'] = setters_map['yyyy']; + setters_map['M'] = setters_map['MM'] = setters_map['mm'] = setters_map['m']; + setters_map['dd'] = setters_map['d']; + date = UTCToday(); + var fparts = format.parts.slice(); + // Remove noop parts + if (parts.length !== fparts.length){ + fparts = $(fparts).filter(function(i,p){ + return $.inArray(p, setters_order) !== -1; + }).toArray(); + } + // Process remainder + function match_part(){ + var m = this.slice(0, parts[i].length), + p = parts[i].slice(0, m.length); + return m.toLowerCase() === p.toLowerCase(); + } + if (parts.length === fparts.length){ + var cnt; + for (i=0, cnt = fparts.length; i < cnt; i++){ + val = parseInt(parts[i], 10); + part = fparts[i]; + if (isNaN(val)){ + switch (part){ + case 'MM': + filtered = $(dates[language].months).filter(match_part); + val = $.inArray(filtered[0], dates[language].months) + 1; + break; + case 'M': + filtered = $(dates[language].monthsShort).filter(match_part); + val = $.inArray(filtered[0], dates[language].monthsShort) + 1; + break; + } + } + parsed[part] = val; + } + var _date, s; + for (i=0; i < setters_order.length; i++){ + s = setters_order[i]; + if (s in parsed && !isNaN(parsed[s])){ + _date = new Date(date); + setters_map[s](_date, parsed[s]); + if (!isNaN(_date)) + date = _date; + } + } + } + return date; + }, + formatDate: function(date, format, language){ + if (!date) + return ''; + if (typeof format === 'string') + format = DPGlobal.parseFormat(format); + if (format.toDisplay) + return format.toDisplay(date, format, language); + var val = { + d: date.getUTCDate(), + D: dates[language].daysShort[date.getUTCDay()], + DD: dates[language].days[date.getUTCDay()], + m: date.getUTCMonth() + 1, + M: dates[language].monthsShort[date.getUTCMonth()], + MM: dates[language].months[date.getUTCMonth()], + yy: date.getUTCFullYear().toString().substring(2), + yyyy: date.getUTCFullYear() + }; + val.dd = (val.d < 10 ? '0' : '') + val.d; + val.mm = (val.m < 10 ? '0' : '') + val.m; + date = []; + var seps = $.extend([], format.separators); + for (var i=0, cnt = format.parts.length; i <= cnt; i++){ + if (seps.length) + date.push(seps.shift()); + date.push(val[format.parts[i]]); + } + return date.join(''); + }, + headTemplate: ''+ + ''+ + ''+ + ''+ + ''+ + ''+defaults.templates.leftArrow+''+ + ''+ + ''+defaults.templates.rightArrow+''+ + ''+ + '', + contTemplate: '', + footTemplate: ''+ + ''+ + ''+ + ''+ + ''+ + ''+ + ''+ + '' + }; + DPGlobal.template = '
'+ + '
'+ + ''+ + DPGlobal.headTemplate+ + ''+ + DPGlobal.footTemplate+ + '
'+ + '
'+ + '
'+ + ''+ + DPGlobal.headTemplate+ + DPGlobal.contTemplate+ + DPGlobal.footTemplate+ + '
'+ + '
'+ + '
'+ + ''+ + DPGlobal.headTemplate+ + DPGlobal.contTemplate+ + DPGlobal.footTemplate+ + '
'+ + '
'+ + '
'+ + ''+ + DPGlobal.headTemplate+ + DPGlobal.contTemplate+ + DPGlobal.footTemplate+ + '
'+ + '
'+ + '
'+ + ''+ + DPGlobal.headTemplate+ + DPGlobal.contTemplate+ + DPGlobal.footTemplate+ + '
'+ + '
'+ + '
'; + + $.fn.datepicker.DPGlobal = DPGlobal; + + + /* DATEPICKER NO CONFLICT + * =================== */ + + $.fn.datepicker.noConflict = function(){ + $.fn.datepicker = old; + return this; + }; + + /* DATEPICKER VERSION + * =================== */ + $.fn.datepicker.version = '1.10.1'; + + $.fn.datepicker.deprecated = function(msg){ + var console = window.console; + if (console && console.warn) { + console.warn('DEPRECATED: ' + msg); + } + }; + + + /* DATEPICKER DATA-API + * ================== */ + + $(document).on( + 'focus.datepicker.data-api click.datepicker.data-api', + '[data-provide="datepicker"]', + function(e){ + var $this = $(this); + if ($this.data('datepicker')) + return; + e.preventDefault(); + // component click requires us to explicitly show it + datepickerPlugin.call($this, 'show'); + } + ); + $(function(){ + datepickerPlugin.call($('[data-provide="datepicker-inline"]')); + }); + +})); diff --git a/npm/packs/bootstrap-daterangepicker/abp.resourcemapping.js b/npm/packs/bootstrap-daterangepicker/abp.resourcemapping.js index b82d1e94b3..48c3b20023 100644 --- a/npm/packs/bootstrap-daterangepicker/abp.resourcemapping.js +++ b/npm/packs/bootstrap-daterangepicker/abp.resourcemapping.js @@ -1,6 +1,6 @@ module.exports = { mappings: { "@node_modules/@abp/bootstrap-daterangepicker/src/daterangepicker.js": "@libs/bootstrap-daterangepicker/", - "@node_modules/bootstrap-daterangepicker/daterangepicker.css": "@libs/bootstrap-daterangepicker/", + "@node_modules/@abp/bootstrap-daterangepicker/src/daterangepicker.css": "@libs/bootstrap-daterangepicker/", } } \ No newline at end of file diff --git a/npm/packs/bootstrap-daterangepicker/package.json b/npm/packs/bootstrap-daterangepicker/package.json index f7ad3c8259..6493354edc 100644 --- a/npm/packs/bootstrap-daterangepicker/package.json +++ b/npm/packs/bootstrap-daterangepicker/package.json @@ -11,7 +11,8 @@ }, "dependencies": { "@abp/moment": "~10.7.0", - "bootstrap-daterangepicker": "^3.1.0" + "jquery": "~4.0.0", + "moment": "^2.30.1" }, "gitHead": "bb4ea17d5996f01889134c138d00b6c8f858a431", "homepage": "https://abp.io", diff --git a/npm/packs/bootstrap-daterangepicker/src/daterangepicker.css b/npm/packs/bootstrap-daterangepicker/src/daterangepicker.css new file mode 100644 index 0000000000..a96380496e --- /dev/null +++ b/npm/packs/bootstrap-daterangepicker/src/daterangepicker.css @@ -0,0 +1,410 @@ +.daterangepicker { + position: absolute; + color: inherit; + background-color: #fff; + border-radius: 4px; + border: 1px solid #ddd; + width: 278px; + max-width: none; + padding: 0; + margin-top: 7px; + top: 100px; + left: 20px; + z-index: 3001; + display: none; + font-family: arial; + font-size: 15px; + line-height: 1em; +} + +.daterangepicker:before, .daterangepicker:after { + position: absolute; + display: inline-block; + border-bottom-color: rgba(0, 0, 0, 0.2); + content: ''; +} + +.daterangepicker:before { + top: -7px; + border-right: 7px solid transparent; + border-left: 7px solid transparent; + border-bottom: 7px solid #ccc; +} + +.daterangepicker:after { + top: -6px; + border-right: 6px solid transparent; + border-bottom: 6px solid #fff; + border-left: 6px solid transparent; +} + +.daterangepicker.opensleft:before { + right: 9px; +} + +.daterangepicker.opensleft:after { + right: 10px; +} + +.daterangepicker.openscenter:before { + left: 0; + right: 0; + width: 0; + margin-left: auto; + margin-right: auto; +} + +.daterangepicker.openscenter:after { + left: 0; + right: 0; + width: 0; + margin-left: auto; + margin-right: auto; +} + +.daterangepicker.opensright:before { + left: 9px; +} + +.daterangepicker.opensright:after { + left: 10px; +} + +.daterangepicker.drop-up { + margin-top: -7px; +} + +.daterangepicker.drop-up:before { + top: initial; + bottom: -7px; + border-bottom: initial; + border-top: 7px solid #ccc; +} + +.daterangepicker.drop-up:after { + top: initial; + bottom: -6px; + border-bottom: initial; + border-top: 6px solid #fff; +} + +.daterangepicker.single .daterangepicker .ranges, .daterangepicker.single .drp-calendar { + float: none; +} + +.daterangepicker.single .drp-selected { + display: none; +} + +.daterangepicker.show-calendar .drp-calendar { + display: block; +} + +.daterangepicker.show-calendar .drp-buttons { + display: block; +} + +.daterangepicker.auto-apply .drp-buttons { + display: none; +} + +.daterangepicker .drp-calendar { + display: none; + max-width: 270px; +} + +.daterangepicker .drp-calendar.left { + padding: 8px 0 8px 8px; +} + +.daterangepicker .drp-calendar.right { + padding: 8px; +} + +.daterangepicker .drp-calendar.single .calendar-table { + border: none; +} + +.daterangepicker .calendar-table .next span, .daterangepicker .calendar-table .prev span { + color: #fff; + border: solid black; + border-width: 0 2px 2px 0; + border-radius: 0; + display: inline-block; + padding: 3px; +} + +.daterangepicker .calendar-table .next span { + transform: rotate(-45deg); + -webkit-transform: rotate(-45deg); +} + +.daterangepicker .calendar-table .prev span { + transform: rotate(135deg); + -webkit-transform: rotate(135deg); +} + +.daterangepicker .calendar-table th, .daterangepicker .calendar-table td { + white-space: nowrap; + text-align: center; + vertical-align: middle; + min-width: 32px; + width: 32px; + height: 24px; + line-height: 24px; + font-size: 12px; + border-radius: 4px; + border: 1px solid transparent; + white-space: nowrap; + cursor: pointer; +} + +.daterangepicker .calendar-table { + border: 1px solid #fff; + border-radius: 4px; + background-color: #fff; +} + +.daterangepicker .calendar-table table { + width: 100%; + margin: 0; + border-spacing: 0; + border-collapse: collapse; +} + +.daterangepicker td.available:hover, .daterangepicker th.available:hover { + background-color: #eee; + border-color: transparent; + color: inherit; +} + +.daterangepicker td.week, .daterangepicker th.week { + font-size: 80%; + color: #ccc; +} + +.daterangepicker td.off, .daterangepicker td.off.in-range, .daterangepicker td.off.start-date, .daterangepicker td.off.end-date { + background-color: #fff; + border-color: transparent; + color: #999; +} + +.daterangepicker td.in-range { + background-color: #ebf4f8; + border-color: transparent; + color: #000; + border-radius: 0; +} + +.daterangepicker td.start-date { + border-radius: 4px 0 0 4px; +} + +.daterangepicker td.end-date { + border-radius: 0 4px 4px 0; +} + +.daterangepicker td.start-date.end-date { + border-radius: 4px; +} + +.daterangepicker td.active, .daterangepicker td.active:hover { + background-color: #357ebd; + border-color: transparent; + color: #fff; +} + +.daterangepicker th.month { + width: auto; +} + +.daterangepicker td.disabled, .daterangepicker option.disabled { + color: #999; + cursor: not-allowed; + text-decoration: line-through; +} + +.daterangepicker select.monthselect, .daterangepicker select.yearselect { + font-size: 12px; + padding: 1px; + height: auto; + margin: 0; + cursor: default; +} + +.daterangepicker select.monthselect { + margin-right: 2%; + width: 56%; +} + +.daterangepicker select.yearselect { + width: 40%; +} + +.daterangepicker select.hourselect, .daterangepicker select.minuteselect, .daterangepicker select.secondselect, .daterangepicker select.ampmselect { + width: 50px; + margin: 0 auto; + background: #eee; + border: 1px solid #eee; + padding: 2px; + outline: 0; + font-size: 12px; +} + +.daterangepicker .calendar-time { + text-align: center; + margin: 4px auto 0 auto; + line-height: 30px; + position: relative; +} + +.daterangepicker .calendar-time select.disabled { + color: #ccc; + cursor: not-allowed; +} + +.daterangepicker .drp-buttons { + clear: both; + text-align: right; + padding: 8px; + border-top: 1px solid #ddd; + display: none; + line-height: 12px; + vertical-align: middle; +} + +.daterangepicker .drp-selected { + display: inline-block; + font-size: 12px; + padding-right: 8px; +} + +.daterangepicker .drp-buttons .btn { + margin-left: 8px; + font-size: 12px; + font-weight: bold; + padding: 4px 8px; +} + +.daterangepicker.show-ranges.single.rtl .drp-calendar.left { + border-right: 1px solid #ddd; +} + +.daterangepicker.show-ranges.single.ltr .drp-calendar.left { + border-left: 1px solid #ddd; +} + +.daterangepicker.show-ranges.rtl .drp-calendar.right { + border-right: 1px solid #ddd; +} + +.daterangepicker.show-ranges.ltr .drp-calendar.left { + border-left: 1px solid #ddd; +} + +.daterangepicker .ranges { + float: none; + text-align: left; + margin: 0; +} + +.daterangepicker.show-calendar .ranges { + margin-top: 8px; +} + +.daterangepicker .ranges ul { + list-style: none; + margin: 0 auto; + padding: 0; + width: 100%; +} + +.daterangepicker .ranges li { + font-size: 12px; + padding: 8px 12px; + cursor: pointer; +} + +.daterangepicker .ranges li:hover { + background-color: #eee; +} + +.daterangepicker .ranges li.active { + background-color: #08c; + color: #fff; +} + +/* Larger Screen Styling */ +@media (min-width: 564px) { + .daterangepicker { + width: auto; + } + + .daterangepicker .ranges ul { + width: 140px; + } + + .daterangepicker.single .ranges ul { + width: 100%; + } + + .daterangepicker.single .drp-calendar.left { + clear: none; + } + + .daterangepicker.single .ranges, .daterangepicker.single .drp-calendar { + float: left; + } + + .daterangepicker { + direction: ltr; + text-align: left; + } + + .daterangepicker .drp-calendar.left { + clear: left; + margin-right: 0; + } + + .daterangepicker .drp-calendar.left .calendar-table { + border-right: none; + border-top-right-radius: 0; + border-bottom-right-radius: 0; + } + + .daterangepicker .drp-calendar.right { + margin-left: 0; + } + + .daterangepicker .drp-calendar.right .calendar-table { + border-left: none; + border-top-left-radius: 0; + border-bottom-left-radius: 0; + } + + .daterangepicker .drp-calendar.left .calendar-table { + padding-right: 8px; + } + + .daterangepicker .ranges, .daterangepicker .drp-calendar { + float: left; + } +} + +@media (min-width: 730px) { + .daterangepicker .ranges { + width: auto; + } + + .daterangepicker .ranges { + float: left; + } + + .daterangepicker.rtl .ranges { + float: right; + } + + .daterangepicker .drp-calendar.left { + clear: none !important; + } +} diff --git a/npm/packs/bootstrap-daterangepicker/src/daterangepicker.js b/npm/packs/bootstrap-daterangepicker/src/daterangepicker.js index 0ef46e765f..c5d366d803 100644 --- a/npm/packs/bootstrap-daterangepicker/src/daterangepicker.js +++ b/npm/packs/bootstrap-daterangepicker/src/daterangepicker.js @@ -4,6 +4,8 @@ * @copyright: Copyright (c) 2012-2019 Dan Grossman. All rights reserved. * @license: Licensed under the MIT license. See http://www.opensource.org/licenses/mit-license.php * @website: http://www.daterangepicker.com/ +* Patched copy: autoApply works together with timePicker, predefined ranges start at the beginning of the day, +* and Function.prototype.bind is used instead of the jQuery.proxy API deprecated in jQuery 4. */ // Following the UMD template https://github.com/umdjs/umd/blob/master/templates/returnExportsGlobal.js (function (root, factory) { diff --git a/npm/packs/docs/package.json b/npm/packs/docs/package.json index 7a356d9869..a6c29895b9 100644 --- a/npm/packs/docs/package.json +++ b/npm/packs/docs/package.json @@ -7,7 +7,6 @@ "dependencies": { "@abp/anchor-js": "~10.7.0", "@abp/clipboard": "~10.7.0", - "@abp/malihu-custom-scrollbar-plugin": "~10.7.0", "@abp/popper.js": "~10.7.0", "@abp/prismjs": "~10.7.0" }, diff --git a/npm/packs/jquery-form/abp.resourcemapping.js b/npm/packs/jquery-form/abp.resourcemapping.js deleted file mode 100644 index 4ec5565b0c..0000000000 --- a/npm/packs/jquery-form/abp.resourcemapping.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = { - mappings: { - "@node_modules/@abp/jquery-form/src/jquery.form.min.js": "@libs/jquery-form/" - } -} \ No newline at end of file diff --git a/npm/packs/jquery-form/package.json b/npm/packs/jquery-form/package.json deleted file mode 100644 index 4ad75ac76d..0000000000 --- a/npm/packs/jquery-form/package.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "version": "10.7.0", - "name": "@abp/jquery-form", - "repository": { - "type": "git", - "url": "https://github.com/abpframework/abp.git", - "directory": "npm/packs/jquery-form" - }, - "publishConfig": { - "access": "public" - }, - "dependencies": { - "@abp/jquery": "~10.7.0", - "jquery-form": "^4.3.0" - }, - "gitHead": "bb4ea17d5996f01889134c138d00b6c8f858a431", - "homepage": "https://abp.io", - "license": "LGPL-3.0", - "keywords": [ - "aspnetcore", - "boilerplate", - "framework", - "web", - "best-practices", - "angular", - "maui", - "blazor", - "mvc", - "csharp", - "webapp" - ] -} diff --git a/npm/packs/jquery-form/src/jquery.form.min.js b/npm/packs/jquery-form/src/jquery.form.min.js deleted file mode 100644 index c794a23e13..0000000000 --- a/npm/packs/jquery-form/src/jquery.form.min.js +++ /dev/null @@ -1,22 +0,0 @@ -/*! - * jQuery Form Plugin - * version: 4.3.0 - * Requires jQuery v1.7.2 or later - * Project repository: https://github.com/jquery-form/form - - * Copyright 2017 Kevin Morris - * Copyright 2006 M. Alsup - - * Dual licensed under the LGPL-2.1+ or MIT licenses - * https://github.com/jquery-form/form#license - - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - */ -!function(e){"function"==typeof define&&define.amd?define(["jquery"],e):"object"==typeof module&&module.exports?module.exports=function(t,r){return void 0===r&&(r="undefined"!=typeof window?require("jquery"):require("jquery")(t)),e(r),r}:e(jQuery)}(function(e){"use strict";var t=/\r?\n/g,r={};r.fileapi=void 0!==e('').get(0).files,r.formdata=void 0!==window.FormData;var a=!!e.fn.prop;function n(t){var r=t.data;t.isDefaultPrevented()||(t.preventDefault(),e(t.target).closest("form").ajaxSubmit(r))}function i(t){var r=t.target,a=e(r);if(!a.is("[type=submit],[type=image]")){var n=a.closest("[type=submit]");if(0===n.length)return;r=n[0]}var i=r.form;if(i.clk=r,"image"===r.type)if(void 0!==t.offsetX)i.clk_x=t.offsetX,i.clk_y=t.offsetY;else if("function"==typeof e.fn.offset){var o=a.offset();i.clk_x=t.pageX-o.left,i.clk_y=t.pageY-o.top}else i.clk_x=t.pageX-r.offsetLeft,i.clk_y=t.pageY-r.offsetTop;setTimeout(function(){i.clk=i.clk_x=i.clk_y=null},100)}function o(){if(e.fn.ajaxSubmit.debug){var t="[jquery.form] "+Array.prototype.join.call(arguments,"");window.console&&window.console.log?window.console.log(t):window.opera&&window.opera.postError&&window.opera.postError(t)}}e.fn.attr2=function(){if(!a)return this.attr.apply(this,arguments);var e=this.prop.apply(this,arguments);return e&&e.jquery||"string"==typeof e?e:this.attr.apply(this,arguments)},e.fn.ajaxSubmit=function(t,n,i,s){if(!this.length)return o("ajaxSubmit: skipping submit process - no element selected"),this;var u,c,l,f,d=this;"function"==typeof t?t={success:t}:"string"==typeof t||!1===t&&arguments.length>0?(t={url:t,data:n,dataType:i},"function"==typeof s&&(t.success=s)):void 0===t&&(t={}),u=t.method||t.type||this.attr2("method"),(l=(l="string"==typeof(c=t.url||this.attr2("action"))?e.trim(c):"")||window.location.href||"")&&(l=(l.match(/^([^#]+)/)||[])[1]),f=/(MSIE|Trident)/.test(navigator.userAgent||"")&&/^https/i.test(window.location.href||"")?"javascript:false":"about:blank",t=e.extend(!0,{url:l,success:e.ajaxSettings.success,type:u||e.ajaxSettings.type,iframeSrc:f},t);var m={};if(this.trigger("form-pre-serialize",[this,t,m]),m.veto)return o("ajaxSubmit: submit vetoed via form-pre-serialize trigger"),this;if(t.beforeSerialize&&!1===t.beforeSerialize(this,t))return o("ajaxSubmit: submit aborted via beforeSerialize callback"),this;var p=t.traditional;void 0===p&&(p=e.ajaxSettings.traditional);var h,v=[],g=this.formToArray(t.semantic,v,t.filtering);if(t.data){var x=e.isFunction(t.data)?t.data(g):t.data;t.extraData=x,h=e.param(x,p)}if(t.beforeSubmit&&!1===t.beforeSubmit(g,this,t))return o("ajaxSubmit: submit aborted via beforeSubmit callback"),this;if(this.trigger("form-submit-validate",[g,this,t,m]),m.veto)return o("ajaxSubmit: submit vetoed via form-submit-validate trigger"),this;var y=e.param(g,p);h&&(y=y?y+"&"+h:h),"GET"===t.type.toUpperCase()?(t.url+=(t.url.indexOf("?")>=0?"&":"?")+y,t.data=null):t.data=y;var b=[];if(t.resetForm&&b.push(function(){d.resetForm()}),t.clearForm&&b.push(function(){d.clearForm(t.includeHidden)}),!t.dataType&&t.target){var T=t.success||function(){};b.push(function(r,a,n){var i=arguments,o=t.replaceTarget?"replaceWith":"html";"html"==o&&(r=e.parseHTML(e("
").text(r).html())),e(t.target)[o](r).each(function(){T.apply(this,i)})})}else t.success&&(e.isArray(t.success)?e.merge(b,t.success):b.push(t.success));if(t.success=function(e,r,a){for(var n=t.context||this,i=0,o=b.length;i0,k="multipart/form-data",D=d.attr("enctype")===k||d.attr("encoding")===k,A=r.fileapi&&r.formdata;o("fileAPI :"+A);var F,L=(S||D)&&!A;!1!==t.iframe&&(t.iframe||L)?t.closeKeepAlive?e.get(t.closeKeepAlive,function(){F=M(g)}):F=M(g):F=(S||D)&&A?function(r){for(var a=new FormData,n=0;n',j)).css({position:"absolute",top:"-1000px",left:"-1000px"}),m=f[0],p={aborted:0,responseText:null,responseXML:null,status:0,statusText:"n/a",getAllResponseHeaders:function(){},getResponseHeader:function(){},setRequestHeader:function(){},abort:function(t){var r="timeout"===t?"timeout":"aborted";o("aborting upload... "+r),this.aborted=1;try{m.contentWindow.document.execCommand&&m.contentWindow.document.execCommand("Stop")}catch(e){}f.attr("src",s.iframeSrc),p.error=r,s.error&&s.error.call(s.context,p,r,t),c&&e.event.trigger("ajaxError",[p,s,r]),s.complete&&s.complete.call(s.context,p,r)}},(c=s.global)&&0==e.active++&&e.event.trigger("ajaxStart"),c&&e.event.trigger("ajaxSend",[p,s]),s.beforeSend&&!1===s.beforeSend.call(s.context,p,s))return s.global&&e.active--,T.reject(),T;if(p.aborted)return T.reject(),T;(h=b.clk)&&(g=h.name)&&!h.disabled&&(s.extraData=s.extraData||{},s.extraData[g]=h.value,"image"===h.type&&(s.extraData[g+".x"]=b.clk_x,s.extraData[g+".y"]=b.clk_y));var S=1,k=2;function D(e){var t=null;try{e.contentWindow&&(t=e.contentWindow.document)}catch(e){o("cannot get iframe.contentWindow document: "+e)}if(t)return t;try{t=e.contentDocument?e.contentDocument:e.document}catch(r){o("cannot get iframe.contentDocument: "+r),t=e.document}return t}var A=e("meta[name=csrf-token]").attr("content"),F=e("meta[name=csrf-param]").attr("content");function L(){var t=d.attr2("target"),r=d.attr2("action"),a=d.attr("enctype")||d.attr("encoding")||"multipart/form-data";b.setAttribute("target",l),u&&!/post/i.test(u)||b.setAttribute("method","POST"),r!==s.url&&b.setAttribute("action",s.url),s.skipEncodingOverride||u&&!/post/i.test(u)||d.attr({encoding:"multipart/form-data",enctype:"multipart/form-data"}),s.timeout&&(y=setTimeout(function(){x=!0,C(S)},s.timeout));var n=[];try{if(s.extraData)for(var i in s.extraData)s.extraData.hasOwnProperty(i)&&(e.isPlainObject(s.extraData[i])&&s.extraData[i].hasOwnProperty("name")&&s.extraData[i].hasOwnProperty("value")?n.push(e('',j).val(s.extraData[i].value).appendTo(b)[0]):n.push(e('',j).val(s.extraData[i]).appendTo(b)[0]));s.iframeTarget||f.appendTo(w),m.attachEvent?m.attachEvent("onload",C):m.addEventListener("load",C,!1),setTimeout(function e(){try{var t=D(m).readyState;o("state = "+t),t&&"uninitialized"===t.toLowerCase()&&setTimeout(e,50)}catch(e){o("Server abort: ",e," (",e.name,")"),C(k),y&&clearTimeout(y),y=void 0}},15);try{b.submit()}catch(e){document.createElement("form").submit.apply(b)}}finally{b.setAttribute("action",r),b.setAttribute("enctype",a),t?b.setAttribute("target",t):d.removeAttr("target"),e(n).remove()}}F&&A&&(s.extraData=s.extraData||{},s.extraData[F]=A),s.forceSync?L():setTimeout(L,10);var E,M,O,X=50;function C(t){if(!p.aborted&&!O){if((M=D(m))||(o("cannot access response document"),t=k),t===S&&p)return p.abort("timeout"),void T.reject(p,"timeout");if(t===k&&p)return p.abort("server abort"),void T.reject(p,"error","server abort");if(M&&M.location.href!==s.iframeSrc||x){m.detachEvent?m.detachEvent("onload",C):m.removeEventListener("load",C,!1);var r,a="success";try{if(x)throw"timeout";var n="xml"===s.dataType||M.XMLDocument||e.isXMLDoc(M);if(o("isXml="+n),!n&&window.opera&&(null===M.body||!M.body.innerHTML)&&--X)return o("requeing onLoad callback, DOM not available"),void setTimeout(C,250);var i=M.body?M.body:M.documentElement;p.responseText=i?i.innerHTML:null,p.responseXML=M.XMLDocument?M.XMLDocument:M,n&&(s.dataType="xml"),p.getResponseHeader=function(e){return{"content-type":s.dataType}[e.toLowerCase()]},i&&(p.status=Number(i.getAttribute("status"))||p.status,p.statusText=i.getAttribute("statusText")||p.statusText);var u=(s.dataType||"").toLowerCase(),l=/(json|script|text)/.test(u);if(l||s.textarea){var d=M.getElementsByTagName("textarea")[0];if(d)p.responseText=d.value,p.status=Number(d.getAttribute("status"))||p.status,p.statusText=d.getAttribute("statusText")||p.statusText;else if(l){var h=M.getElementsByTagName("pre")[0],v=M.getElementsByTagName("body")[0];h?p.responseText=h.textContent?h.textContent:h.innerText:v&&(p.responseText=v.textContent?v.textContent:v.innerText)}}else"xml"===u&&!p.responseXML&&p.responseText&&(p.responseXML=q(p.responseText));try{E=_(p,u,s)}catch(e){a="parsererror",p.error=r=e||a}}catch(e){o("error caught: ",e),a="error",p.error=r=e||a}p.aborted&&(o("upload aborted"),a=null),p.status&&(a=p.status>=200&&p.status<300||304===p.status?"success":"error"),"success"===a?(s.success&&s.success.call(s.context,E,"success",p),T.resolve(p.responseText,"success",p),c&&e.event.trigger("ajaxSuccess",[p,s])):a&&(void 0===r&&(r=p.statusText),s.error&&s.error.call(s.context,p,a,r),T.reject(p,"error",r),c&&e.event.trigger("ajaxError",[p,s,r])),c&&e.event.trigger("ajaxComplete",[p,s]),c&&!--e.active&&e.event.trigger("ajaxStop"),s.complete&&s.complete.call(s.context,p,a),O=!0,s.timeout&&clearTimeout(y),setTimeout(function(){s.iframeTarget?f.attr("src",s.iframeSrc):f.remove(),p.responseXML=null},100)}}}var q=e.parseXML||function(e,t){return window.ActiveXObject?((t=new ActiveXObject("Microsoft.XMLDOM")).async="false",t.loadXML(e)):t=(new DOMParser).parseFromString(e,"text/xml"),t&&t.documentElement&&"parsererror"!==t.documentElement.nodeName?t:null},N=e.parseJSON||function(e){return window.console.error("jquery.parseJSON is undefined"),null},_=function(t,r,a){var n=t.getResponseHeader("content-type")||"",i=("xml"===r||!r)&&n.indexOf("xml")>=0,o=i?t.responseXML:t.responseText;return i&&"parsererror"===o.documentElement.nodeName&&e.error&&e.error("parsererror"),a&&a.dataFilter&&(o=a.dataFilter(o,r)),"string"==typeof o&&(("json"===r||!r)&&n.indexOf("json")>=0?o=N(o):("script"===r||!r)&&n.indexOf("javascript")>=0&&e.globalEval(o)),o};return T}},e.fn.ajaxForm=function(t,r,a,s){if(("string"==typeof t||!1===t&&arguments.length>0)&&(t={url:t,data:r,dataType:a},"function"==typeof s&&(t.success=s)),(t=t||{}).delegation=t.delegation&&e.isFunction(e.fn.on),!t.delegation&&0===this.length){var u={s:this.selector,c:this.context};return!e.isReady&&u.s?(o("DOM not ready, queuing ajaxForm"),e(function(){e(u.s,u.c).ajaxForm(t)}),this):(o("terminating; zero elements found by selector"+(e.isReady?"":" (DOM not ready)")),this)}return t.delegation?(e(document).off("submit.form-plugin",this.selector,n).off("click.form-plugin",this.selector,i).on("submit.form-plugin",this.selector,t,n).on("click.form-plugin",this.selector,t,i),this):(t.beforeFormUnbind&&t.beforeFormUnbind(this,t),this.ajaxFormUnbind().on("submit.form-plugin",t,n).on("click.form-plugin",t,i))},e.fn.ajaxFormUnbind=function(){return this.off("submit.form-plugin click.form-plugin")},e.fn.formToArray=function(t,a,n){var i=[];if(0===this.length)return i;var o,s,u,c,l,f,d,m,p=this[0],h=this.attr("id"),v=t||void 0===p.elements?p.getElementsByTagName("*"):p.elements;if(v&&(v=e.makeArray(v)),h&&(t||/(Edge|Trident)\//.test(navigator.userAgent))&&(o=e(':input[form="'+h+'"]').get()).length&&(v=(v||[]).concat(o)),!v||!v.length)return i;for(e.isFunction(n)&&(v=e.map(v,n)),s=0,d=v.length;s?@\[\\\]^`{|}~])/g, "\\$1"); + } + + function getModelPrefix(fieldName) { + return fieldName.substr(0, fieldName.lastIndexOf(".") + 1); + } + + function appendModelPrefix(value, prefix) { + if (value.indexOf("*.") === 0) { + value = value.replace("*.", prefix); + } + return value; + } + + function onError(error, inputElement) { // 'this' is the form element + var container = $(this).find("[data-valmsg-for='" + escapeAttributeValue(inputElement[0].name) + "']"), + replaceAttrValue = container.attr("data-valmsg-replace"), + replace = replaceAttrValue ? JSON.parse(replaceAttrValue) !== false : null; + + container.removeClass("field-validation-valid").addClass("field-validation-error"); + error.data("unobtrusiveContainer", container); + + if (replace) { + container.empty(); + error.removeClass("input-validation-error").appendTo(container); + } + else { + error.hide(); + } + } + + function onErrors(event, validator) { // 'this' is the form element + var container = $(this).find("[data-valmsg-summary=true]"), + list = container.find("ul"); + + if (list && list.length && validator.errorList.length) { + list.empty(); + container.addClass("validation-summary-errors").removeClass("validation-summary-valid"); + + $.each(validator.errorList, function () { + $("
  • ").html(this.message).appendTo(list); + }); + } + } + + function onSuccess(error) { // 'this' is the form element + var container = error.data("unobtrusiveContainer"); + + if (container) { + var replaceAttrValue = container.attr("data-valmsg-replace"), + replace = replaceAttrValue ? JSON.parse(replaceAttrValue) : null; + + container.addClass("field-validation-valid").removeClass("field-validation-error"); + error.removeData("unobtrusiveContainer"); + + if (replace) { + container.empty(); + } + } + } + + function onReset(event) { // 'this' is the form element + var $form = $(this), + key = '__jquery_unobtrusive_validation_form_reset'; + if ($form.data(key)) { + return; + } + // Set a flag that indicates we're currently resetting the form. + $form.data(key, true); + try { + $form.data("validator").resetForm(); + } finally { + $form.removeData(key); + } + + $form.find(".validation-summary-errors") + .addClass("validation-summary-valid") + .removeClass("validation-summary-errors"); + $form.find(".field-validation-error") + .addClass("field-validation-valid") + .removeClass("field-validation-error") + .removeData("unobtrusiveContainer") + .find(">*") // If we were using valmsg-replace, get the underlying error + .removeData("unobtrusiveContainer"); + } + + function validationInfo(form) { + var $form = $(form), + result = $form.data(data_validation), + onResetProxy = onReset.bind(form), + defaultOptions = $jQval.unobtrusive.options || {}, + execInContext = function (name, args) { + var func = defaultOptions[name]; + func && typeof func === "function" && func.apply(form, args); + }; + + if (!result) { + result = { + options: { // options structure passed to jQuery Validate's validate() method + errorClass: defaultOptions.errorClass || "input-validation-error", + errorElement: defaultOptions.errorElement || "span", + errorPlacement: function () { + onError.apply(form, arguments); + execInContext("errorPlacement", arguments); + }, + invalidHandler: function () { + onErrors.apply(form, arguments); + execInContext("invalidHandler", arguments); + }, + messages: {}, + rules: {}, + success: function () { + onSuccess.apply(form, arguments); + execInContext("success", arguments); + } + }, + attachValidation: function () { + $form + .off("reset." + data_validation) + .on("reset." + data_validation, onResetProxy) + .validate(this.options); + }, + validate: function () { // a validation function that is called by unobtrusive Ajax + $form.validate(); + return $form.valid(); + } + }; + $form.data(data_validation, result); + } + + return result; + } + + $jQval.unobtrusive = { + adapters: [], + + parseElement: function (element, skipAttach) { + /// + /// Parses a single HTML element for unobtrusive validation attributes. + /// + /// The HTML element to be parsed. + /// [Optional] true to skip attaching the + /// validation to the form. If parsing just this single element, you should specify true. + /// If parsing several elements, you should specify false, and manually attach the validation + /// to the form when you are finished. The default is false. + var $element = $(element), + form = $element.parents("form")[0], + valInfo, rules, messages; + + if (!form) { // Cannot do client-side validation without a form + return; + } + + valInfo = validationInfo(form); + valInfo.options.rules[element.name] = rules = {}; + valInfo.options.messages[element.name] = messages = {}; + + $.each(this.adapters, function () { + var prefix = "data-val-" + this.name, + message = $element.attr(prefix), + paramValues = {}; + + if (message !== undefined) { // Compare against undefined, because an empty message is legal (and falsy) + prefix += "-"; + + $.each(this.params, function () { + paramValues[this] = $element.attr(prefix + this); + }); + + this.adapt({ + element: element, + form: form, + message: message, + params: paramValues, + rules: rules, + messages: messages + }); + } + }); + + $.extend(rules, { "__dummy__": true }); + + if (!skipAttach) { + valInfo.attachValidation(); + } + }, + + parse: function (selector) { + /// + /// Parses all the HTML elements in the specified selector. It looks for input elements decorated + /// with the [data-val=true] attribute value and enables validation according to the data-val-* + /// attribute values. + /// + /// Any valid jQuery selector. + + // $forms includes all forms in selector's DOM hierarchy (parent, children and self) that have at least one + // element with data-val=true + var $selector = $(selector), + $forms = $selector.parents() + .addBack() + .filter("form") + .add($selector.find("form")) + .has("[data-val=true]"); + + $selector.find("[data-val=true]").each(function () { + $jQval.unobtrusive.parseElement(this, true); + }); + + $forms.each(function () { + var info = validationInfo(this); + if (info) { + info.attachValidation(); + } + }); + } + }; + + adapters = $jQval.unobtrusive.adapters; + + adapters.add = function (adapterName, params, fn) { + /// Adds a new adapter to convert unobtrusive HTML into a jQuery Validate validation. + /// The name of the adapter to be added. This matches the name used + /// in the data-val-nnnn HTML attribute (where nnnn is the adapter name). + /// [Optional] An array of parameter names (strings) that will + /// be extracted from the data-val-nnnn-mmmm HTML attributes (where nnnn is the adapter name, and + /// mmmm is the parameter name). + /// The function to call, which adapts the values from the HTML + /// attributes into jQuery Validate rules and/or messages. + /// + if (!fn) { // Called with no params, just a function + fn = params; + params = []; + } + this.push({ name: adapterName, params: params, adapt: fn }); + return this; + }; + + adapters.addBool = function (adapterName, ruleName) { + /// Adds a new adapter to convert unobtrusive HTML into a jQuery Validate validation, where + /// the jQuery Validate validation rule has no parameter values. + /// The name of the adapter to be added. This matches the name used + /// in the data-val-nnnn HTML attribute (where nnnn is the adapter name). + /// [Optional] The name of the jQuery Validate rule. If not provided, the value + /// of adapterName will be used instead. + /// + return this.add(adapterName, function (options) { + setValidationValues(options, ruleName || adapterName, true); + }); + }; + + adapters.addMinMax = function (adapterName, minRuleName, maxRuleName, minMaxRuleName, minAttribute, maxAttribute) { + /// Adds a new adapter to convert unobtrusive HTML into a jQuery Validate validation, where + /// the jQuery Validate validation has three potential rules (one for min-only, one for max-only, and + /// one for min-and-max). The HTML parameters are expected to be named -min and -max. + /// The name of the adapter to be added. This matches the name used + /// in the data-val-nnnn HTML attribute (where nnnn is the adapter name). + /// The name of the jQuery Validate rule to be used when you only + /// have a minimum value. + /// The name of the jQuery Validate rule to be used when you only + /// have a maximum value. + /// The name of the jQuery Validate rule to be used when you + /// have both a minimum and maximum value. + /// [Optional] The name of the HTML attribute that + /// contains the minimum value. The default is "min". + /// [Optional] The name of the HTML attribute that + /// contains the maximum value. The default is "max". + /// + return this.add(adapterName, [minAttribute || "min", maxAttribute || "max"], function (options) { + var min = options.params.min, + max = options.params.max; + + if (min && max) { + setValidationValues(options, minMaxRuleName, [min, max]); + } + else if (min) { + setValidationValues(options, minRuleName, min); + } + else if (max) { + setValidationValues(options, maxRuleName, max); + } + }); + }; + + adapters.addSingleVal = function (adapterName, attribute, ruleName) { + /// Adds a new adapter to convert unobtrusive HTML into a jQuery Validate validation, where + /// the jQuery Validate validation rule has a single value. + /// The name of the adapter to be added. This matches the name used + /// in the data-val-nnnn HTML attribute(where nnnn is the adapter name). + /// [Optional] The name of the HTML attribute that contains the value. + /// The default is "val". + /// [Optional] The name of the jQuery Validate rule. If not provided, the value + /// of adapterName will be used instead. + /// + return this.add(adapterName, [attribute || "val"], function (options) { + setValidationValues(options, ruleName || adapterName, options.params[attribute]); + }); + }; + + $jQval.addMethod("__dummy__", function (value, element, params) { + return true; + }); + + $jQval.addMethod("regex", function (value, element, params) { + var match; + if (this.optional(element)) { + return true; + } + + match = new RegExp(params).exec(value); + return (match && (match.index === 0) && (match[0].length === value.length)); + }); + + $jQval.addMethod("nonalphamin", function (value, element, nonalphamin) { + var match; + if (nonalphamin) { + match = value.match(/\W/g); + match = match && match.length >= nonalphamin; + } + return match; + }); + + if ($jQval.methods.extension) { + adapters.addSingleVal("accept", "mimtype"); + adapters.addSingleVal("extension", "extension"); + } else { + // for backward compatibility, when the 'extension' validation method does not exist, such as with versions + // of JQuery Validation plugin prior to 1.10, we should use the 'accept' method for + // validating the extension, and ignore mime-type validations as they are not supported. + adapters.addSingleVal("extension", "extension", "accept"); + } + + adapters.addSingleVal("regex", "pattern"); + adapters.addBool("creditcard").addBool("date").addBool("digits").addBool("email").addBool("number").addBool("url"); + adapters.addMinMax("length", "minlength", "maxlength", "rangelength").addMinMax("range", "min", "max", "range"); + adapters.addMinMax("minlength", "minlength").addMinMax("maxlength", "minlength", "maxlength"); + adapters.add("equalto", ["other"], function (options) { + var prefix = getModelPrefix(options.element.name), + other = options.params.other, + fullOtherName = appendModelPrefix(other, prefix), + element = $(options.form).find(":input").filter("[name='" + escapeAttributeValue(fullOtherName) + "']")[0]; + + setValidationValues(options, "equalTo", element); + }); + adapters.add("required", function (options) { + // jQuery Validate equates "required" with "mandatory" for checkbox elements + if (options.element.tagName.toUpperCase() !== "INPUT" || options.element.type.toUpperCase() !== "CHECKBOX") { + setValidationValues(options, "required", true); + } + }); + adapters.add("remote", ["url", "type", "additionalfields"], function (options) { + var value = { + url: options.params.url, + type: options.params.type || "GET", + data: {} + }, + prefix = getModelPrefix(options.element.name); + + $.each(splitAndTrim(options.params.additionalfields || options.element.name), function (i, fieldName) { + var paramName = appendModelPrefix(fieldName, prefix); + value.data[paramName] = function () { + var field = $(options.form).find(":input").filter("[name='" + escapeAttributeValue(paramName) + "']"); + // For checkboxes and radio buttons, only pick up values from checked fields. + if (field.is(":checkbox")) { + return field.filter(":checked").val() || field.filter(":hidden").val() || ''; + } + else if (field.is(":radio")) { + return field.filter(":checked").val() || ''; + } + return field.val(); + }; + }); + + setValidationValues(options, "remote", value); + }); + adapters.add("password", ["min", "nonalphamin", "regex"], function (options) { + if (options.params.min) { + setValidationValues(options, "minlength", options.params.min); + } + if (options.params.nonalphamin) { + setValidationValues(options, "nonalphamin", options.params.nonalphamin); + } + if (options.params.regex) { + setValidationValues(options, "regex", options.params.regex); + } + }); + adapters.add("fileextensions", ["extensions"], function (options) { + setValidationValues(options, "extension", options.params.extensions); + }); + + $(function () { + $jQval.unobtrusive.parse(document); + }); + + return $jQval.unobtrusive; +})); diff --git a/npm/packs/malihu-custom-scrollbar-plugin/README.md b/npm/packs/malihu-custom-scrollbar-plugin/README.md deleted file mode 100644 index 8416714abe..0000000000 --- a/npm/packs/malihu-custom-scrollbar-plugin/README.md +++ /dev/null @@ -1,129 +0,0 @@ -## ℹ️ Description - -ABP Framework is a complete open-source infrastructure to create modern web applications by following the best practices and conventions of software development. This package is a part of the [ABP Framework](https://abp.io) and contains client-side files. -For more information, check out the below links: - -🔗Official Website: https://abp.io - -🔗Commercial Website: https://commercial.abp.io - -🔗Commercial Demo: https://commercial.abp.io/demo - -🔗GitHub Repository: https://github.com/abpframework/abp - -🔗Official Theme: https://www.LeptonTheme.com - -🔗Documentation: https://docs.abp.io - -🔗Community: https://community.abp.io - -🔗Blog: https://blog.abp.io - -🔗Books: https://abp.io/books - -🔗Twitter: https://twitter.com/abpframework - -🔗Discord: https://community.abp.io/discord - -🔗Stackoverflow: https://stackoverflow.com/questions/tagged/abp - -🔗YouTube: https://www.youtube.com/@Volosoft - - -## 🤔 Why ABP Platform? - -Why should you use the ABP.IO Platform instead of creating a new solution from scratch? - -You can find the answer here 👉🏻 [Why ABP Platform?](https://docs.abp.io/en/commercial/latest/why-abp-io-platform) - -## 🚀 Key Features of the ABP Framework - -🟡 Modularity - -🟡 Multi-Tenancy - -🟡 Bootstrap Tag Helpers - -🟡 Dynamic Forms - -🟡 Authentication - -🟡 Authorization - -🟡 Distributed Event Bus - -🟡 BLOB Storing - -🟡 Text Templating - -🟡 Tooling: ABP CLI - -🟡 Cross-Cutting Concerns - -🟡 Bundling & Minification - -🟡 Virtual File System - -🟡 Theming - -🟡 Background Jobs - -🟡 DDD Infrastructure - -🟡 Auto REST APIs - -🟡 Dynamic Client Proxies - -🟡 Multiple Database Providers - -🟡 Data filtering - -🟡 Test Infrastructure - -🟡 Audit Logging - -🟡 Object to Object Mapping - -🟡 Email & SMS Abstractions - -🟡 Localization - -🟡 Setting Management - -🟡 Extension Methods - -🟡 Aspect Oriented Programming - -🟡 Dependency Injection - - -## 🧐 How It Works? - -The following page explains how you use the ABP.IO Platform as a .NET developer 👉 [How it works?](https://commercial.abp.io/how-it-works) - - -### 📘 Supported Database Providers - -🔵 Entity Framework Core - -🔵 MongoDB - -🔵 Dapper - - -### 🎴 Supported UI Frameworks - -🔵 Angular - -🔵 Razor Pages - -🔵 Blazor Web Assembly - -🔵 Blazor Server - -🔵 MAUI with Blazor Hybrid - - -## 📫 Bug & Support - -Support for open-source ABP Framework client-side packages is available at [GitHub Issues](https://github.com/abpframework/abp/issues), and the commercial support is available at [support.abp.io](https://support.abp.io). diff --git a/npm/packs/malihu-custom-scrollbar-plugin/abp.resourcemapping.js b/npm/packs/malihu-custom-scrollbar-plugin/abp.resourcemapping.js deleted file mode 100644 index 7e7f1001e6..0000000000 --- a/npm/packs/malihu-custom-scrollbar-plugin/abp.resourcemapping.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = { - mappings: { - "@node_modules/malihu-custom-scrollbar-plugin/*.*": "@libs/malihu-custom-scrollbar-plugin/" - } -} \ No newline at end of file diff --git a/npm/packs/malihu-custom-scrollbar-plugin/package.json b/npm/packs/malihu-custom-scrollbar-plugin/package.json deleted file mode 100644 index 3c6fc244a2..0000000000 --- a/npm/packs/malihu-custom-scrollbar-plugin/package.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "version": "10.7.0", - "name": "@abp/malihu-custom-scrollbar-plugin", - "repository": { - "type": "git", - "url": "https://github.com/abpframework/abp.git", - "directory": "npm/packs/malihu-custom-scrollbar-plugin" - }, - "publishConfig": { - "access": "public" - }, - "dependencies": { - "@abp/core": "~10.7.0", - "malihu-custom-scrollbar-plugin": "^3.1.5" - }, - "gitHead": "bb4ea17d5996f01889134c138d00b6c8f858a431", - "homepage": "https://abp.io", - "license": "LGPL-3.0", - "keywords": [ - "aspnetcore", - "boilerplate", - "framework", - "web", - "best-practices", - "angular", - "maui", - "blazor", - "mvc", - "csharp", - "webapp" - ] -} diff --git a/npm/packs/owl.carousel/README.md b/npm/packs/owl.carousel/README.md deleted file mode 100644 index 8416714abe..0000000000 --- a/npm/packs/owl.carousel/README.md +++ /dev/null @@ -1,129 +0,0 @@ -## ℹ️ Description - -ABP Framework is a complete open-source infrastructure to create modern web applications by following the best practices and conventions of software development. This package is a part of the [ABP Framework](https://abp.io) and contains client-side files. -For more information, check out the below links: - -🔗Official Website: https://abp.io - -🔗Commercial Website: https://commercial.abp.io - -🔗Commercial Demo: https://commercial.abp.io/demo - -🔗GitHub Repository: https://github.com/abpframework/abp - -🔗Official Theme: https://www.LeptonTheme.com - -🔗Documentation: https://docs.abp.io - -🔗Community: https://community.abp.io - -🔗Blog: https://blog.abp.io - -🔗Books: https://abp.io/books - -🔗Twitter: https://twitter.com/abpframework - -🔗Discord: https://community.abp.io/discord - -🔗Stackoverflow: https://stackoverflow.com/questions/tagged/abp - -🔗YouTube: https://www.youtube.com/@Volosoft - - -## 🤔 Why ABP Platform? - -Why should you use the ABP.IO Platform instead of creating a new solution from scratch? - -You can find the answer here 👉🏻 [Why ABP Platform?](https://docs.abp.io/en/commercial/latest/why-abp-io-platform) - -## 🚀 Key Features of the ABP Framework - -🟡 Modularity - -🟡 Multi-Tenancy - -🟡 Bootstrap Tag Helpers - -🟡 Dynamic Forms - -🟡 Authentication - -🟡 Authorization - -🟡 Distributed Event Bus - -🟡 BLOB Storing - -🟡 Text Templating - -🟡 Tooling: ABP CLI - -🟡 Cross-Cutting Concerns - -🟡 Bundling & Minification - -🟡 Virtual File System - -🟡 Theming - -🟡 Background Jobs - -🟡 DDD Infrastructure - -🟡 Auto REST APIs - -🟡 Dynamic Client Proxies - -🟡 Multiple Database Providers - -🟡 Data filtering - -🟡 Test Infrastructure - -🟡 Audit Logging - -🟡 Object to Object Mapping - -🟡 Email & SMS Abstractions - -🟡 Localization - -🟡 Setting Management - -🟡 Extension Methods - -🟡 Aspect Oriented Programming - -🟡 Dependency Injection - - -## 🧐 How It Works? - -The following page explains how you use the ABP.IO Platform as a .NET developer 👉 [How it works?](https://commercial.abp.io/how-it-works) - - -### 📘 Supported Database Providers - -🔵 Entity Framework Core - -🔵 MongoDB - -🔵 Dapper - - -### 🎴 Supported UI Frameworks - -🔵 Angular - -🔵 Razor Pages - -🔵 Blazor Web Assembly - -🔵 Blazor Server - -🔵 MAUI with Blazor Hybrid - - -## 📫 Bug & Support - -Support for open-source ABP Framework client-side packages is available at [GitHub Issues](https://github.com/abpframework/abp/issues), and the commercial support is available at [support.abp.io](https://support.abp.io). diff --git a/npm/packs/owl.carousel/abp.resourcemapping.js b/npm/packs/owl.carousel/abp.resourcemapping.js deleted file mode 100644 index 3f540f8a28..0000000000 --- a/npm/packs/owl.carousel/abp.resourcemapping.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = { - mappings: { - "@node_modules/owl.carousel/dist/**/*.*": "@libs/owl.carousel/" - } -} \ No newline at end of file diff --git a/npm/packs/jquery-form/README.md b/npm/packs/swiper/README.md similarity index 100% rename from npm/packs/jquery-form/README.md rename to npm/packs/swiper/README.md diff --git a/npm/packs/swiper/abp.resourcemapping.js b/npm/packs/swiper/abp.resourcemapping.js new file mode 100644 index 0000000000..9917ce0bee --- /dev/null +++ b/npm/packs/swiper/abp.resourcemapping.js @@ -0,0 +1,6 @@ +module.exports = { + mappings: { + "@node_modules/swiper/swiper-bundle.min.js*": "@libs/swiper/", + "@node_modules/swiper/swiper-bundle.min.css": "@libs/swiper/" + } +} diff --git a/npm/packs/owl.carousel/package.json b/npm/packs/swiper/package.json similarity index 84% rename from npm/packs/owl.carousel/package.json rename to npm/packs/swiper/package.json index 6afe9d7093..e614f2c68b 100644 --- a/npm/packs/owl.carousel/package.json +++ b/npm/packs/swiper/package.json @@ -1,12 +1,11 @@ { "version": "10.7.0", - "name": "@abp/owl.carousel", + "name": "@abp/swiper", "publishConfig": { "access": "public" }, "dependencies": { - "@abp/core": "~10.7.0", - "owl.carousel": "^2.3.4" + "swiper": "^14.1.0" }, "gitHead": "bb4ea17d5996f01889134c138d00b6c8f858a431", "homepage": "https://abp.io", diff --git a/npm/packs/timeago/abp.resourcemapping.js b/npm/packs/timeago/abp.resourcemapping.js index df913e3d28..de0c3464db 100644 --- a/npm/packs/timeago/abp.resourcemapping.js +++ b/npm/packs/timeago/abp.resourcemapping.js @@ -1,6 +1,6 @@ module.exports = { mappings: { - "@node_modules/timeago/jquery.timeago.js": "@libs/timeago/", - "@node_modules/timeago/locales/*.*": "@libs/timeago/locales/" + "@node_modules/timeago.js/dist/*.js": "@libs/timeago/", + "@node_modules/@abp/timeago/src/*.*": "@libs/abp/timeago/" } -} \ No newline at end of file +} diff --git a/npm/packs/timeago/package.json b/npm/packs/timeago/package.json index 3ace1dadf1..06ebced1a6 100644 --- a/npm/packs/timeago/package.json +++ b/npm/packs/timeago/package.json @@ -11,7 +11,7 @@ }, "dependencies": { "@abp/jquery": "~10.7.0", - "timeago": "^1.6.7" + "timeago.js": "^4.0.2" }, "gitHead": "bb4ea17d5996f01889134c138d00b6c8f858a431", "homepage": "https://abp.io", diff --git a/npm/packs/timeago/src/abp.timeago.js b/npm/packs/timeago/src/abp.timeago.js new file mode 100644 index 0000000000..40693779a7 --- /dev/null +++ b/npm/packs/timeago/src/abp.timeago.js @@ -0,0 +1,164 @@ +var abp = abp || {}; +(function ($) { + + if (typeof timeago === 'undefined') { + throw "abp/timeago library requires the timeago.js library included to the page!"; + } + + abp.timeago = abp.timeago || {}; + + // ABP culture name -> timeago.js locale name (only the ones that don't match the two-letter language code) + abp.timeago.localeMap = { + 'en': 'en_US', + 'zh': 'zh_CN', + 'zh-Hans': 'zh_CN', + 'zh-Hant': 'zh_TW', + 'zh-CN': 'zh_CN', + 'zh-TW': 'zh_TW', + 'pt': 'pt_BR', + 'nb': 'nb_NO', + 'no': 'nb_NO', + 'nn': 'nn_NO', + 'hi': 'hi_IN', + 'id': 'id_ID', + 'bn': 'bn_IN' + }; + + abp.timeago.getLocale = function (cultureName) { + cultureName = cultureName || (abp.localization && abp.localization.currentCulture && abp.localization.currentCulture.cultureName) || 'en'; + + if (abp.timeago.localeMap[cultureName]) { + return abp.timeago.localeMap[cultureName]; + } + + var language = cultureName.split('-')[0]; + return abp.timeago.localeMap[language] || language; + }; + + abp.timeago.format = function (date, options) { + return timeago.format(date, abp.timeago.getLocale(), options); + }; + + var toNodeList = function (nodes) { + if (!nodes) { + return []; + } + + return Array.prototype.filter.call(nodes.nodeType ? [nodes] : nodes, function (node) { + return node && node.getAttribute; + }); + }; + + //