Browse Source

Merge pull request #10696 from abpframework/cotur/file-scope-namespaces

Use file scoped namespaces
pull/10704/head
Halil İbrahim Kalkan 5 years ago
committed by GitHub
parent
commit
e3e1779de6
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 137
      .editorconfig
  2. 2
      .gitignore
  3. 11
      framework/src/Volo.Abp.ApiVersioning.Abstractions/Volo/Abp/ApiVersioning/AbpApiVersioningAbstractionsModule.cs
  4. 9
      framework/src/Volo.Abp.ApiVersioning.Abstractions/Volo/Abp/ApiVersioning/IRequestedApiVersion.cs
  5. 19
      framework/src/Volo.Abp.ApiVersioning.Abstractions/Volo/Abp/ApiVersioning/NullRequestedApiVersion.cs
  6. 25
      framework/src/Volo.Abp.AspNetCore.Authentication.JwtBearer/Microsoft/AspNetCore/Builder/ApplicationBuilderAbpJwtTokenMiddlewareExtension.cs
  7. 9
      framework/src/Volo.Abp.AspNetCore.Authentication.JwtBearer/Volo/Abp/AspNetCore/Authentication/JwtBearer/AbpAspNetCoreAuthenticationJwtBearerModule.cs
  8. 85
      framework/src/Volo.Abp.AspNetCore.Authentication.OAuth/Microsoft/AspNetCore/Authentication/OAuth/Claims/AbpClaimActionCollectionExtensions.cs
  9. 9
      framework/src/Volo.Abp.AspNetCore.Authentication.OAuth/Volo/Abp/AspNetCore/Authentication/OAuth/AbpAspNetCoreAuthenticationOAuthModule.cs
  10. 71
      framework/src/Volo.Abp.AspNetCore.Authentication.OAuth/Volo/Abp/AspNetCore/Authentication/OAuth/Claims/MultipleClaimAction.cs
  11. 41
      framework/src/Volo.Abp.AspNetCore.Authentication.OAuth/Volo/Abp/AspNetCore/Authentication/OAuth/Claims/RemoveDuplicateClaimAction.cs
  12. 81
      framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Microsoft/Extensions/DependencyInjection/AbpOpenIdConnectExtensions.cs
  13. 13
      framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Volo/Abp/AspNetCore/Authentication/OpenIdConnect/AbpAspNetCoreAuthenticationOpenIdConnectModule.cs
  14. 53
      framework/src/Volo.Abp.AspNetCore.Components.Server.Theming/AbpAspNetCoreComponentsServerThemingModule.cs
  15. 21
      framework/src/Volo.Abp.AspNetCore.Components.Server.Theming/Bundling/BlazorGlobalBundles.cs
  16. 13
      framework/src/Volo.Abp.AspNetCore.Components.Server.Theming/Bundling/BlazorGlobalScriptContributor.cs
  17. 25
      framework/src/Volo.Abp.AspNetCore.Components.Server.Theming/Bundling/BlazorGlobalStyleContributor.cs
  18. 79
      framework/src/Volo.Abp.AspNetCore.Components.Server/Volo/Abp/AspNetCore/Components/Server/AbpAspNetCoreComponentsServerModule.cs
  19. 37
      framework/src/Volo.Abp.AspNetCore.Components.Server/Volo/Abp/AspNetCore/Components/Server/Configuration/BlazorServerCurrentApplicationConfigurationCacheResetService.cs
  20. 119
      framework/src/Volo.Abp.AspNetCore.Components.Server/Volo/Abp/AspNetCore/Components/Server/Extensibility/BlazorServerLookupApiRequestService.cs
  21. 19
      framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/AbpAspNetCoreComponentsWebThemingModule.cs
  22. 95
      framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Layout/PageHeader.razor.cs
  23. 9
      framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/PageToolbars/IPageToolbarContributor.cs
  24. 9
      framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/PageToolbars/IPageToolbarManager.cs
  25. 15
      framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/PageToolbars/PageToolbar.cs
  26. 25
      framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/PageToolbars/PageToolbarContributionContext.cs
  27. 9
      framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/PageToolbars/PageToolbarContributor.cs
  28. 7
      framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/PageToolbars/PageToolbarContributorList.cs
  29. 7
      framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/PageToolbars/PageToolbarDictionary.cs
  30. 97
      framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/PageToolbars/PageToolbarExtensions.cs
  31. 33
      framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/PageToolbars/PageToolbarItem.cs
  32. 7
      framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/PageToolbars/PageToolbarItemList.cs
  33. 39
      framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/PageToolbars/PageToolbarManager.cs
  34. 63
      framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/PageToolbars/SimplePageToolbarContributor.cs
  35. 17
      framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Routing/AbpRouterOptions.cs
  36. 11
      framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Routing/RouterAssemblyList.cs
  37. 17
      framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Toolbars/AbpToolbarOptions.cs
  38. 27
      framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Toolbars/IToolbarConfigurationContext.cs
  39. 11
      framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Toolbars/IToolbarContributor.cs
  40. 9
      framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Toolbars/IToolbarManager.cs
  41. 11
      framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Toolbars/StandardToolbars.cs
  42. 19
      framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Toolbars/Toolbar.cs
  43. 65
      framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Toolbars/ToolbarConfigurationContext.cs
  44. 30
      framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Toolbars/ToolbarItem.cs
  45. 43
      framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Toolbars/ToolbarManager.cs
  46. 17
      framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/AbpAspNetCoreApplicationCreationOptions.cs
  47. 25
      framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/AbpAspNetCoreComponentsWebModule.cs
  48. 123
      framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/AbpBlazorClientHttpMessageHandler.cs
  49. 57
      framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/AbpBlazorMessageLocalizerHelper.cs
  50. 87
      framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/AbpUtilsService.cs
  51. 17
      framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/Alerts/AlertManager.cs
  52. 11
      framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/Configuration/ICurrentApplicationConfigurationCacheResetService.cs
  53. 13
      framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/Configuration/NullCurrentApplicationConfigurationCacheResetService.cs
  54. 15
      framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/CookieOptions.cs
  55. 43
      framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/CookieService.cs
  56. 13
      framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/DefaultServerUrlProvider.cs
  57. 13
      framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/DependencyInjection/ComponentsClientScopeServiceProviderAccessor.cs
  58. 87
      framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/ExceptionHandling/AbpExceptionHandlingLogger.cs
  59. 43
      framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/ExceptionHandling/AbpExceptionHandlingLoggerProvider.cs
  60. 91
      framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/ExceptionHandling/UserExceptionInformer.cs
  61. 25
      framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/Extensibility/EntityActions/EntityAction.cs
  62. 13
      framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/Extensibility/EntityActions/EntityActionDictionary.cs
  63. 11
      framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/Extensibility/ILookupApiRequestService.cs
  64. 37
      framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/Extensibility/TableColumns/TableColumn.cs
  65. 13
      framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/Extensibility/TableColumns/TableColumnDictionary.cs
  66. 21
      framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/IAbpUtilsService.cs
  67. 15
      framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/ICookieService.cs
  68. 11
      framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/IServerUrlProvider.cs
  69. 65
      framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/Messages/SimpleUiMessageService.cs
  70. 49
      framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/Security/AbpComponentsClaimsCache.cs
  71. 15
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/AbpAspNetCoreComponentsWebAssemblyThemingModule.cs
  72. 43
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/ComponentsComponentsBundleContributor.cs
  73. 105
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Microsoft/AspNetCore/Components/WebAssembly/Hosting/AbpWebAssemblyHostBuilderExtensions.cs
  74. 15
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Microsoft/Extensions/DependencyInjection/AbpWebAssemblyServiceCollectionExtensions.cs
  75. 39
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/AbpAspNetCoreComponentsWebAssemblyModule.cs
  76. 23
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/AbpWebAssemblyApplicationCreationOptions.cs
  77. 23
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/ApplicationConfigurationCache.cs
  78. 83
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/Extensibility/WebAssemblyLookupApiRequestService.cs
  79. 91
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/WebAssemblyCachedApplicationConfigurationClient.cs
  80. 25
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/WebAssemblyCurrentPrincipalAccessor.cs
  81. 11
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/WebAssemblyCurrentTenantAccessor.cs
  82. 37
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/WebAssemblyServerUrlProvider.cs
  83. 23
      framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/AbpAspNetCoreComponentsModule.cs
  84. 231
      framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/AbpComponentBase.cs
  85. 43
      framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Alerts/AlertList.cs
  86. 40
      framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Alerts/AlertMessage.cs
  87. 25
      framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Alerts/AlertType.cs
  88. 9
      framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Alerts/IAlertManager.cs
  89. 27
      framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/DependencyInjection/AbpWebAssemblyConventionalRegistrar.cs
  90. 37
      framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/DependencyInjection/ServiceProviderComponentActivator.cs
  91. 13
      framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/ExceptionHandling/IUserExceptionInformer.cs
  92. 21
      framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/ExceptionHandling/NullUserExceptionInformer.cs
  93. 17
      framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/ExceptionHandling/UserExceptionInformerContext.cs
  94. 17
      framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Messages/IUiMessageService.cs
  95. 45
      framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Messages/UiMessageEventArgs.cs
  96. 99
      framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Messages/UiMessageOptions.cs
  97. 23
      framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Messages/UiMessageType.cs
  98. 21
      framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Notifications/IUiNotificationService.cs
  99. 37
      framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Notifications/NullUiNotificationService.cs
  100. 27
      framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Notifications/UiNotificationEventArgs.cs

137
.editorconfig

@ -0,0 +1,137 @@
# EditorConfig is awesome: https://EditorConfig.org
# Please feel free to update it (by considering the code style of ABP Team).
# top-most EditorConfig file
root = true
[*.cs]
#Namespace settings
csharp_style_namespace_declarations = file_scoped
dotnet_diagnostic.IDE0161.severity = warning
#Core editorconfig formatting - indentation
#use tabs for indentation
indent_style = tabs
#Formatting - indentation options
#indent switch case contents.
csharp_indent_case_contents = true
#indent switch labels
csharp_indent_switch_labels = true
#Formatting - new line options
#place catch statements on a new line
csharp_new_line_before_catch = true
#place else statements on a new line
csharp_new_line_before_else = true
#require members of object intializers to be on separate lines
csharp_new_line_before_members_in_object_initializers = true
#require braces to be on a new line for object_collection_array_initializers, methods, control_blocks, types, and lambdas (also known as "Allman" style)
csharp_new_line_before_open_brace = object_collection_array_initializers, methods, control_blocks, types, lambdas
#Formatting - organize using options
#sort System.* using directives alphabetically, and place them before other usings
dotnet_sort_system_directives_first = true
#Formatting - spacing options
#require NO space between a cast and the value
csharp_space_after_cast = false
#require a space before the colon for bases or interfaces in a type declaration
csharp_space_after_colon_in_inheritance_clause = true
#require a space after a keyword in a control flow statement such as a for loop
csharp_space_after_keywords_in_control_flow_statements = true
#require a space before the colon for bases or interfaces in a type declaration
csharp_space_before_colon_in_inheritance_clause = true
#remove space within empty argument list parentheses
csharp_space_between_method_call_empty_parameter_list_parentheses = false
#remove space between method call name and opening parenthesis
csharp_space_between_method_call_name_and_opening_parenthesis = false
#do not place space characters after the opening parenthesis and before the closing parenthesis of a method call
csharp_space_between_method_call_parameter_list_parentheses = false
#remove space within empty parameter list parentheses for a method declaration
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
#place a space character after the opening parenthesis and before the closing parenthesis of a method declaration parameter list.
csharp_space_between_method_declaration_parameter_list_parentheses = false
#Formatting - wrapping options
#leave code block on single line
csharp_preserve_single_line_blocks = true
#Style - Code block preferences
#prefer curly braces even for one line of code
csharp_prefer_braces = true:suggestion
#Style - expression bodied member options
#prefer block bodies for constructors
csharp_style_expression_bodied_constructors = false:suggestion
#prefer block bodies for methods
csharp_style_expression_bodied_methods = false:suggestion
#prefer expression-bodied members for properties
csharp_style_expression_bodied_properties = true:suggestion
#Style - expression level options
#prefer out variables to be declared inline in the argument list of a method call when possible
csharp_style_inlined_variable_declaration = true:suggestion
#prefer the language keyword for member access expressions, instead of the type name, for types that have a keyword to represent them
dotnet_style_predefined_type_for_member_access = true:suggestion
#Style - Expression-level preferences
#prefer default over default(T)
csharp_prefer_simple_default_expression = true:suggestion
#prefer objects to be initialized using object initializers when possible
dotnet_style_object_initializer = true:suggestion
#prefer inferred tuple element names
dotnet_style_prefer_inferred_tuple_names = true:suggestion
#Style - implicit and explicit types
#prefer var over explicit type in all cases, unless overridden by another code style rule
csharp_style_var_elsewhere = true:suggestion
#prefer var is used to declare variables with built-in system types such as int
csharp_style_var_for_built_in_types = true:suggestion
#prefer var when the type is already mentioned on the right-hand side of a declaration expression
csharp_style_var_when_type_is_apparent = true:suggestion
#Style - language keyword and framework type options
#prefer the language keyword for local variables, method parameters, and class members, instead of the type name, for types that have a keyword to represent them
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
#Style - Miscellaneous preferences
#prefer local functions over anonymous functions
csharp_style_pattern_local_over_anonymous_function = true:suggestion
#Style - modifier options
#prefer accessibility modifiers to be declared except for public interface members. This will currently not differ from always and will act as future proofing for if C# adds default interface methods.
dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion
#Style - Modifier preferences
#when this rule is set to a list of modifiers, prefer the specified ordering.
csharp_preferred_modifier_order = public,protected,private,virtual,async,readonly,static,override,abstract:suggestion
#Style - Pattern matching
#prefer pattern matching instead of is expression with type casts
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
#Style - qualification options
#prefer fields not to be prefaced with this. or Me. in Visual Basic
dotnet_style_qualification_for_field = false:suggestion
#prefer methods not to be prefaced with this. or Me. in Visual Basic
dotnet_style_qualification_for_method = false:suggestion
#prefer properties not to be prefaced with this. or Me. in Visual Basic
dotnet_style_qualification_for_property = false:suggestion

2
.gitignore

@ -6,7 +6,7 @@
*.user *.user
*.userosscache *.userosscache
*.sln.docstates *.sln.docstates
*.editorconfig
# User-specific files (MonoDevelop/Xamarin Studio) # User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs *.userprefs

11
framework/src/Volo.Abp.ApiVersioning.Abstractions/Volo/Abp/ApiVersioning/AbpApiVersioningAbstractionsModule.cs

@ -1,13 +1,12 @@
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
namespace Volo.Abp.ApiVersioning namespace Volo.Abp.ApiVersioning;
public class AbpApiVersioningAbstractionsModule : AbpModule
{ {
public class AbpApiVersioningAbstractionsModule : AbpModule public override void ConfigureServices(ServiceConfigurationContext context)
{ {
public override void ConfigureServices(ServiceConfigurationContext context) context.Services.AddSingleton<IRequestedApiVersion>(NullRequestedApiVersion.Instance);
{
context.Services.AddSingleton<IRequestedApiVersion>(NullRequestedApiVersion.Instance);
}
} }
} }

9
framework/src/Volo.Abp.ApiVersioning.Abstractions/Volo/Abp/ApiVersioning/IRequestedApiVersion.cs

@ -1,7 +1,6 @@
namespace Volo.Abp.ApiVersioning namespace Volo.Abp.ApiVersioning;
public interface IRequestedApiVersion
{ {
public interface IRequestedApiVersion string Current { get; }
{
string Current { get; }
}
} }

19
framework/src/Volo.Abp.ApiVersioning.Abstractions/Volo/Abp/ApiVersioning/NullRequestedApiVersion.cs

@ -1,14 +1,13 @@
namespace Volo.Abp.ApiVersioning namespace Volo.Abp.ApiVersioning;
public class NullRequestedApiVersion : IRequestedApiVersion
{ {
public class NullRequestedApiVersion : IRequestedApiVersion public static NullRequestedApiVersion Instance = new NullRequestedApiVersion();
{
public static NullRequestedApiVersion Instance = new NullRequestedApiVersion();
public string Current => null; public string Current => null;
private NullRequestedApiVersion()
{
private NullRequestedApiVersion()
{
}
} }
} }

25
framework/src/Volo.Abp.AspNetCore.Authentication.JwtBearer/Microsoft/AspNetCore/Builder/ApplicationBuilderAbpJwtTokenMiddlewareExtension.cs

@ -1,25 +1,24 @@
using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authentication.JwtBearer;
namespace Microsoft.AspNetCore.Builder namespace Microsoft.AspNetCore.Builder;
public static class ApplicationBuilderAbpJwtTokenMiddlewareExtension
{ {
public static class ApplicationBuilderAbpJwtTokenMiddlewareExtension public static IApplicationBuilder UseJwtTokenMiddleware(this IApplicationBuilder app, string schema = JwtBearerDefaults.AuthenticationScheme)
{ {
public static IApplicationBuilder UseJwtTokenMiddleware(this IApplicationBuilder app, string schema = JwtBearerDefaults.AuthenticationScheme) return app.Use(async (ctx, next) =>
{ {
return app.Use(async (ctx, next) => if (ctx.User.Identity?.IsAuthenticated != true)
{ {
if (ctx.User.Identity?.IsAuthenticated != true) var result = await ctx.AuthenticateAsync(schema);
if (result.Succeeded && result.Principal != null)
{ {
var result = await ctx.AuthenticateAsync(schema); ctx.User = result.Principal;
if (result.Succeeded && result.Principal != null)
{
ctx.User = result.Principal;
}
} }
}
await next(); await next();
}); });
}
} }
} }

9
framework/src/Volo.Abp.AspNetCore.Authentication.JwtBearer/Volo/Abp/AspNetCore/Authentication/JwtBearer/AbpAspNetCoreAuthenticationJwtBearerModule.cs

@ -1,11 +1,10 @@
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
using Volo.Abp.Security; using Volo.Abp.Security;
namespace Volo.Abp.AspNetCore.Authentication.JwtBearer namespace Volo.Abp.AspNetCore.Authentication.JwtBearer;
[DependsOn(typeof(AbpSecurityModule))]
public class AbpAspNetCoreAuthenticationJwtBearerModule : AbpModule
{ {
[DependsOn(typeof(AbpSecurityModule))]
public class AbpAspNetCoreAuthenticationJwtBearerModule : AbpModule
{
}
} }

85
framework/src/Volo.Abp.AspNetCore.Authentication.OAuth/Microsoft/AspNetCore/Authentication/OAuth/Claims/AbpClaimActionCollectionExtensions.cs

@ -1,57 +1,56 @@
using Volo.Abp.AspNetCore.Authentication.OAuth.Claims; using Volo.Abp.AspNetCore.Authentication.OAuth.Claims;
using Volo.Abp.Security.Claims; using Volo.Abp.Security.Claims;
namespace Microsoft.AspNetCore.Authentication.OAuth.Claims namespace Microsoft.AspNetCore.Authentication.OAuth.Claims;
public static class AbpClaimActionCollectionExtensions
{ {
public static class AbpClaimActionCollectionExtensions public static void MapAbpClaimTypes(this ClaimActionCollection claimActions)
{ {
public static void MapAbpClaimTypes(this ClaimActionCollection claimActions) if (AbpClaimTypes.UserName != "name")
{
claimActions.MapJsonKey(AbpClaimTypes.UserName, "name");
claimActions.DeleteClaim("name");
claimActions.RemoveDuplicate(AbpClaimTypes.UserName);
}
if (AbpClaimTypes.Email != "email")
{
claimActions.MapJsonKey(AbpClaimTypes.Email, "email");
claimActions.DeleteClaim("email");
claimActions.RemoveDuplicate(AbpClaimTypes.Email);
}
if (AbpClaimTypes.EmailVerified != "email_verified")
{
claimActions.MapJsonKey(AbpClaimTypes.EmailVerified, "email_verified");
}
if (AbpClaimTypes.PhoneNumber != "phone_number")
{ {
if (AbpClaimTypes.UserName != "name") claimActions.MapJsonKey(AbpClaimTypes.PhoneNumber, "phone_number");
{
claimActions.MapJsonKey(AbpClaimTypes.UserName, "name");
claimActions.DeleteClaim("name");
claimActions.RemoveDuplicate(AbpClaimTypes.UserName);
}
if (AbpClaimTypes.Email != "email")
{
claimActions.MapJsonKey(AbpClaimTypes.Email, "email");
claimActions.DeleteClaim("email");
claimActions.RemoveDuplicate(AbpClaimTypes.Email);
}
if (AbpClaimTypes.EmailVerified != "email_verified")
{
claimActions.MapJsonKey(AbpClaimTypes.EmailVerified, "email_verified");
}
if (AbpClaimTypes.PhoneNumber != "phone_number")
{
claimActions.MapJsonKey(AbpClaimTypes.PhoneNumber, "phone_number");
}
if (AbpClaimTypes.PhoneNumberVerified != "phone_number_verified")
{
claimActions.MapJsonKey(AbpClaimTypes.PhoneNumberVerified, "phone_number_verified");
}
if (AbpClaimTypes.Role != "role")
{
claimActions.MapJsonKeyMultiple(AbpClaimTypes.Role, "role");
}
claimActions.RemoveDuplicate(AbpClaimTypes.Name);
} }
public static void MapJsonKeyMultiple(this ClaimActionCollection claimActions, string claimType, string jsonKey) if (AbpClaimTypes.PhoneNumberVerified != "phone_number_verified")
{ {
claimActions.Add(new MultipleClaimAction(claimType, jsonKey)); claimActions.MapJsonKey(AbpClaimTypes.PhoneNumberVerified, "phone_number_verified");
} }
public static void RemoveDuplicate(this ClaimActionCollection claimActions, string claimType) if (AbpClaimTypes.Role != "role")
{ {
claimActions.Add(new RemoveDuplicateClaimAction(claimType)); claimActions.MapJsonKeyMultiple(AbpClaimTypes.Role, "role");
} }
claimActions.RemoveDuplicate(AbpClaimTypes.Name);
}
public static void MapJsonKeyMultiple(this ClaimActionCollection claimActions, string claimType, string jsonKey)
{
claimActions.Add(new MultipleClaimAction(claimType, jsonKey));
}
public static void RemoveDuplicate(this ClaimActionCollection claimActions, string claimType)
{
claimActions.Add(new RemoveDuplicateClaimAction(claimType));
} }
} }

9
framework/src/Volo.Abp.AspNetCore.Authentication.OAuth/Volo/Abp/AspNetCore/Authentication/OAuth/AbpAspNetCoreAuthenticationOAuthModule.cs

@ -1,11 +1,10 @@
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
using Volo.Abp.Security; using Volo.Abp.Security;
namespace Volo.Abp.AspNetCore.Authentication.OAuth namespace Volo.Abp.AspNetCore.Authentication.OAuth;
[DependsOn(typeof(AbpSecurityModule))]
public class AbpAspNetCoreAuthenticationOAuthModule : AbpModule
{ {
[DependsOn(typeof(AbpSecurityModule))]
public class AbpAspNetCoreAuthenticationOAuthModule : AbpModule
{
}
} }

71
framework/src/Volo.Abp.AspNetCore.Authentication.OAuth/Volo/Abp/AspNetCore/Authentication/OAuth/Claims/MultipleClaimAction.cs

@ -3,51 +3,50 @@ using System.Security.Claims;
using System.Text.Json; using System.Text.Json;
using Microsoft.AspNetCore.Authentication.OAuth.Claims; using Microsoft.AspNetCore.Authentication.OAuth.Claims;
namespace Volo.Abp.AspNetCore.Authentication.OAuth.Claims namespace Volo.Abp.AspNetCore.Authentication.OAuth.Claims;
public class MultipleClaimAction : ClaimAction
{ {
public class MultipleClaimAction : ClaimAction public MultipleClaimAction(string claimType, string jsonKey)
: base(claimType, jsonKey)
{ {
public MultipleClaimAction(string claimType, string jsonKey)
: base(claimType, jsonKey)
{
} }
public override void Run(JsonElement userData, ClaimsIdentity identity, string issuer) public override void Run(JsonElement userData, ClaimsIdentity identity, string issuer)
{ {
JsonElement prop; JsonElement prop;
if (!userData.TryGetProperty(ValueType, out prop)) if (!userData.TryGetProperty(ValueType, out prop))
return; return;
if (prop.ValueKind == JsonValueKind.Null)
{
return;
}
Claim claim; if (prop.ValueKind == JsonValueKind.Null)
switch (prop.ValueKind) {
{ return;
case JsonValueKind.String: }
claim = new Claim(ClaimType, prop.GetString(), ValueType, issuer);
Claim claim;
switch (prop.ValueKind)
{
case JsonValueKind.String:
claim = new Claim(ClaimType, prop.GetString(), ValueType, issuer);
if (!identity.Claims.Any(c => c.Type == claim.Type && c.Value == claim.Value))
{
identity.AddClaim(claim);
}
break;
case JsonValueKind.Array:
foreach (var arramItem in prop.EnumerateArray())
{
claim = new Claim(ClaimType, arramItem.GetString(), ValueType, issuer);
if (!identity.Claims.Any(c => c.Type == claim.Type && c.Value == claim.Value)) if (!identity.Claims.Any(c => c.Type == claim.Type && c.Value == claim.Value))
{ {
identity.AddClaim(claim); identity.AddClaim(claim);
} }
break; }
case JsonValueKind.Array: break;
foreach (var arramItem in prop.EnumerateArray()) default:
{ throw new AbpException("Unhandled JsonValueKind: " + prop.ValueKind);
claim = new Claim(ClaimType, arramItem.GetString(), ValueType, issuer);
if (!identity.Claims.Any(c => c.Type == claim.Type && c.Value == claim.Value))
{
identity.AddClaim(claim);
}
}
break;
default:
throw new AbpException("Unhandled JsonValueKind: " + prop.ValueKind);
}
} }
} }
} }

41
framework/src/Volo.Abp.AspNetCore.Authentication.OAuth/Volo/Abp/AspNetCore/Authentication/OAuth/Claims/RemoveDuplicateClaimAction.cs

@ -5,36 +5,35 @@ using System.Security.Claims;
using System.Text.Json; using System.Text.Json;
using Microsoft.AspNetCore.Authentication.OAuth.Claims; using Microsoft.AspNetCore.Authentication.OAuth.Claims;
namespace Volo.Abp.AspNetCore.Authentication.OAuth.Claims namespace Volo.Abp.AspNetCore.Authentication.OAuth.Claims;
public class RemoveDuplicateClaimAction : ClaimAction
{ {
public class RemoveDuplicateClaimAction : ClaimAction public RemoveDuplicateClaimAction(string claimType)
: base(claimType, ClaimValueTypes.String)
{ {
public RemoveDuplicateClaimAction(string claimType) }
: base(claimType, ClaimValueTypes.String)
/// <inheritdoc />
public override void Run(JsonElement userData, ClaimsIdentity identity, string issuer)
{
var claims = identity.Claims.Where(c => c.Type == ClaimType).ToArray();
if (claims.Length < 2)
{ {
return;
} }
/// <inheritdoc /> var previousValues = new List<string>();
public override void Run(JsonElement userData, ClaimsIdentity identity, string issuer) foreach (var claim in claims)
{ {
var claims = identity.Claims.Where(c => c.Type == ClaimType).ToArray(); if (claim.Value.IsIn(previousValues))
if (claims.Length < 2)
{ {
return; identity.RemoveClaim(claim);
} }
else
var previousValues = new List<string>();
foreach (var claim in claims)
{ {
if (claim.Value.IsIn(previousValues)) previousValues.Add(claim.Value);
{
identity.RemoveClaim(claim);
}
else
{
previousValues.Add(claim.Value);
}
} }
} }
} }
} }

81
framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Microsoft/Extensions/DependencyInjection/AbpOpenIdConnectExtensions.cs

@ -7,59 +7,58 @@ using Microsoft.Extensions.Options;
using Microsoft.IdentityModel.Protocols.OpenIdConnect; using Microsoft.IdentityModel.Protocols.OpenIdConnect;
using Volo.Abp.AspNetCore.MultiTenancy; using Volo.Abp.AspNetCore.MultiTenancy;
namespace Microsoft.Extensions.DependencyInjection namespace Microsoft.Extensions.DependencyInjection;
public static class AbpOpenIdConnectExtensions
{ {
public static class AbpOpenIdConnectExtensions public static AuthenticationBuilder AddAbpOpenIdConnect(this AuthenticationBuilder builder)
{ => builder.AddAbpOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, _ => { });
public static AuthenticationBuilder AddAbpOpenIdConnect(this AuthenticationBuilder builder)
=> builder.AddAbpOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, _ => { });
public static AuthenticationBuilder AddAbpOpenIdConnect(this AuthenticationBuilder builder, Action<OpenIdConnectOptions> configureOptions) public static AuthenticationBuilder AddAbpOpenIdConnect(this AuthenticationBuilder builder, Action<OpenIdConnectOptions> configureOptions)
=> builder.AddAbpOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, configureOptions); => builder.AddAbpOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, configureOptions);
public static AuthenticationBuilder AddAbpOpenIdConnect(this AuthenticationBuilder builder, string authenticationScheme, Action<OpenIdConnectOptions> configureOptions) public static AuthenticationBuilder AddAbpOpenIdConnect(this AuthenticationBuilder builder, string authenticationScheme, Action<OpenIdConnectOptions> configureOptions)
=> builder.AddAbpOpenIdConnect(authenticationScheme, OpenIdConnectDefaults.DisplayName, configureOptions); => builder.AddAbpOpenIdConnect(authenticationScheme, OpenIdConnectDefaults.DisplayName, configureOptions);
public static AuthenticationBuilder AddAbpOpenIdConnect(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action<OpenIdConnectOptions> configureOptions) public static AuthenticationBuilder AddAbpOpenIdConnect(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action<OpenIdConnectOptions> configureOptions)
{
return builder.AddOpenIdConnect(authenticationScheme, displayName, options =>
{ {
return builder.AddOpenIdConnect(authenticationScheme, displayName, options => options.ClaimActions.MapAbpClaimTypes();
{
options.ClaimActions.MapAbpClaimTypes();
configureOptions?.Invoke(options); configureOptions?.Invoke(options);
options.Events ??= new OpenIdConnectEvents(); options.Events ??= new OpenIdConnectEvents();
var authorizationCodeReceived = options.Events.OnAuthorizationCodeReceived ?? (_ => Task.CompletedTask); var authorizationCodeReceived = options.Events.OnAuthorizationCodeReceived ?? (_ => Task.CompletedTask);
options.Events.OnAuthorizationCodeReceived = receivedContext => options.Events.OnAuthorizationCodeReceived = receivedContext =>
{ {
SetAbpTenantId(receivedContext); SetAbpTenantId(receivedContext);
return authorizationCodeReceived.Invoke(receivedContext); return authorizationCodeReceived.Invoke(receivedContext);
}; };
options.Events.OnRemoteFailure = remoteFailureContext => options.Events.OnRemoteFailure = remoteFailureContext =>
{
if (remoteFailureContext.Failure is OpenIdConnectProtocolException &&
remoteFailureContext.Failure.Message.Contains("access_denied"))
{ {
if (remoteFailureContext.Failure is OpenIdConnectProtocolException && remoteFailureContext.HandleResponse();
remoteFailureContext.Failure.Message.Contains("access_denied")) remoteFailureContext.Response.Redirect($"{remoteFailureContext.Request.PathBase}/");
{ }
remoteFailureContext.HandleResponse(); return Task.CompletedTask;
remoteFailureContext.Response.Redirect($"{remoteFailureContext.Request.PathBase}/"); };
} });
return Task.CompletedTask; }
};
});
}
private static void SetAbpTenantId(AuthorizationCodeReceivedContext receivedContext) private static void SetAbpTenantId(AuthorizationCodeReceivedContext receivedContext)
{ {
var tenantKey = receivedContext.HttpContext.RequestServices var tenantKey = receivedContext.HttpContext.RequestServices
.GetRequiredService<IOptions<AbpAspNetCoreMultiTenancyOptions>>().Value.TenantKey; .GetRequiredService<IOptions<AbpAspNetCoreMultiTenancyOptions>>().Value.TenantKey;
if (receivedContext.Request.Cookies.ContainsKey(tenantKey)) if (receivedContext.Request.Cookies.ContainsKey(tenantKey))
{ {
receivedContext.TokenEndpointRequest.SetParameter(tenantKey, receivedContext.TokenEndpointRequest.SetParameter(tenantKey,
receivedContext.Request.Cookies[tenantKey]); receivedContext.Request.Cookies[tenantKey]);
}
} }
} }
} }

13
framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Volo/Abp/AspNetCore/Authentication/OpenIdConnect/AbpAspNetCoreAuthenticationOpenIdConnectModule.cs

@ -2,13 +2,12 @@
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
using Volo.Abp.MultiTenancy; using Volo.Abp.MultiTenancy;
namespace Volo.Abp.AspNetCore.Authentication.OpenIdConnect namespace Volo.Abp.AspNetCore.Authentication.OpenIdConnect;
[DependsOn(
typeof(AbpMultiTenancyModule),
typeof(AbpAspNetCoreAuthenticationOAuthModule))]
public class AbpAspNetCoreAuthenticationOpenIdConnectModule : AbpModule
{ {
[DependsOn(
typeof(AbpMultiTenancyModule),
typeof(AbpAspNetCoreAuthenticationOAuthModule))]
public class AbpAspNetCoreAuthenticationOpenIdConnectModule : AbpModule
{
}
} }

53
framework/src/Volo.Abp.AspNetCore.Components.Server.Theming/AbpAspNetCoreComponentsServerThemingModule.cs

@ -4,34 +4,33 @@ using Volo.Abp.AspNetCore.Mvc.UI.Bundling;
using Volo.Abp.AspNetCore.Mvc.UI.Packages; using Volo.Abp.AspNetCore.Mvc.UI.Packages;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
namespace Volo.Abp.AspNetCore.Components.Server.Theming namespace Volo.Abp.AspNetCore.Components.Server.Theming;
[DependsOn(
typeof(AbpAspNetCoreComponentsServerModule),
typeof(AbpAspNetCoreMvcUiPackagesModule),
typeof(AbpAspNetCoreComponentsWebThemingModule),
typeof(AbpAspNetCoreMvcUiBundlingModule)
)]
public class AbpAspNetCoreComponentsServerThemingModule : AbpModule
{ {
[DependsOn( public override void ConfigureServices(ServiceConfigurationContext context)
typeof(AbpAspNetCoreComponentsServerModule),
typeof(AbpAspNetCoreMvcUiPackagesModule),
typeof(AbpAspNetCoreComponentsWebThemingModule),
typeof(AbpAspNetCoreMvcUiBundlingModule)
)]
public class AbpAspNetCoreComponentsServerThemingModule : AbpModule
{ {
public override void ConfigureServices(ServiceConfigurationContext context) Configure<AbpBundlingOptions>(options =>
{ {
Configure<AbpBundlingOptions>(options => options
{ .StyleBundles
options .Add(BlazorStandardBundles.Styles.Global, bundle =>
.StyleBundles {
.Add(BlazorStandardBundles.Styles.Global, bundle => bundle.AddContributors(typeof(BlazorGlobalStyleContributor));
{ });
bundle.AddContributors(typeof(BlazorGlobalStyleContributor));
}); options
.ScriptBundles
options .Add(BlazorStandardBundles.Scripts.Global, bundle =>
.ScriptBundles {
.Add(BlazorStandardBundles.Scripts.Global, bundle => bundle.AddContributors(typeof(BlazorGlobalScriptContributor));
{ });
bundle.AddContributors(typeof(BlazorGlobalScriptContributor)); });
});
});
}
} }
} }

21
framework/src/Volo.Abp.AspNetCore.Components.Server.Theming/Bundling/BlazorGlobalBundles.cs

@ -1,15 +1,14 @@
namespace Volo.Abp.AspNetCore.Components.Server.Theming.Bundling namespace Volo.Abp.AspNetCore.Components.Server.Theming.Bundling;
public class BlazorStandardBundles
{ {
public class BlazorStandardBundles public static class Styles
{ {
public static class Styles public static string Global = "Blazor.Global";
{ }
public static string Global = "Blazor.Global";
}
public static class Scripts public static class Scripts
{ {
public static string Global = "Blazor.Global"; public static string Global = "Blazor.Global";
}
} }
} }

13
framework/src/Volo.Abp.AspNetCore.Components.Server.Theming/Bundling/BlazorGlobalScriptContributor.cs

@ -1,14 +1,13 @@
using System.Collections.Generic; using System.Collections.Generic;
using Volo.Abp.AspNetCore.Mvc.UI.Bundling; using Volo.Abp.AspNetCore.Mvc.UI.Bundling;
namespace Volo.Abp.AspNetCore.Components.Server.Theming.Bundling namespace Volo.Abp.AspNetCore.Components.Server.Theming.Bundling;
public class BlazorGlobalScriptContributor : BundleContributor
{ {
public class BlazorGlobalScriptContributor : BundleContributor public override void ConfigureBundle(BundleConfigurationContext context)
{ {
public override void ConfigureBundle(BundleConfigurationContext context) context.Files.AddIfNotContains("/_framework/blazor.server.js");
{ context.Files.AddIfNotContains("/_content/Volo.Abp.AspNetCore.Components.Web/libs/abp/js/abp.js");
context.Files.AddIfNotContains("/_framework/blazor.server.js");
context.Files.AddIfNotContains("/_content/Volo.Abp.AspNetCore.Components.Web/libs/abp/js/abp.js");
}
} }
} }

25
framework/src/Volo.Abp.AspNetCore.Components.Server.Theming/Bundling/BlazorGlobalStyleContributor.cs

@ -4,19 +4,18 @@ using Volo.Abp.AspNetCore.Mvc.UI.Packages.Bootstrap;
using Volo.Abp.AspNetCore.Mvc.UI.Packages.FontAwesome; using Volo.Abp.AspNetCore.Mvc.UI.Packages.FontAwesome;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
namespace Volo.Abp.AspNetCore.Components.Server.Theming.Bundling namespace Volo.Abp.AspNetCore.Components.Server.Theming.Bundling;
[DependsOn(
typeof(BootstrapStyleContributor),
typeof(FontAwesomeStyleContributor)
)]
public class BlazorGlobalStyleContributor : BundleContributor
{ {
[DependsOn( public override void ConfigureBundle(BundleConfigurationContext context)
typeof(BootstrapStyleContributor),
typeof(FontAwesomeStyleContributor)
)]
public class BlazorGlobalStyleContributor : BundleContributor
{ {
public override void ConfigureBundle(BundleConfigurationContext context) context.Files.AddIfNotContains("/_content/Blazorise/blazorise.css");
{ context.Files.AddIfNotContains("/_content/Blazorise.Bootstrap5/blazorise.bootstrap5.css");
context.Files.AddIfNotContains("/_content/Blazorise/blazorise.css"); context.Files.AddIfNotContains("/_content/Blazorise.Snackbar/blazorise.snackbar.css");
context.Files.AddIfNotContains("/_content/Blazorise.Bootstrap5/blazorise.bootstrap5.css");
context.Files.AddIfNotContains("/_content/Blazorise.Snackbar/blazorise.snackbar.css");
}
} }
} }

79
framework/src/Volo.Abp.AspNetCore.Components.Server/Volo/Abp/AspNetCore/Components/Server/AbpAspNetCoreComponentsServerModule.cs

@ -13,55 +13,54 @@ using Volo.Abp.EventBus;
using Volo.Abp.Http.Client; using Volo.Abp.Http.Client;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
namespace Volo.Abp.AspNetCore.Components.Server namespace Volo.Abp.AspNetCore.Components.Server;
[DependsOn(
typeof(AbpHttpClientModule),
typeof(AbpAspNetCoreComponentsWebModule),
typeof(AbpAspNetCoreSignalRModule),
typeof(AbpEventBusModule),
typeof(AbpAspNetCoreMvcContractsModule)
)]
public class AbpAspNetCoreComponentsServerModule : AbpModule
{ {
[DependsOn( public override void ConfigureServices(ServiceConfigurationContext context)
typeof(AbpHttpClientModule),
typeof(AbpAspNetCoreComponentsWebModule),
typeof(AbpAspNetCoreSignalRModule),
typeof(AbpEventBusModule),
typeof(AbpAspNetCoreMvcContractsModule)
)]
public class AbpAspNetCoreComponentsServerModule : AbpModule
{ {
public override void ConfigureServices(ServiceConfigurationContext context) var serverSideBlazorBuilder = context.Services.AddServerSideBlazor(options =>
{ {
var serverSideBlazorBuilder = context.Services.AddServerSideBlazor(options => if (context.Services.GetHostingEnvironment().IsDevelopment())
{ {
if (context.Services.GetHostingEnvironment().IsDevelopment()) options.DetailedErrors = true;
{ }
options.DetailedErrors = true; });
} context.Services.ExecutePreConfiguredActions(serverSideBlazorBuilder);
});
context.Services.ExecutePreConfiguredActions(serverSideBlazorBuilder);
Configure<AbpAspNetCoreUnitOfWorkOptions>(options => Configure<AbpAspNetCoreUnitOfWorkOptions>(options =>
{ {
options.IgnoredUrls.AddIfNotContains("/_blazor"); options.IgnoredUrls.AddIfNotContains("/_blazor");
}); });
Configure<AbpAspNetCoreAuditingOptions>(options => Configure<AbpAspNetCoreAuditingOptions>(options =>
{ {
options.IgnoredUrls.AddIfNotContains("/_blazor"); options.IgnoredUrls.AddIfNotContains("/_blazor");
}); });
Configure<AbpEndpointRouterOptions>(options => Configure<AbpEndpointRouterOptions>(options =>
{
options.EndpointConfigureActions.Add(endpointContext =>
{ {
options.EndpointConfigureActions.Add(endpointContext => endpointContext.Endpoints.MapBlazorHub();
{ endpointContext.Endpoints.MapFallbackToPage("/_Host");
endpointContext.Endpoints.MapBlazorHub();
endpointContext.Endpoints.MapFallbackToPage("/_Host");
});
}); });
} });
}
public override void OnApplicationInitialization(ApplicationInitializationContext context) public override void OnApplicationInitialization(ApplicationInitializationContext context)
{ {
context.GetEnvironment().WebRootFileProvider = context.GetEnvironment().WebRootFileProvider =
new CompositeFileProvider( new CompositeFileProvider(
new ManifestEmbeddedFileProvider(typeof(IServerSideBlazorBuilder).Assembly), new ManifestEmbeddedFileProvider(typeof(IServerSideBlazorBuilder).Assembly),
context.GetEnvironment().WebRootFileProvider context.GetEnvironment().WebRootFileProvider
); );
}
} }
} }

37
framework/src/Volo.Abp.AspNetCore.Components.Server/Volo/Abp/AspNetCore/Components/Server/Configuration/BlazorServerCurrentApplicationConfigurationCacheResetService.cs

@ -4,26 +4,25 @@ using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.EventBus.Local; using Volo.Abp.EventBus.Local;
namespace Volo.Abp.AspNetCore.Components.Server.Configuration namespace Volo.Abp.AspNetCore.Components.Server.Configuration;
[Dependency(ReplaceServices = true)]
public class BlazorServerCurrentApplicationConfigurationCacheResetService :
ICurrentApplicationConfigurationCacheResetService,
ITransientDependency
{ {
[Dependency(ReplaceServices = true)] private readonly ILocalEventBus _localEventBus;
public class BlazorServerCurrentApplicationConfigurationCacheResetService :
ICurrentApplicationConfigurationCacheResetService,
ITransientDependency
{
private readonly ILocalEventBus _localEventBus;
public BlazorServerCurrentApplicationConfigurationCacheResetService( public BlazorServerCurrentApplicationConfigurationCacheResetService(
ILocalEventBus localEventBus) ILocalEventBus localEventBus)
{ {
_localEventBus = localEventBus; _localEventBus = localEventBus;
} }
public async Task ResetAsync() public async Task ResetAsync()
{ {
await _localEventBus.PublishAsync( await _localEventBus.PublishAsync(
new CurrentApplicationConfigurationCacheResetEventData() new CurrentApplicationConfigurationCacheResetEventData()
); );
}
} }
} }

119
framework/src/Volo.Abp.AspNetCore.Components.Server/Volo/Abp/AspNetCore/Components/Server/Extensibility/BlazorServerLookupApiRequestService.cs

@ -13,78 +13,77 @@ using Volo.Abp.Http.Client;
using Volo.Abp.Http.Client.Authentication; using Volo.Abp.Http.Client.Authentication;
using Volo.Abp.MultiTenancy; using Volo.Abp.MultiTenancy;
namespace Volo.Abp.AspNetCore.Components.Server.Extensibility namespace Volo.Abp.AspNetCore.Components.Server.Extensibility;
public class BlazorServerLookupApiRequestService : ILookupApiRequestService, ITransientDependency
{ {
public class BlazorServerLookupApiRequestService : ILookupApiRequestService, ITransientDependency public IHttpClientFactory HttpClientFactory { get; }
public IRemoteServiceHttpClientAuthenticator HttpClientAuthenticator { get; }
public IRemoteServiceConfigurationProvider RemoteServiceConfigurationProvider { get; }
public ICurrentTenant CurrentTenant { get; }
public IHttpContextAccessor HttpContextAccessor { get; }
public NavigationManager NavigationManager { get; }
public BlazorServerLookupApiRequestService(IHttpClientFactory httpClientFactory,
IRemoteServiceHttpClientAuthenticator httpClientAuthenticator,
ICurrentTenant currentTenant,
IHttpContextAccessor httpContextAccessor,
NavigationManager navigationManager,
IRemoteServiceConfigurationProvider remoteServiceConfigurationProvider)
{ {
public IHttpClientFactory HttpClientFactory { get; } HttpClientFactory = httpClientFactory;
public IRemoteServiceHttpClientAuthenticator HttpClientAuthenticator { get; } HttpClientAuthenticator = httpClientAuthenticator;
public IRemoteServiceConfigurationProvider RemoteServiceConfigurationProvider { get; } CurrentTenant = currentTenant;
public ICurrentTenant CurrentTenant { get; } HttpContextAccessor = httpContextAccessor;
public IHttpContextAccessor HttpContextAccessor { get; } NavigationManager = navigationManager;
public NavigationManager NavigationManager { get; } RemoteServiceConfigurationProvider = remoteServiceConfigurationProvider;
}
public BlazorServerLookupApiRequestService(IHttpClientFactory httpClientFactory, public async Task<string> SendAsync(string url)
IRemoteServiceHttpClientAuthenticator httpClientAuthenticator, {
ICurrentTenant currentTenant, var client = HttpClientFactory.CreateClient();
IHttpContextAccessor httpContextAccessor, var requestMessage = new HttpRequestMessage(HttpMethod.Get, url);
NavigationManager navigationManager,
IRemoteServiceConfigurationProvider remoteServiceConfigurationProvider)
{
HttpClientFactory = httpClientFactory;
HttpClientAuthenticator = httpClientAuthenticator;
CurrentTenant = currentTenant;
HttpContextAccessor = httpContextAccessor;
NavigationManager = navigationManager;
RemoteServiceConfigurationProvider = remoteServiceConfigurationProvider;
}
public async Task<string> SendAsync(string url) var uri = new Uri(url, UriKind.RelativeOrAbsolute);
if (!uri.IsAbsoluteUri)
{ {
var client = HttpClientFactory.CreateClient(); var baseUrl = string.Empty;
var requestMessage = new HttpRequestMessage(HttpMethod.Get, url); try
var uri = new Uri(url, UriKind.RelativeOrAbsolute);
if (!uri.IsAbsoluteUri)
{ {
var baseUrl = string.Empty; //Blazor tiered -- mode
try var remoteServiceConfig = await RemoteServiceConfigurationProvider.GetConfigurationOrDefaultAsync("Default");
{ baseUrl = remoteServiceConfig.BaseUrl;
//Blazor tiered -- mode client.BaseAddress = new Uri(baseUrl);
var remoteServiceConfig = await RemoteServiceConfigurationProvider.GetConfigurationOrDefaultAsync("Default"); AddHeaders(requestMessage);
baseUrl = remoteServiceConfig.BaseUrl; await HttpClientAuthenticator.Authenticate(new RemoteServiceHttpClientAuthenticateContext(client,
client.BaseAddress = new Uri(baseUrl); requestMessage, new RemoteServiceConfiguration(baseUrl), string.Empty));
AddHeaders(requestMessage); }
await HttpClientAuthenticator.Authenticate(new RemoteServiceHttpClientAuthenticateContext(client, catch (AbpException) // Blazor-Server mode.
requestMessage, new RemoteServiceConfiguration(baseUrl), string.Empty)); {
} baseUrl = NavigationManager.BaseUri;
catch (AbpException) // Blazor-Server mode. client.BaseAddress = new Uri(baseUrl);
foreach (var header in HttpContextAccessor.HttpContext.Request.Headers)
{ {
baseUrl = NavigationManager.BaseUri; requestMessage.Headers.Add(header.Key, header.Value.ToArray());
client.BaseAddress = new Uri(baseUrl);
foreach (var header in HttpContextAccessor.HttpContext.Request.Headers)
{
requestMessage.Headers.Add(header.Key, header.Value.ToArray());
}
} }
} }
var response = await client.SendAsync(requestMessage);
return await response.Content.ReadAsStringAsync();
} }
protected virtual void AddHeaders(HttpRequestMessage requestMessage) var response = await client.SendAsync(requestMessage);
return await response.Content.ReadAsStringAsync();
}
protected virtual void AddHeaders(HttpRequestMessage requestMessage)
{
if (CurrentTenant.Id.HasValue)
{ {
if (CurrentTenant.Id.HasValue) requestMessage.Headers.Add(TenantResolverConsts.DefaultTenantKey, CurrentTenant.Id.Value.ToString());
{ }
requestMessage.Headers.Add(TenantResolverConsts.DefaultTenantKey, CurrentTenant.Id.Value.ToString());
}
var currentCulture = CultureInfo.CurrentUICulture.Name ?? CultureInfo.CurrentCulture.Name; var currentCulture = CultureInfo.CurrentUICulture.Name ?? CultureInfo.CurrentCulture.Name;
if (!currentCulture.IsNullOrEmpty()) if (!currentCulture.IsNullOrEmpty())
{ {
requestMessage.Headers.AcceptLanguage.Add(new(currentCulture)); requestMessage.Headers.AcceptLanguage.Add(new(currentCulture));
}
} }
} }
} }

19
framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/AbpAspNetCoreComponentsWebThemingModule.cs

@ -2,14 +2,13 @@
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
using Volo.Abp.UI.Navigation; using Volo.Abp.UI.Navigation;
namespace Volo.Abp.AspNetCore.Components.Web.Theming namespace Volo.Abp.AspNetCore.Components.Web.Theming;
[DependsOn(
typeof(AbpBlazoriseUIModule),
typeof(AbpUiNavigationModule)
)]
public class AbpAspNetCoreComponentsWebThemingModule : AbpModule
{ {
[DependsOn(
typeof(AbpBlazoriseUIModule), }
typeof(AbpUiNavigationModule)
)]
public class AbpAspNetCoreComponentsWebThemingModule : AbpModule
{
}
}

95
framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Layout/PageHeader.razor.cs

@ -5,69 +5,68 @@ using System.Threading.Tasks;
using Volo.Abp.AspNetCore.Components.Web.Theming.PageToolbars; using Volo.Abp.AspNetCore.Components.Web.Theming.PageToolbars;
using Volo.Abp.BlazoriseUI; using Volo.Abp.BlazoriseUI;
namespace Volo.Abp.AspNetCore.Components.Web.Theming.Layout namespace Volo.Abp.AspNetCore.Components.Web.Theming.Layout;
public partial class PageHeader : ComponentBase
{ {
public partial class PageHeader : ComponentBase protected List<RenderFragment> ToolbarItemRenders { get; set; }
{
protected List<RenderFragment> ToolbarItemRenders { get; set; }
public IPageToolbarManager PageToolbarManager { get; set; }
[Parameter]
public string Title { get; set; }
[Parameter] public IPageToolbarManager PageToolbarManager { get; set; }
public bool BreadcrumbShowHome { get; set; } = true;
[Parameter] [Parameter]
public bool BreadcrumbShowCurrent { get; set; } = true; public string Title { get; set; }
[Parameter] [Parameter]
public RenderFragment ChildContent { get; set; } public bool BreadcrumbShowHome { get; set; } = true;
[Parameter] [Parameter]
public List<BreadcrumbItem> BreadcrumbItems { get; set; } public bool BreadcrumbShowCurrent { get; set; } = true;
[Parameter]
public PageToolbar Toolbar { get; set; }
public PageHeader() [Parameter]
{ public RenderFragment ChildContent { get; set; }
BreadcrumbItems = new List<BreadcrumbItem>();
ToolbarItemRenders = new List<RenderFragment>(); [Parameter]
} public List<BreadcrumbItem> BreadcrumbItems { get; set; }
[Parameter]
public PageToolbar Toolbar { get; set; }
public PageHeader()
{
BreadcrumbItems = new List<BreadcrumbItem>();
ToolbarItemRenders = new List<RenderFragment>();
}
protected override async Task OnParametersSetAsync() protected override async Task OnParametersSetAsync()
{
await base.OnParametersSetAsync();
if (Toolbar != null)
{ {
await base.OnParametersSetAsync(); var toolbarItems = await PageToolbarManager.GetItemsAsync(Toolbar);
if (Toolbar!=null) ToolbarItemRenders.Clear();
{
var toolbarItems = await PageToolbarManager.GetItemsAsync(Toolbar);
ToolbarItemRenders.Clear();
foreach (var item in toolbarItems) foreach (var item in toolbarItems)
{
var sequence = 0;
ToolbarItemRenders.Add(builder =>
{ {
var sequence = 0; builder.OpenComponent(sequence, item.ComponentType);
ToolbarItemRenders.Add(builder => if (item.Arguments != null)
{ {
builder.OpenComponent(sequence, item.ComponentType); foreach (var argument in item.Arguments)
if (item.Arguments != null)
{ {
foreach (var argument in item.Arguments) sequence++;
{ builder.AddAttribute(sequence, argument.Key, argument.Value);
sequence++;
builder.AddAttribute(sequence, argument.Key, argument.Value);
}
} }
builder.CloseComponent(); }
}); builder.CloseComponent();
} });
} }
} }
}
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
await base.OnInitializedAsync(); await base.OnInitializedAsync();
}
} }
} }

9
framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/PageToolbars/IPageToolbarContributor.cs

@ -1,9 +1,8 @@
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Volo.Abp.AspNetCore.Components.Web.Theming.PageToolbars namespace Volo.Abp.AspNetCore.Components.Web.Theming.PageToolbars;
public interface IPageToolbarContributor
{ {
public interface IPageToolbarContributor Task ContributeAsync(PageToolbarContributionContext context);
{
Task ContributeAsync(PageToolbarContributionContext context);
}
} }

9
framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/PageToolbars/IPageToolbarManager.cs

@ -1,9 +1,8 @@
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Volo.Abp.AspNetCore.Components.Web.Theming.PageToolbars namespace Volo.Abp.AspNetCore.Components.Web.Theming.PageToolbars;
public interface IPageToolbarManager
{ {
public interface IPageToolbarManager Task<PageToolbarItem[]> GetItemsAsync(PageToolbar toolbar);
{
Task<PageToolbarItem[]> GetItemsAsync(PageToolbar toolbar);
}
} }

15
framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/PageToolbars/PageToolbar.cs

@ -1,12 +1,11 @@
namespace Volo.Abp.AspNetCore.Components.Web.Theming.PageToolbars namespace Volo.Abp.AspNetCore.Components.Web.Theming.PageToolbars;
public class PageToolbar
{ {
public class PageToolbar public PageToolbarContributorList Contributors { get; set; }
{
public PageToolbarContributorList Contributors { get; set; }
public PageToolbar() public PageToolbar()
{ {
Contributors = new PageToolbarContributorList(); Contributors = new PageToolbarContributorList();
}
} }
} }

25
framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/PageToolbars/PageToolbarContributionContext.cs

@ -1,21 +1,20 @@
using JetBrains.Annotations; using JetBrains.Annotations;
using System; using System;
namespace Volo.Abp.AspNetCore.Components.Web.Theming.PageToolbars namespace Volo.Abp.AspNetCore.Components.Web.Theming.PageToolbars;
public class PageToolbarContributionContext
{ {
public class PageToolbarContributionContext [NotNull]
{ public IServiceProvider ServiceProvider { get; }
[NotNull]
public IServiceProvider ServiceProvider { get; }
[NotNull] [NotNull]
public PageToolbarItemList Items { get; } public PageToolbarItemList Items { get; }
public PageToolbarContributionContext( public PageToolbarContributionContext(
[NotNull] IServiceProvider serviceProvider) [NotNull] IServiceProvider serviceProvider)
{ {
ServiceProvider = Check.NotNull(serviceProvider, nameof(serviceProvider)); ServiceProvider = Check.NotNull(serviceProvider, nameof(serviceProvider));
Items = new PageToolbarItemList(); Items = new PageToolbarItemList();
}
} }
} }

9
framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/PageToolbars/PageToolbarContributor.cs

@ -1,9 +1,8 @@
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Volo.Abp.AspNetCore.Components.Web.Theming.PageToolbars namespace Volo.Abp.AspNetCore.Components.Web.Theming.PageToolbars;
public abstract class PageToolbarContributor : IPageToolbarContributor
{ {
public abstract class PageToolbarContributor : IPageToolbarContributor public abstract Task ContributeAsync(PageToolbarContributionContext context);
{
public abstract Task ContributeAsync(PageToolbarContributionContext context);
}
} }

7
framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/PageToolbars/PageToolbarContributorList.cs

@ -1,8 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
namespace Volo.Abp.AspNetCore.Components.Web.Theming.PageToolbars namespace Volo.Abp.AspNetCore.Components.Web.Theming.PageToolbars;
public class PageToolbarContributorList : List<IPageToolbarContributor>
{ {
public class PageToolbarContributorList : List<IPageToolbarContributor>
{
}
} }

7
framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/PageToolbars/PageToolbarDictionary.cs

@ -1,9 +1,8 @@
using System.Collections.Generic; using System.Collections.Generic;
namespace Volo.Abp.AspNetCore.Components.Web.Theming.PageToolbars namespace Volo.Abp.AspNetCore.Components.Web.Theming.PageToolbars;
public class PageToolbarDictionary : Dictionary<string, PageToolbar>
{ {
public class PageToolbarDictionary : Dictionary<string, PageToolbar>
{
}
} }

97
framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/PageToolbars/PageToolbarExtensions.cs

@ -5,67 +5,66 @@ using System.Threading.Tasks;
using Volo.Abp.BlazoriseUI.Components; using Volo.Abp.BlazoriseUI.Components;
using Volo.Abp.Localization; using Volo.Abp.Localization;
namespace Volo.Abp.AspNetCore.Components.Web.Theming.PageToolbars namespace Volo.Abp.AspNetCore.Components.Web.Theming.PageToolbars;
public static class PageToolbarExtensions
{ {
public static class PageToolbarExtensions public static PageToolbar AddComponent<TComponent>(
this PageToolbar toolbar,
Dictionary<string, object> arguments = null,
int order = 0,
string requiredPolicyName = null)
{ {
public static PageToolbar AddComponent<TComponent>( return toolbar.AddComponent(
this PageToolbar toolbar, typeof(TComponent),
Dictionary<string, object> arguments = null, arguments,
int order = 0, order,
string requiredPolicyName = null) requiredPolicyName
{ );
return toolbar.AddComponent( }
typeof(TComponent),
public static PageToolbar AddComponent(
this PageToolbar toolbar,
Type componentType,
Dictionary<string, object> arguments = null,
int order = 0,
string requiredPolicyName = null)
{
toolbar.Contributors.Add(
new SimplePageToolbarContributor(
componentType,
arguments, arguments,
order, order,
requiredPolicyName requiredPolicyName
); )
} );
public static PageToolbar AddComponent(
this PageToolbar toolbar,
Type componentType,
Dictionary<string, object> arguments = null,
int order = 0,
string requiredPolicyName = null)
{
toolbar.Contributors.Add(
new SimplePageToolbarContributor(
componentType,
arguments,
order,
requiredPolicyName
)
);
return toolbar; return toolbar;
} }
public static PageToolbar AddButton( public static PageToolbar AddButton(
this PageToolbar toolbar, this PageToolbar toolbar,
string text, string text,
Func<Task> clicked, Func<Task> clicked,
object icon = null, object icon = null,
Color color = Color.Primary, Color color = Color.Primary,
bool disabled = false, bool disabled = false,
int order = 0, int order = 0,
string requiredPolicyName = null) string requiredPolicyName = null)
{ {
toolbar.AddComponent<ToolbarButton>( toolbar.AddComponent<ToolbarButton>(
new Dictionary<string, object> new Dictionary<string, object>
{ {
{ nameof(ToolbarButton.Color), color}, { nameof(ToolbarButton.Color), color},
{ nameof(ToolbarButton.Text), text}, { nameof(ToolbarButton.Text), text},
{ nameof(ToolbarButton.Disabled), disabled}, { nameof(ToolbarButton.Disabled), disabled},
{ nameof(ToolbarButton.Icon), icon}, { nameof(ToolbarButton.Icon), icon},
{ nameof(ToolbarButton.Clicked),clicked}, { nameof(ToolbarButton.Clicked),clicked},
}, },
order, order,
requiredPolicyName requiredPolicyName
); );
return toolbar; return toolbar;
}
} }
} }

33
framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/PageToolbars/PageToolbarItem.cs

@ -2,26 +2,25 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace Volo.Abp.AspNetCore.Components.Web.Theming.PageToolbars namespace Volo.Abp.AspNetCore.Components.Web.Theming.PageToolbars;
public class PageToolbarItem
{ {
public class PageToolbarItem [NotNull]
{ public Type ComponentType { get; }
[NotNull]
public Type ComponentType { get; }
[CanBeNull] [CanBeNull]
public Dictionary<string, object> Arguments { get; set; } public Dictionary<string, object> Arguments { get; set; }
public int Order { get; set; } public int Order { get; set; }
public PageToolbarItem( public PageToolbarItem(
[NotNull] Type componentType, [NotNull] Type componentType,
[CanBeNull] Dictionary<string, object> arguments = null, [CanBeNull] Dictionary<string, object> arguments = null,
int order = 0) int order = 0)
{ {
ComponentType = Check.NotNull(componentType, nameof(componentType)); ComponentType = Check.NotNull(componentType, nameof(componentType));
Arguments = arguments; Arguments = arguments;
Order = order; Order = order;
}
} }
} }

7
framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/PageToolbars/PageToolbarItemList.cs

@ -1,9 +1,8 @@
using System.Collections.Generic; using System.Collections.Generic;
namespace Volo.Abp.AspNetCore.Components.Web.Theming.PageToolbars namespace Volo.Abp.AspNetCore.Components.Web.Theming.PageToolbars;
public class PageToolbarItemList : List<PageToolbarItem>
{ {
public class PageToolbarItemList : List<PageToolbarItem>
{
}
} }

39
framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/PageToolbars/PageToolbarManager.cs

@ -5,36 +5,35 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
namespace Volo.Abp.AspNetCore.Components.Web.Theming.PageToolbars namespace Volo.Abp.AspNetCore.Components.Web.Theming.PageToolbars;
public class PageToolbarManager : IPageToolbarManager, ITransientDependency
{ {
public class PageToolbarManager : IPageToolbarManager, ITransientDependency protected IHybridServiceScopeFactory ServiceScopeFactory { get; }
public PageToolbarManager(
IHybridServiceScopeFactory serviceScopeFactory)
{ {
protected IHybridServiceScopeFactory ServiceScopeFactory { get; } ServiceScopeFactory = serviceScopeFactory;
}
public PageToolbarManager( public virtual async Task<PageToolbarItem[]> GetItemsAsync(PageToolbar toolbar)
IHybridServiceScopeFactory serviceScopeFactory) {
if (toolbar == null || !toolbar.Contributors.Any())
{ {
ServiceScopeFactory = serviceScopeFactory; return Array.Empty<PageToolbarItem>();
} }
public virtual async Task<PageToolbarItem[]> GetItemsAsync(PageToolbar toolbar) using (var scope = ServiceScopeFactory.CreateScope())
{ {
if (toolbar == null || !toolbar.Contributors.Any()) var context = new PageToolbarContributionContext(scope.ServiceProvider);
{
return Array.Empty<PageToolbarItem>();
}
using (var scope = ServiceScopeFactory.CreateScope()) foreach (var contributor in toolbar.Contributors)
{ {
var context = new PageToolbarContributionContext(scope.ServiceProvider); await contributor.ContributeAsync(context);
foreach (var contributor in toolbar.Contributors)
{
await contributor.ContributeAsync(context);
}
return context.Items.OrderBy(i => i.Order).ToArray();
} }
return context.Items.OrderBy(i => i.Order).ToArray();
} }
} }
} }

63
framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/PageToolbars/SimplePageToolbarContributor.cs

@ -4,50 +4,49 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Volo.Abp.AspNetCore.Components.Web.Theming.PageToolbars namespace Volo.Abp.AspNetCore.Components.Web.Theming.PageToolbars;
public class SimplePageToolbarContributor : IPageToolbarContributor
{ {
public class SimplePageToolbarContributor : IPageToolbarContributor public Type ComponentType { get; }
{
public Type ComponentType { get; }
public Dictionary<string, object> Arguments { get; set; } public Dictionary<string, object> Arguments { get; set; }
public int Order { get; } public int Order { get; }
public string RequiredPolicyName { get; } public string RequiredPolicyName { get; }
public SimplePageToolbarContributor( public SimplePageToolbarContributor(
Type componentType, Type componentType,
Dictionary<string, object> arguments = null, Dictionary<string, object> arguments = null,
int order = 0, int order = 0,
string requiredPolicyName = null) string requiredPolicyName = null)
{ {
ComponentType = componentType; ComponentType = componentType;
Arguments = arguments; Arguments = arguments;
Order = order; Order = order;
RequiredPolicyName = requiredPolicyName; RequiredPolicyName = requiredPolicyName;
} }
public async Task ContributeAsync(PageToolbarContributionContext context) public async Task ContributeAsync(PageToolbarContributionContext context)
{
if (await ShouldAddComponentAsync(context))
{ {
if (await ShouldAddComponentAsync(context)) context.Items.Add(new PageToolbarItem(ComponentType, Arguments, Order));
{
context.Items.Add(new PageToolbarItem(ComponentType, Arguments, Order));
}
} }
}
protected virtual async Task<bool> ShouldAddComponentAsync(PageToolbarContributionContext context) protected virtual async Task<bool> ShouldAddComponentAsync(PageToolbarContributionContext context)
{
if (RequiredPolicyName != null)
{ {
if (RequiredPolicyName != null) var authorizationService = context.ServiceProvider.GetRequiredService<IAuthorizationService>();
if (!await authorizationService.IsGrantedAsync(RequiredPolicyName))
{ {
var authorizationService = context.ServiceProvider.GetRequiredService<IAuthorizationService>(); return false;
if (!await authorizationService.IsGrantedAsync(RequiredPolicyName))
{
return false;
}
} }
return true;
} }
return true;
} }
} }

17
framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Routing/AbpRouterOptions.cs

@ -1,16 +1,15 @@
using System.Reflection; using System.Reflection;
namespace Volo.Abp.AspNetCore.Components.Web.Theming.Routing namespace Volo.Abp.AspNetCore.Components.Web.Theming.Routing;
public class AbpRouterOptions
{ {
public class AbpRouterOptions public Assembly AppAssembly { get; set; }
{
public Assembly AppAssembly { get; set; }
public RouterAssemblyList AdditionalAssemblies { get; } public RouterAssemblyList AdditionalAssemblies { get; }
public AbpRouterOptions() public AbpRouterOptions()
{ {
AdditionalAssemblies = new RouterAssemblyList(); AdditionalAssemblies = new RouterAssemblyList();
}
} }
} }

11
framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Routing/RouterAssemblyList.cs

@ -1,10 +1,9 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection; using System.Reflection;
namespace Volo.Abp.AspNetCore.Components.Web.Theming.Routing namespace Volo.Abp.AspNetCore.Components.Web.Theming.Routing;
public class RouterAssemblyList : List<Assembly>
{ {
public class RouterAssemblyList : List<Assembly>
{ }
}
}

17
framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Toolbars/AbpToolbarOptions.cs

@ -1,16 +1,15 @@
using System.Collections.Generic; using System.Collections.Generic;
using JetBrains.Annotations; using JetBrains.Annotations;
namespace Volo.Abp.AspNetCore.Components.Web.Theming.Toolbars namespace Volo.Abp.AspNetCore.Components.Web.Theming.Toolbars;
public class AbpToolbarOptions
{ {
public class AbpToolbarOptions [NotNull]
{ public List<IToolbarContributor> Contributors { get; }
[NotNull]
public List<IToolbarContributor> Contributors { get; }
public AbpToolbarOptions() public AbpToolbarOptions()
{ {
Contributors = new List<IToolbarContributor>(); Contributors = new List<IToolbarContributor>();
}
} }
} }

27
framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Toolbars/IToolbarConfigurationContext.cs

@ -5,25 +5,24 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Localization; using Microsoft.Extensions.Localization;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
namespace Volo.Abp.AspNetCore.Components.Web.Theming.Toolbars namespace Volo.Abp.AspNetCore.Components.Web.Theming.Toolbars;
public interface IToolbarConfigurationContext : IServiceProviderAccessor
{ {
public interface IToolbarConfigurationContext : IServiceProviderAccessor Toolbar Toolbar { get; }
{
Toolbar Toolbar { get; }
IAuthorizationService AuthorizationService { get; } IAuthorizationService AuthorizationService { get; }
IStringLocalizerFactory StringLocalizerFactory { get; } IStringLocalizerFactory StringLocalizerFactory { get; }
Task<bool> IsGrantedAsync(string policyName); Task<bool> IsGrantedAsync(string policyName);
[CanBeNull] [CanBeNull]
IStringLocalizer GetDefaultLocalizer(); IStringLocalizer GetDefaultLocalizer();
[NotNull] [NotNull]
public IStringLocalizer GetLocalizer<T>(); public IStringLocalizer GetLocalizer<T>();
[NotNull] [NotNull]
public IStringLocalizer GetLocalizer(Type resourceType); public IStringLocalizer GetLocalizer(Type resourceType);
}
} }

11
framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Toolbars/IToolbarContributor.cs

@ -1,9 +1,8 @@
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Volo.Abp.AspNetCore.Components.Web.Theming.Toolbars namespace Volo.Abp.AspNetCore.Components.Web.Theming.Toolbars;
public interface IToolbarContributor
{ {
public interface IToolbarContributor Task ConfigureToolbarAsync(IToolbarConfigurationContext context);
{ }
Task ConfigureToolbarAsync(IToolbarConfigurationContext context);
}
}

9
framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Toolbars/IToolbarManager.cs

@ -1,9 +1,8 @@
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Volo.Abp.AspNetCore.Components.Web.Theming.Toolbars namespace Volo.Abp.AspNetCore.Components.Web.Theming.Toolbars;
public interface IToolbarManager
{ {
public interface IToolbarManager Task<Toolbar> GetAsync(string name);
{
Task<Toolbar> GetAsync(string name);
}
} }

11
framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Toolbars/StandardToolbars.cs

@ -1,7 +1,6 @@
namespace Volo.Abp.AspNetCore.Components.Web.Theming.Toolbars namespace Volo.Abp.AspNetCore.Components.Web.Theming.Toolbars;
public static class StandardToolbars
{ {
public static class StandardToolbars public const string Main = "Main";
{ }
public const string Main = "Main";
}
}

19
framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Toolbars/Toolbar.cs

@ -1,18 +1,17 @@
using System.Collections.Generic; using System.Collections.Generic;
using JetBrains.Annotations; using JetBrains.Annotations;
namespace Volo.Abp.AspNetCore.Components.Web.Theming.Toolbars namespace Volo.Abp.AspNetCore.Components.Web.Theming.Toolbars;
public class Toolbar
{ {
public class Toolbar public string Name { get; }
{
public string Name { get; }
public List<ToolbarItem> Items { get; } public List<ToolbarItem> Items { get; }
public Toolbar([NotNull] string name) public Toolbar([NotNull] string name)
{ {
Name = Check.NotNull(name, nameof(name)); Name = Check.NotNull(name, nameof(name));
Items = new List<ToolbarItem>(); Items = new List<ToolbarItem>();
}
} }
} }

65
framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Toolbars/ToolbarConfigurationContext.cs

@ -6,48 +6,47 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Localization; using Microsoft.Extensions.Localization;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
namespace Volo.Abp.AspNetCore.Components.Web.Theming.Toolbars namespace Volo.Abp.AspNetCore.Components.Web.Theming.Toolbars;
public class ToolbarConfigurationContext : IToolbarConfigurationContext
{ {
public class ToolbarConfigurationContext : IToolbarConfigurationContext public IServiceProvider ServiceProvider { get; }
{
public IServiceProvider ServiceProvider { get; }
private readonly IAbpLazyServiceProvider _lazyServiceProvider; private readonly IAbpLazyServiceProvider _lazyServiceProvider;
public IAuthorizationService AuthorizationService => _lazyServiceProvider.LazyGetRequiredService<IAuthorizationService>(); public IAuthorizationService AuthorizationService => _lazyServiceProvider.LazyGetRequiredService<IAuthorizationService>();
public IStringLocalizerFactory StringLocalizerFactory => _lazyServiceProvider.LazyGetRequiredService<IStringLocalizerFactory>(); public IStringLocalizerFactory StringLocalizerFactory => _lazyServiceProvider.LazyGetRequiredService<IStringLocalizerFactory>();
public Toolbar Toolbar { get; } public Toolbar Toolbar { get; }
public ToolbarConfigurationContext(Toolbar toolbar, IServiceProvider serviceProvider) public ToolbarConfigurationContext(Toolbar toolbar, IServiceProvider serviceProvider)
{ {
Toolbar = toolbar; Toolbar = toolbar;
ServiceProvider = serviceProvider; ServiceProvider = serviceProvider;
_lazyServiceProvider = ServiceProvider.GetRequiredService<IAbpLazyServiceProvider>(); _lazyServiceProvider = ServiceProvider.GetRequiredService<IAbpLazyServiceProvider>();
} }
public Task<bool> IsGrantedAsync(string policyName) public Task<bool> IsGrantedAsync(string policyName)
{ {
return AuthorizationService.IsGrantedAsync(policyName); return AuthorizationService.IsGrantedAsync(policyName);
} }
[CanBeNull] [CanBeNull]
public IStringLocalizer GetDefaultLocalizer() public IStringLocalizer GetDefaultLocalizer()
{ {
return StringLocalizerFactory.CreateDefaultOrNull(); return StringLocalizerFactory.CreateDefaultOrNull();
} }
[NotNull] [NotNull]
public IStringLocalizer GetLocalizer<T>() public IStringLocalizer GetLocalizer<T>()
{ {
return StringLocalizerFactory.Create<T>(); return StringLocalizerFactory.Create<T>();
} }
[NotNull] [NotNull]
public IStringLocalizer GetLocalizer(Type resourceType) public IStringLocalizer GetLocalizer(Type resourceType)
{ {
return StringLocalizerFactory.Create(resourceType); return StringLocalizerFactory.Create(resourceType);
}
} }
} }

30
framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Toolbars/ToolbarItem.cs

@ -1,23 +1,21 @@
using System; using System;
using JetBrains.Annotations; using JetBrains.Annotations;
namespace Volo.Abp.AspNetCore.Components.Web.Theming.Toolbars namespace Volo.Abp.AspNetCore.Components.Web.Theming.Toolbars;
public class ToolbarItem
{ {
public class ToolbarItem public Type ComponentType {
{ get => _componentType;
public Type ComponentType set => _componentType = Check.NotNull(value, nameof(value));
{ }
get => _componentType; private Type _componentType;
set => _componentType = Check.NotNull(value, nameof(value));
}
private Type _componentType;
public int Order { get; set; } public int Order { get; set; }
public ToolbarItem([NotNull] Type componentType, int order = 0) public ToolbarItem([NotNull] Type componentType, int order = 0)
{ {
Order = order; Order = order;
ComponentType = Check.NotNull(componentType, nameof(componentType)); ComponentType = Check.NotNull(componentType, nameof(componentType));
}
} }
} }

43
framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Toolbars/ToolbarManager.cs

@ -4,36 +4,35 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
namespace Volo.Abp.AspNetCore.Components.Web.Theming.Toolbars namespace Volo.Abp.AspNetCore.Components.Web.Theming.Toolbars;
public class ToolbarManager : IToolbarManager, ITransientDependency
{ {
public class ToolbarManager : IToolbarManager, ITransientDependency protected AbpToolbarOptions Options { get; }
protected IServiceProvider ServiceProvider { get; }
public ToolbarManager(
IOptions<AbpToolbarOptions> options,
IServiceProvider serviceProvider)
{ {
protected AbpToolbarOptions Options { get; } ServiceProvider = serviceProvider;
protected IServiceProvider ServiceProvider { get; } Options = options.Value;
}
public ToolbarManager( public async Task<Toolbar> GetAsync(string name)
IOptions<AbpToolbarOptions> options, {
IServiceProvider serviceProvider) var toolbar = new Toolbar(name);
{
ServiceProvider = serviceProvider;
Options = options.Value;
}
public async Task<Toolbar> GetAsync(string name) using (var scope = ServiceProvider.CreateScope())
{ {
var toolbar = new Toolbar(name); var context = new ToolbarConfigurationContext(toolbar, scope.ServiceProvider);
using (var scope = ServiceProvider.CreateScope()) foreach (var contributor in Options.Contributors)
{ {
var context = new ToolbarConfigurationContext(toolbar, scope.ServiceProvider); await contributor.ConfigureToolbarAsync(context);
foreach (var contributor in Options.Contributors)
{
await contributor.ConfigureToolbarAsync(context);
}
} }
return toolbar;
} }
return toolbar;
} }
} }

17
framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/AbpAspNetCoreApplicationCreationOptions.cs

@ -1,13 +1,12 @@
namespace Volo.Abp.AspNetCore.Components.Web namespace Volo.Abp.AspNetCore.Components.Web;
public class AbpAspNetCoreApplicationCreationOptions
{ {
public class AbpAspNetCoreApplicationCreationOptions public AbpApplicationCreationOptions ApplicationCreationOptions { get; }
{
public AbpApplicationCreationOptions ApplicationCreationOptions { get; }
public AbpAspNetCoreApplicationCreationOptions( public AbpAspNetCoreApplicationCreationOptions(
AbpApplicationCreationOptions applicationCreationOptions) AbpApplicationCreationOptions applicationCreationOptions)
{ {
ApplicationCreationOptions = applicationCreationOptions; ApplicationCreationOptions = applicationCreationOptions;
}
} }
} }

25
framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/AbpAspNetCoreComponentsWebModule.cs

@ -5,22 +5,21 @@ using Volo.Abp.AspNetCore.Components.DependencyInjection;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
using Volo.Abp.UI; using Volo.Abp.UI;
namespace Volo.Abp.AspNetCore.Components.Web namespace Volo.Abp.AspNetCore.Components.Web;
[DependsOn(
typeof(AbpUiModule),
typeof(AbpAspNetCoreComponentsModule)
)]
public class AbpAspNetCoreComponentsWebModule : AbpModule
{ {
[DependsOn( public override void PreConfigureServices(ServiceConfigurationContext context)
typeof(AbpUiModule),
typeof(AbpAspNetCoreComponentsModule)
)]
public class AbpAspNetCoreComponentsWebModule : AbpModule
{ {
public override void PreConfigureServices(ServiceConfigurationContext context)
{
} }
public override void ConfigureServices(ServiceConfigurationContext context) public override void ConfigureServices(ServiceConfigurationContext context)
{ {
context.Services.Replace(ServiceDescriptor.Transient<IComponentActivator, ServiceProviderComponentActivator>()); context.Services.Replace(ServiceDescriptor.Transient<IComponentActivator, ServiceProviderComponentActivator>());
}
} }
} }

123
framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/AbpBlazorClientHttpMessageHandler.cs

@ -9,90 +9,89 @@ using Microsoft.JSInterop;
using Volo.Abp.AspNetCore.Components.Progression; using Volo.Abp.AspNetCore.Components.Progression;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
namespace Volo.Abp.AspNetCore.Components.Web namespace Volo.Abp.AspNetCore.Components.Web;
public class AbpBlazorClientHttpMessageHandler : DelegatingHandler, ITransientDependency
{ {
public class AbpBlazorClientHttpMessageHandler : DelegatingHandler, ITransientDependency private readonly IJSRuntime _jsRuntime;
{
private readonly IJSRuntime _jsRuntime;
private readonly ICookieService _cookieService; private readonly ICookieService _cookieService;
private readonly NavigationManager _navigationManager; private readonly NavigationManager _navigationManager;
private readonly IUiPageProgressService _uiPageProgressService; private readonly IUiPageProgressService _uiPageProgressService;
private const string AntiForgeryCookieName = "XSRF-TOKEN"; private const string AntiForgeryCookieName = "XSRF-TOKEN";
private const string AntiForgeryHeaderName = "RequestVerificationToken"; private const string AntiForgeryHeaderName = "RequestVerificationToken";
public AbpBlazorClientHttpMessageHandler( public AbpBlazorClientHttpMessageHandler(
IJSRuntime jsRuntime, IJSRuntime jsRuntime,
ICookieService cookieService, ICookieService cookieService,
NavigationManager navigationManager, NavigationManager navigationManager,
IClientScopeServiceProviderAccessor clientScopeServiceProviderAccessor) IClientScopeServiceProviderAccessor clientScopeServiceProviderAccessor)
{ {
_jsRuntime = jsRuntime; _jsRuntime = jsRuntime;
_cookieService = cookieService; _cookieService = cookieService;
_navigationManager = navigationManager; _navigationManager = navigationManager;
_uiPageProgressService = clientScopeServiceProviderAccessor.ServiceProvider.GetRequiredService<IUiPageProgressService>(); _uiPageProgressService = clientScopeServiceProviderAccessor.ServiceProvider.GetRequiredService<IUiPageProgressService>();
} }
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
try
{ {
try await _uiPageProgressService.Go(null, options =>
{ {
await _uiPageProgressService.Go(null, options => options.Type = UiPageProgressType.Info;
{ });
options.Type = UiPageProgressType.Info;
});
await SetLanguageAsync(request, cancellationToken); await SetLanguageAsync(request, cancellationToken);
await SetAntiForgeryTokenAsync(request); await SetAntiForgeryTokenAsync(request);
return await base.SendAsync(request, cancellationToken); return await base.SendAsync(request, cancellationToken);
}
finally
{
await _uiPageProgressService.Go(-1);
}
} }
finally
private async Task SetLanguageAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{ {
var selectedLanguage = await _jsRuntime.InvokeAsync<string>( await _uiPageProgressService.Go(-1);
"localStorage.getItem", }
cancellationToken, }
"Abp.SelectedLanguage"
);
if (!selectedLanguage.IsNullOrWhiteSpace()) private async Task SetLanguageAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{ {
request.Headers.AcceptLanguage.Clear(); var selectedLanguage = await _jsRuntime.InvokeAsync<string>(
request.Headers.AcceptLanguage.Add(new StringWithQualityHeaderValue(selectedLanguage)); "localStorage.getItem",
} cancellationToken,
"Abp.SelectedLanguage"
);
if (!selectedLanguage.IsNullOrWhiteSpace())
{
request.Headers.AcceptLanguage.Clear();
request.Headers.AcceptLanguage.Add(new StringWithQualityHeaderValue(selectedLanguage));
} }
}
private async Task SetAntiForgeryTokenAsync(HttpRequestMessage request) private async Task SetAntiForgeryTokenAsync(HttpRequestMessage request)
{
if (request.Method == HttpMethod.Get || request.Method == HttpMethod.Head ||
request.Method == HttpMethod.Trace || request.Method == HttpMethod.Options)
{ {
if (request.Method == HttpMethod.Get || request.Method == HttpMethod.Head || return;
request.Method == HttpMethod.Trace || request.Method == HttpMethod.Options) }
{
return;
}
var selfUri = new Uri(_navigationManager.Uri); var selfUri = new Uri(_navigationManager.Uri);
if (request.RequestUri.Host != selfUri.Host || request.RequestUri.Port != selfUri.Port) if (request.RequestUri.Host != selfUri.Host || request.RequestUri.Port != selfUri.Port)
{ {
return; return;
} }
var token = await _cookieService.GetAsync(AntiForgeryCookieName); var token = await _cookieService.GetAsync(AntiForgeryCookieName);
if (!token.IsNullOrWhiteSpace()) if (!token.IsNullOrWhiteSpace())
{ {
request.Headers.Add(AntiForgeryHeaderName, token); request.Headers.Add(AntiForgeryHeaderName, token);
}
} }
} }
} }

57
framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/AbpBlazorMessageLocalizerHelper.cs

@ -3,46 +3,45 @@ using System.Linq;
using JetBrains.Annotations; using JetBrains.Annotations;
using Microsoft.Extensions.Localization; using Microsoft.Extensions.Localization;
namespace Volo.Abp.AspNetCore.Components.Web namespace Volo.Abp.AspNetCore.Components.Web;
public class AbpBlazorMessageLocalizerHelper<T>
{ {
public class AbpBlazorMessageLocalizerHelper<T> private readonly IStringLocalizer<T> stringLocalizer;
public AbpBlazorMessageLocalizerHelper(IStringLocalizer<T> stringLocalizer)
{ {
private readonly IStringLocalizer<T> stringLocalizer; this.stringLocalizer = stringLocalizer;
}
public AbpBlazorMessageLocalizerHelper(IStringLocalizer<T> stringLocalizer) public string Localize(string message, [CanBeNull] IEnumerable<string> arguments)
{
try
{ {
this.stringLocalizer = stringLocalizer; return arguments?.Count() > 0
? stringLocalizer[message, LocalizeMessageArguments(arguments)?.ToArray()]
: stringLocalizer[message];
} }
catch
public string Localize(string message, [CanBeNull] IEnumerable<string> arguments)
{ {
try return stringLocalizer[message];
{
return arguments?.Count() > 0
? stringLocalizer[message, LocalizeMessageArguments(arguments)?.ToArray()]
: stringLocalizer[message];
}
catch
{
return stringLocalizer[message];
}
} }
}
private IEnumerable<string> LocalizeMessageArguments(IEnumerable<string> arguments) private IEnumerable<string> LocalizeMessageArguments(IEnumerable<string> arguments)
{
foreach (var argument in arguments)
{ {
foreach (var argument in arguments) // first try to localize with "DisplayName:{Name}"
{ var localization = stringLocalizer[$"DisplayName:{argument}"];
// first try to localize with "DisplayName:{Name}"
var localization = stringLocalizer[$"DisplayName:{argument}"];
if (localization.ResourceNotFound) if (localization.ResourceNotFound)
{ {
// then try to localize with just "{Name}" // then try to localize with just "{Name}"
localization = stringLocalizer[argument]; localization = stringLocalizer[argument];
}
yield return localization;
} }
yield return localization;
} }
} }
} }

87
framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/AbpUtilsService.cs

@ -2,50 +2,49 @@
using Microsoft.JSInterop; using Microsoft.JSInterop;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
namespace Volo.Abp.AspNetCore.Components.Web namespace Volo.Abp.AspNetCore.Components.Web;
public class AbpUtilsService : IAbpUtilsService, ITransientDependency
{ {
public class AbpUtilsService : IAbpUtilsService, ITransientDependency protected IJSRuntime JsRuntime { get; }
{
protected IJSRuntime JsRuntime { get; } public AbpUtilsService(IJSRuntime jsRuntime)
{
public AbpUtilsService(IJSRuntime jsRuntime) JsRuntime = jsRuntime;
{ }
JsRuntime = jsRuntime;
} public ValueTask AddClassToTagAsync(string tagName, string className)
{
public ValueTask AddClassToTagAsync(string tagName, string className) return JsRuntime.InvokeVoidAsync("abp.utils.addClassToTag", tagName, className);
{ }
return JsRuntime.InvokeVoidAsync("abp.utils.addClassToTag", tagName, className);
} public ValueTask RemoveClassFromTagAsync(string tagName, string className)
{
public ValueTask RemoveClassFromTagAsync(string tagName, string className) return JsRuntime.InvokeVoidAsync("abp.utils.removeClassFromTag", tagName, className);
{ }
return JsRuntime.InvokeVoidAsync("abp.utils.removeClassFromTag", tagName, className);
} public ValueTask<bool> HasClassOnTagAsync(string tagName, string className)
{
public ValueTask<bool> HasClassOnTagAsync(string tagName, string className) return JsRuntime.InvokeAsync<bool>("abp.utils.hasClassOnTag", tagName, className);
{ }
return JsRuntime.InvokeAsync<bool>("abp.utils.hasClassOnTag", tagName, className);
} public ValueTask ReplaceLinkHrefByIdAsync(string linkId, string hrefValue)
{
public ValueTask ReplaceLinkHrefByIdAsync(string linkId, string hrefValue) return JsRuntime.InvokeVoidAsync("abp.utils.replaceLinkHrefById", linkId, hrefValue);
{ }
return JsRuntime.InvokeVoidAsync("abp.utils.replaceLinkHrefById", linkId, hrefValue);
} public ValueTask ToggleFullscreenAsync()
{
public ValueTask ToggleFullscreenAsync() return JsRuntime.InvokeVoidAsync("abp.utils.toggleFullscreen");
{ }
return JsRuntime.InvokeVoidAsync("abp.utils.toggleFullscreen");
} public ValueTask RequestFullscreenAsync()
{
public ValueTask RequestFullscreenAsync() return JsRuntime.InvokeVoidAsync("abp.utils.requestFullscreen");
{ }
return JsRuntime.InvokeVoidAsync("abp.utils.requestFullscreen");
} public ValueTask ExitFullscreenAsync()
{
public ValueTask ExitFullscreenAsync() return JsRuntime.InvokeVoidAsync("abp.utils.exitFullscreen");
{
return JsRuntime.InvokeVoidAsync("abp.utils.exitFullscreen");
}
} }
} }

17
framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/Alerts/AlertManager.cs

@ -1,15 +1,14 @@
using Volo.Abp.AspNetCore.Components.Alerts; using Volo.Abp.AspNetCore.Components.Alerts;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
namespace Volo.Abp.AspNetCore.Components.Web.Alerts namespace Volo.Abp.AspNetCore.Components.Web.Alerts;
public class AlertManager : IAlertManager, IScopedDependency
{ {
public class AlertManager : IAlertManager, IScopedDependency public AlertList Alerts { get; }
{
public AlertList Alerts { get; }
public AlertManager() public AlertManager()
{ {
Alerts = new AlertList(); Alerts = new AlertList();
}
} }
} }

11
framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/Configuration/ICurrentApplicationConfigurationCacheResetService.cs

@ -1,9 +1,8 @@
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Volo.Abp.AspNetCore.Components.Web.Configuration namespace Volo.Abp.AspNetCore.Components.Web.Configuration;
public interface ICurrentApplicationConfigurationCacheResetService
{ {
public interface ICurrentApplicationConfigurationCacheResetService Task ResetAsync();
{ }
Task ResetAsync();
}
}

13
framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/Configuration/NullCurrentApplicationConfigurationCacheResetService.cs

@ -1,13 +1,12 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
namespace Volo.Abp.AspNetCore.Components.Web.Configuration namespace Volo.Abp.AspNetCore.Components.Web.Configuration;
public class NullCurrentApplicationConfigurationCacheResetService : ICurrentApplicationConfigurationCacheResetService, ISingletonDependency
{ {
public class NullCurrentApplicationConfigurationCacheResetService : ICurrentApplicationConfigurationCacheResetService, ISingletonDependency public Task ResetAsync()
{ {
public Task ResetAsync() return Task.CompletedTask;
{
return Task.CompletedTask;
}
} }
} }

15
framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/CookieOptions.cs

@ -1,11 +1,10 @@
using System; using System;
namespace Volo.Abp.AspNetCore.Components.Web namespace Volo.Abp.AspNetCore.Components.Web;
public class CookieOptions
{ {
public class CookieOptions public DateTimeOffset? ExpireDate { get; set; }
{ public string Path { get; set; }
public DateTimeOffset? ExpireDate { get; set; } public bool Secure { get; set; }
public string Path { get; set; } }
public bool Secure { get; set; }
}
}

43
framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/CookieService.cs

@ -2,31 +2,30 @@
using Microsoft.JSInterop; using Microsoft.JSInterop;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
namespace Volo.Abp.AspNetCore.Components.Web namespace Volo.Abp.AspNetCore.Components.Web;
[Dependency(ReplaceServices = true)]
public class CookieService : ICookieService, ITransientDependency
{ {
[Dependency(ReplaceServices = true)] public IJSRuntime JsRuntime { get; }
public class CookieService : ICookieService, ITransientDependency
{
public IJSRuntime JsRuntime { get; }
public CookieService(IJSRuntime jsRuntime) public CookieService(IJSRuntime jsRuntime)
{ {
JsRuntime = jsRuntime; JsRuntime = jsRuntime;
} }
public async ValueTask SetAsync(string key, string value, CookieOptions options) public async ValueTask SetAsync(string key, string value, CookieOptions options)
{ {
await JsRuntime.InvokeVoidAsync("abp.utils.setCookieValue", key, value, options?.ExpireDate?.ToString("r"), options?.Path, options?.Secure); await JsRuntime.InvokeVoidAsync("abp.utils.setCookieValue", key, value, options?.ExpireDate?.ToString("r"), options?.Path, options?.Secure);
} }
public async ValueTask<string> GetAsync(string key) public async ValueTask<string> GetAsync(string key)
{ {
return await JsRuntime.InvokeAsync<string>("abp.utils.getCookieValue", key); return await JsRuntime.InvokeAsync<string>("abp.utils.getCookieValue", key);
} }
public async ValueTask DeleteAsync(string key, string path = null) public async ValueTask DeleteAsync(string key, string path = null)
{ {
await JsRuntime.InvokeVoidAsync("abp.utils.deleteCookie", key); await JsRuntime.InvokeVoidAsync("abp.utils.deleteCookie", key);
}
} }
} }

13
framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/DefaultServerUrlProvider.cs

@ -1,13 +1,12 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
namespace Volo.Abp.AspNetCore.Components.Web namespace Volo.Abp.AspNetCore.Components.Web;
public class DefaultServerUrlProvider : IServerUrlProvider, ISingletonDependency
{ {
public class DefaultServerUrlProvider : IServerUrlProvider, ISingletonDependency public Task<string> GetBaseUrlAsync(string remoteServiceName = null)
{ {
public Task<string> GetBaseUrlAsync(string remoteServiceName = null) return Task.FromResult("/");
{
return Task.FromResult("/");
}
} }
} }

13
framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/DependencyInjection/ComponentsClientScopeServiceProviderAccessor.cs

@ -1,12 +1,11 @@
using System; using System;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
namespace Volo.Abp.AspNetCore.Components.Web.DependencyInjection namespace Volo.Abp.AspNetCore.Components.Web.DependencyInjection;
public class ComponentsClientScopeServiceProviderAccessor :
IClientScopeServiceProviderAccessor,
ISingletonDependency
{ {
public class ComponentsClientScopeServiceProviderAccessor : public IServiceProvider ServiceProvider { get; set; }
IClientScopeServiceProviderAccessor,
ISingletonDependency
{
public IServiceProvider ServiceProvider { get; set; }
}
} }

87
framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/ExceptionHandling/AbpExceptionHandlingLogger.cs

@ -3,64 +3,63 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Volo.Abp.AspNetCore.Components.ExceptionHandling; using Volo.Abp.AspNetCore.Components.ExceptionHandling;
namespace Volo.Abp.AspNetCore.Components.Web.ExceptionHandling namespace Volo.Abp.AspNetCore.Components.Web.ExceptionHandling;
public class AbpExceptionHandlingLogger : ILogger
{ {
public class AbpExceptionHandlingLogger : ILogger private readonly IServiceCollection _serviceCollection;
private IUserExceptionInformer _userExceptionInformer;
public AbpExceptionHandlingLogger(IServiceCollection serviceCollection)
{ {
private readonly IServiceCollection _serviceCollection; _serviceCollection = serviceCollection;
private IUserExceptionInformer _userExceptionInformer; }
public AbpExceptionHandlingLogger(IServiceCollection serviceCollection) public virtual void Log<TState>(
LogLevel logLevel,
EventId eventId,
TState state,
Exception exception,
Func<TState, Exception, string> formatter)
{
if (exception == null)
{ {
_serviceCollection = serviceCollection; return;
} }
public virtual void Log<TState>( if (logLevel != LogLevel.Critical && logLevel != LogLevel.Error)
LogLevel logLevel,
EventId eventId,
TState state,
Exception exception,
Func<TState, Exception, string> formatter)
{ {
if (exception == null) return;
{
return;
}
if (logLevel != LogLevel.Critical && logLevel != LogLevel.Error)
{
return;
}
TryInitialize();
if (_userExceptionInformer == null)
{
return;
}
_userExceptionInformer.Inform(new UserExceptionInformerContext(exception));
} }
protected virtual void TryInitialize() TryInitialize();
{
var serviceProvider = _serviceCollection.GetServiceProviderOrNull();
if (serviceProvider == null)
{
return;
}
_userExceptionInformer = serviceProvider.GetRequiredService<IUserExceptionInformer>();
}
public virtual bool IsEnabled(LogLevel logLevel) if (_userExceptionInformer == null)
{ {
return logLevel == LogLevel.Critical || logLevel == LogLevel.Error; return;
} }
public virtual IDisposable BeginScope<TState>(TState state) _userExceptionInformer.Inform(new UserExceptionInformerContext(exception));
}
protected virtual void TryInitialize()
{
var serviceProvider = _serviceCollection.GetServiceProviderOrNull();
if (serviceProvider == null)
{ {
return NullDisposable.Instance; return;
} }
_userExceptionInformer = serviceProvider.GetRequiredService<IUserExceptionInformer>();
}
public virtual bool IsEnabled(LogLevel logLevel)
{
return logLevel == LogLevel.Critical || logLevel == LogLevel.Error;
}
public virtual IDisposable BeginScope<TState>(TState state)
{
return NullDisposable.Instance;
} }
} }

43
framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/ExceptionHandling/AbpExceptionHandlingLoggerProvider.cs

@ -1,38 +1,37 @@
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace Volo.Abp.AspNetCore.Components.Web.ExceptionHandling namespace Volo.Abp.AspNetCore.Components.Web.ExceptionHandling;
public class AbpExceptionHandlingLoggerProvider : ILoggerProvider
{ {
public class AbpExceptionHandlingLoggerProvider : ILoggerProvider private AbpExceptionHandlingLogger _logger;
{ private static readonly object SyncObj = new object();
private AbpExceptionHandlingLogger _logger; private readonly IServiceCollection _serviceCollection;
private static readonly object SyncObj = new object();
private readonly IServiceCollection _serviceCollection;
public AbpExceptionHandlingLoggerProvider(IServiceCollection serviceCollection) public AbpExceptionHandlingLoggerProvider(IServiceCollection serviceCollection)
{ {
_serviceCollection = serviceCollection; _serviceCollection = serviceCollection;
} }
public ILogger CreateLogger(string categoryName) public ILogger CreateLogger(string categoryName)
{
if (_logger == null)
{ {
if (_logger == null) lock (SyncObj)
{ {
lock (SyncObj) if (_logger == null)
{ {
if (_logger == null) _logger = new AbpExceptionHandlingLogger(_serviceCollection);
{
_logger = new AbpExceptionHandlingLogger(_serviceCollection);
}
} }
} }
return _logger;
} }
public void Dispose() return _logger;
{ }
public void Dispose()
{
}
} }
} }

91
framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/ExceptionHandling/UserExceptionInformer.cs

@ -9,65 +9,64 @@ using Volo.Abp.AspNetCore.ExceptionHandling;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.Http; using Volo.Abp.Http;
namespace Volo.Abp.AspNetCore.Components.Web.ExceptionHandling namespace Volo.Abp.AspNetCore.Components.Web.ExceptionHandling;
[Dependency(ReplaceServices = true)]
public class UserExceptionInformer : IUserExceptionInformer, IScopedDependency
{ {
[Dependency(ReplaceServices = true)] public ILogger<UserExceptionInformer> Logger { get; set; }
public class UserExceptionInformer : IUserExceptionInformer, IScopedDependency protected IUiMessageService MessageService { get; }
protected IExceptionToErrorInfoConverter ExceptionToErrorInfoConverter { get; }
protected AbpExceptionHandlingOptions Options { get; }
public UserExceptionInformer(
IUiMessageService messageService,
IExceptionToErrorInfoConverter exceptionToErrorInfoConverter,
IOptions<AbpExceptionHandlingOptions> options)
{
MessageService = messageService;
ExceptionToErrorInfoConverter = exceptionToErrorInfoConverter;
Options = options.Value;
Logger = NullLogger<UserExceptionInformer>.Instance;
}
public void Inform(UserExceptionInformerContext context)
{ {
public ILogger<UserExceptionInformer> Logger { get; set; } //TODO: Create sync versions of the MessageService APIs.
protected IUiMessageService MessageService { get; }
protected IExceptionToErrorInfoConverter ExceptionToErrorInfoConverter { get; }
protected AbpExceptionHandlingOptions Options { get; } var errorInfo = GetErrorInfo(context);
public UserExceptionInformer( if (errorInfo.Details.IsNullOrEmpty())
IUiMessageService messageService,
IExceptionToErrorInfoConverter exceptionToErrorInfoConverter,
IOptions<AbpExceptionHandlingOptions> options)
{ {
MessageService = messageService; MessageService.Error(errorInfo.Message);
ExceptionToErrorInfoConverter = exceptionToErrorInfoConverter;
Options = options.Value;
Logger = NullLogger<UserExceptionInformer>.Instance;
} }
else
public void Inform(UserExceptionInformerContext context)
{ {
//TODO: Create sync versions of the MessageService APIs. MessageService.Error(errorInfo.Details, errorInfo.Message);
}
}
var errorInfo = GetErrorInfo(context); public async Task InformAsync(UserExceptionInformerContext context)
{
var errorInfo = GetErrorInfo(context);
if (errorInfo.Details.IsNullOrEmpty()) if (errorInfo.Details.IsNullOrEmpty())
{ {
MessageService.Error(errorInfo.Message); await MessageService.Error(errorInfo.Message);
}
else
{
MessageService.Error(errorInfo.Details, errorInfo.Message);
}
} }
else
public async Task InformAsync(UserExceptionInformerContext context)
{ {
var errorInfo = GetErrorInfo(context); await MessageService.Error(errorInfo.Details, errorInfo.Message);
if (errorInfo.Details.IsNullOrEmpty())
{
await MessageService.Error(errorInfo.Message);
}
else
{
await MessageService.Error(errorInfo.Details, errorInfo.Message);
}
} }
}
protected virtual RemoteServiceErrorInfo GetErrorInfo(UserExceptionInformerContext context) protected virtual RemoteServiceErrorInfo GetErrorInfo(UserExceptionInformerContext context)
{
return ExceptionToErrorInfoConverter.Convert(context.Exception, options =>
{ {
return ExceptionToErrorInfoConverter.Convert(context.Exception, options => options.SendExceptionsDetailsToClients = Options.SendExceptionsDetailsToClients;
{ options.SendStackTraceToClients = Options.SendStackTraceToClients;
options.SendExceptionsDetailsToClients = Options.SendExceptionsDetailsToClients; });
options.SendStackTraceToClients = Options.SendStackTraceToClients;
});
}
} }
} }

25
framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/Extensibility/EntityActions/EntityAction.cs

@ -1,20 +1,19 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Volo.Abp.AspNetCore.Components.Web.Extensibility.EntityActions namespace Volo.Abp.AspNetCore.Components.Web.Extensibility.EntityActions;
public class EntityAction : IEquatable<EntityAction>
{ {
public class EntityAction : IEquatable<EntityAction> public string Text { get; set; }
public Func<object, Task> Clicked { get; set; }
public Func<object, string> ConfirmationMessage { get; set; }
public bool Primary { get; set; }
public object Color { get; set; }
public string Icon { get; set; }
public Func<object, bool> Visible { get; set; }
public bool Equals(EntityAction other)
{ {
public string Text { get; set; } return string.Equals(Text, other?.Text, StringComparison.OrdinalIgnoreCase);
public Func<object, Task> Clicked { get; set; }
public Func<object, string> ConfirmationMessage { get; set; }
public bool Primary { get; set; }
public object Color { get; set; }
public string Icon { get; set; }
public Func<object, bool> Visible { get; set; }
public bool Equals(EntityAction other)
{
return string.Equals(Text, other?.Text, StringComparison.OrdinalIgnoreCase);
}
} }
} }

13
framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/Extensibility/EntityActions/EntityActionDictionary.cs

@ -1,12 +1,11 @@
using System.Collections.Generic; using System.Collections.Generic;
namespace Volo.Abp.AspNetCore.Components.Web.Extensibility.EntityActions namespace Volo.Abp.AspNetCore.Components.Web.Extensibility.EntityActions;
public class EntityActionDictionary : Dictionary<string, List<EntityAction>>
{ {
public class EntityActionDictionary : Dictionary<string, List<EntityAction>> public List<EntityAction> Get<T>()
{ {
public List<EntityAction> Get<T>() return this.GetOrAdd(typeof(T).FullName, () => new List<EntityAction>());
{
return this.GetOrAdd(typeof(T).FullName, () => new List<EntityAction>());
}
} }
} }

11
framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/Extensibility/ILookupApiRequestService.cs

@ -1,10 +1,9 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using JetBrains.Annotations; using JetBrains.Annotations;
namespace Volo.Abp.AspNetCore.Components.Web.Extensibility namespace Volo.Abp.AspNetCore.Components.Web.Extensibility;
public interface ILookupApiRequestService
{ {
public interface ILookupApiRequestService Task<string> SendAsync([NotNull] string url);
{ }
Task<string> SendAsync([NotNull]string url);
}
}

37
framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/Extensibility/TableColumns/TableColumn.cs

@ -4,25 +4,24 @@ using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using Volo.Abp.AspNetCore.Components.Web.Extensibility.EntityActions; using Volo.Abp.AspNetCore.Components.Web.Extensibility.EntityActions;
namespace Volo.Abp.AspNetCore.Components.Web.Extensibility.TableColumns namespace Volo.Abp.AspNetCore.Components.Web.Extensibility.TableColumns;
public class TableColumn
{ {
public class TableColumn public string Title { get; set; }
{ public string Data { get; set; }
public string Title { get; set; } [CanBeNull]
public string Data { get; set; } public string DisplayFormat { get; set; }
[CanBeNull] public IFormatProvider DisplayFormatProvider { get; set; } = CultureInfo.CurrentCulture;
public string DisplayFormat { get; set; } [CanBeNull]
public IFormatProvider DisplayFormatProvider { get; set; } = CultureInfo.CurrentCulture; public Type Component { get; set; }
[CanBeNull] public List<EntityAction> Actions { get; set; }
public Type Component { get; set; } [CanBeNull]
public List<EntityAction> Actions { get; set; } public Func<object, string> ValueConverter { get; set; }
[CanBeNull] public bool Sortable { get; set; }
public Func<object,string> ValueConverter { get; set; }
public bool Sortable { get; set; }
public TableColumn() public TableColumn()
{ {
Actions = new List<EntityAction>(); Actions = new List<EntityAction>();
}
} }
} }

13
framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/Extensibility/TableColumns/TableColumnDictionary.cs

@ -1,12 +1,11 @@
using System.Collections.Generic; using System.Collections.Generic;
namespace Volo.Abp.AspNetCore.Components.Web.Extensibility.TableColumns namespace Volo.Abp.AspNetCore.Components.Web.Extensibility.TableColumns;
public class TableColumnDictionary : Dictionary<string, List<TableColumn>>
{ {
public class TableColumnDictionary : Dictionary<string, List<TableColumn>> public List<TableColumn> Get<T>()
{ {
public List<TableColumn> Get<T>() return this.GetOrAdd(typeof(T).FullName, () => new List<TableColumn>());
{
return this.GetOrAdd(typeof(T).FullName, () => new List<TableColumn>());
}
} }
} }

21
framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/IAbpUtilsService.cs

@ -1,21 +1,20 @@
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Volo.Abp.AspNetCore.Components.Web namespace Volo.Abp.AspNetCore.Components.Web;
public interface IAbpUtilsService
{ {
public interface IAbpUtilsService ValueTask AddClassToTagAsync(string tagName, string className);
{
ValueTask AddClassToTagAsync(string tagName, string className);
ValueTask RemoveClassFromTagAsync(string tagName, string className); ValueTask RemoveClassFromTagAsync(string tagName, string className);
ValueTask<bool> HasClassOnTagAsync(string tagName, string className); ValueTask<bool> HasClassOnTagAsync(string tagName, string className);
ValueTask ReplaceLinkHrefByIdAsync(string linkId, string hrefValue); ValueTask ReplaceLinkHrefByIdAsync(string linkId, string hrefValue);
ValueTask ToggleFullscreenAsync(); ValueTask ToggleFullscreenAsync();
ValueTask RequestFullscreenAsync(); ValueTask RequestFullscreenAsync();
ValueTask ExitFullscreenAsync(); ValueTask ExitFullscreenAsync();
}
} }

15
framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/ICookieService.cs

@ -1,11 +1,10 @@
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Volo.Abp.AspNetCore.Components.Web namespace Volo.Abp.AspNetCore.Components.Web;
public interface ICookieService
{ {
public interface ICookieService public ValueTask SetAsync(string key, string value, CookieOptions options = null);
{ public ValueTask<string> GetAsync(string key);
public ValueTask SetAsync(string key, string value, CookieOptions options = null); public ValueTask DeleteAsync(string key, string path = null);
public ValueTask<string> GetAsync(string key); }
public ValueTask DeleteAsync(string key, string path = null);
}
}

11
framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/IServerUrlProvider.cs

@ -1,9 +1,8 @@
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Volo.Abp.AspNetCore.Components.Web namespace Volo.Abp.AspNetCore.Components.Web;
public interface IServerUrlProvider
{ {
public interface IServerUrlProvider Task<string> GetBaseUrlAsync(string remoteServiceName = null);
{ }
Task<string> GetBaseUrlAsync(string remoteServiceName = null);
}
}

65
framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/Messages/SimpleUiMessageService.cs

@ -4,40 +4,39 @@ using Microsoft.JSInterop;
using Volo.Abp.AspNetCore.Components.Messages; using Volo.Abp.AspNetCore.Components.Messages;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
namespace Volo.Abp.AspNetCore.Components.Web.Messages namespace Volo.Abp.AspNetCore.Components.Web.Messages;
public class SimpleUiMessageService : IUiMessageService, ITransientDependency
{ {
public class SimpleUiMessageService : IUiMessageService, ITransientDependency protected IJSRuntime JsRuntime { get; }
public SimpleUiMessageService(IJSRuntime jsRuntime)
{
JsRuntime = jsRuntime;
}
public async Task Info(string message, string title = null, Action<UiMessageOptions> options = null)
{
await JsRuntime.InvokeVoidAsync("alert", message);
}
public async Task Success(string message, string title = null, Action<UiMessageOptions> options = null)
{
await JsRuntime.InvokeVoidAsync("alert", message);
}
public async Task Warn(string message, string title = null, Action<UiMessageOptions> options = null)
{
await JsRuntime.InvokeVoidAsync("alert", message);
}
public async Task Error(string message, string title = null, Action<UiMessageOptions> options = null)
{
await JsRuntime.InvokeVoidAsync("alert", message);
}
public async Task<bool> Confirm(string message, string title = null, Action<UiMessageOptions> options = null)
{ {
protected IJSRuntime JsRuntime { get; } return await JsRuntime.InvokeAsync<bool>("confirm", message);
public SimpleUiMessageService(IJSRuntime jsRuntime)
{
JsRuntime = jsRuntime;
}
public async Task Info(string message, string title = null, Action<UiMessageOptions> options = null)
{
await JsRuntime.InvokeVoidAsync("alert", message);
}
public async Task Success(string message, string title = null, Action<UiMessageOptions> options = null)
{
await JsRuntime.InvokeVoidAsync("alert", message);
}
public async Task Warn(string message, string title = null, Action<UiMessageOptions> options = null)
{
await JsRuntime.InvokeVoidAsync("alert", message);
}
public async Task Error(string message, string title = null, Action<UiMessageOptions> options = null)
{
await JsRuntime.InvokeVoidAsync("alert", message);
}
public async Task<bool> Confirm(string message, string title = null, Action<UiMessageOptions> options = null)
{
return await JsRuntime.InvokeAsync<bool>("confirm", message);
}
} }
} }

49
framework/src/Volo.Abp.AspNetCore.Components.Web/Volo/Abp/AspNetCore/Components/Web/Security/AbpComponentsClaimsCache.cs

@ -5,39 +5,38 @@ using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
namespace Volo.Abp.AspNetCore.Components.Web.Security namespace Volo.Abp.AspNetCore.Components.Web.Security;
[ExposeServices(
typeof(AbpComponentsClaimsCache),
typeof(IAsyncInitialize)
)]
public class AbpComponentsClaimsCache : IScopedDependency, IAsyncInitialize
{ {
[ExposeServices( public ClaimsPrincipal Principal { get; private set; }
typeof(AbpComponentsClaimsCache),
typeof(IAsyncInitialize)
)]
public class AbpComponentsClaimsCache : IScopedDependency, IAsyncInitialize
{
public ClaimsPrincipal Principal { get; private set; }
[CanBeNull] [CanBeNull]
private readonly AuthenticationStateProvider _authenticationStateProvider; private readonly AuthenticationStateProvider _authenticationStateProvider;
public AbpComponentsClaimsCache( public AbpComponentsClaimsCache(
IClientScopeServiceProviderAccessor serviceProviderAccessor) IClientScopeServiceProviderAccessor serviceProviderAccessor)
{
_authenticationStateProvider = serviceProviderAccessor.ServiceProvider.GetService<AuthenticationStateProvider>();
if (_authenticationStateProvider != null)
{ {
_authenticationStateProvider = serviceProviderAccessor.ServiceProvider.GetService<AuthenticationStateProvider>(); _authenticationStateProvider.AuthenticationStateChanged += async (task) =>
if (_authenticationStateProvider != null)
{ {
_authenticationStateProvider.AuthenticationStateChanged += async (task) => Principal = (await task).User;
{ };
Principal = (await task).User;
};
}
} }
}
public virtual async Task InitializeAsync() public virtual async Task InitializeAsync()
{
if (_authenticationStateProvider != null)
{ {
if (_authenticationStateProvider != null) var authenticationState = await _authenticationStateProvider.GetAuthenticationStateAsync();
{ Principal = authenticationState.User;
var authenticationState = await _authenticationStateProvider.GetAuthenticationStateAsync();
Principal = authenticationState.User;
}
} }
} }
} }

15
framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/AbpAspNetCoreComponentsWebAssemblyThemingModule.cs

@ -1,14 +1,13 @@
using Volo.Abp.AspNetCore.Components.Web.Theming; using Volo.Abp.AspNetCore.Components.Web.Theming;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
namespace Volo.Abp.AspNetCore.Components.WebAssembly.Theming namespace Volo.Abp.AspNetCore.Components.WebAssembly.Theming;
[DependsOn(
typeof(AbpAspNetCoreComponentsWebThemingModule),
typeof(AbpAspNetCoreComponentsWebAssemblyModule)
)]
public class AbpAspNetCoreComponentsWebAssemblyThemingModule : AbpModule
{ {
[DependsOn(
typeof(AbpAspNetCoreComponentsWebThemingModule),
typeof(AbpAspNetCoreComponentsWebAssemblyModule)
)]
public class AbpAspNetCoreComponentsWebAssemblyThemingModule : AbpModule
{
}
} }

43
framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/ComponentsComponentsBundleContributor.cs

@ -1,31 +1,30 @@
using Volo.Abp.Bundling; using Volo.Abp.Bundling;
namespace Volo.Abp.AspNetCore.Components.WebAssembly.Theming namespace Volo.Abp.AspNetCore.Components.WebAssembly.Theming;
public class ComponentsComponentsBundleContributor : IBundleContributor
{ {
public class ComponentsComponentsBundleContributor : IBundleContributor public void AddScripts(BundleContext context)
{ {
public void AddScripts(BundleContext context) context.Add("_content/Microsoft.AspNetCore.Components.WebAssembly.Authentication/AuthenticationService.js");
{ context.Add("_content/Volo.Abp.AspNetCore.Components.Web/libs/abp/js/abp.js");
context.Add("_content/Microsoft.AspNetCore.Components.WebAssembly.Authentication/AuthenticationService.js"); context.Add("_content/Volo.Abp.AspNetCore.Components.Web/libs/abp/js/lang-utils.js");
context.Add("_content/Volo.Abp.AspNetCore.Components.Web/libs/abp/js/abp.js"); }
context.Add("_content/Volo.Abp.AspNetCore.Components.Web/libs/abp/js/lang-utils.js");
}
public void AddStyles(BundleContext context) public void AddStyles(BundleContext context)
{
context.BundleDefinitions.Insert(0, new BundleDefinition
{
Source = "_content/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/libs/bootstrap/css/bootstrap.min.css"
});
context.BundleDefinitions.Insert(1, new BundleDefinition
{ {
context.BundleDefinitions.Insert(0, new BundleDefinition Source = "_content/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/libs/fontawesome/css/all.css"
{ });
Source = "_content/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/libs/bootstrap/css/bootstrap.min.css"
});
context.BundleDefinitions.Insert(1, new BundleDefinition
{
Source = "_content/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/libs/fontawesome/css/all.css"
});
context.Add("_content/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/libs/flag-icon/css/flag-icon.css"); context.Add("_content/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/libs/flag-icon/css/flag-icon.css");
context.Add("_content/Blazorise/blazorise.css"); context.Add("_content/Blazorise/blazorise.css");
context.Add("_content/Blazorise.Bootstrap5/blazorise.bootstrap5.css"); context.Add("_content/Blazorise.Bootstrap5/blazorise.bootstrap5.css");
context.Add("_content/Blazorise.Snackbar/blazorise.snackbar.css"); context.Add("_content/Blazorise.Snackbar/blazorise.snackbar.css");
}
} }
} }

105
framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Microsoft/AspNetCore/Components/WebAssembly/Hosting/AbpWebAssemblyHostBuilderExtensions.cs

@ -13,74 +13,73 @@ using Volo.Abp.AspNetCore.Mvc.Client;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
namespace Microsoft.AspNetCore.Components.WebAssembly.Hosting namespace Microsoft.AspNetCore.Components.WebAssembly.Hosting;
public static class AbpWebAssemblyHostBuilderExtensions
{ {
public static class AbpWebAssemblyHostBuilderExtensions public static IAbpApplicationWithExternalServiceProvider AddApplication<TStartupModule>(
[NotNull] this WebAssemblyHostBuilder builder,
Action<AbpWebAssemblyApplicationCreationOptions> options)
where TStartupModule : IAbpModule
{ {
public static IAbpApplicationWithExternalServiceProvider AddApplication<TStartupModule>( Check.NotNull(builder, nameof(builder));
[NotNull] this WebAssemblyHostBuilder builder,
Action<AbpWebAssemblyApplicationCreationOptions> options)
where TStartupModule : IAbpModule
{
Check.NotNull(builder, nameof(builder));
// Related this commit(https://github.com/dotnet/aspnetcore/commit/b99d805bc037fcac56afb79abeb7d5a43141c85e) // Related this commit(https://github.com/dotnet/aspnetcore/commit/b99d805bc037fcac56afb79abeb7d5a43141c85e)
// Microsoft.AspNetCore.Blazor.BuildTools has been removed in net 5.0. // Microsoft.AspNetCore.Blazor.BuildTools has been removed in net 5.0.
// This call may be removed when we find a suitable solution. // This call may be removed when we find a suitable solution.
// System.Runtime.CompilerServices.AsyncStateMachineAttribute // System.Runtime.CompilerServices.AsyncStateMachineAttribute
Castle.DynamicProxy.Generators.AttributesToAvoidReplicating.Add<AsyncStateMachineAttribute>(); Castle.DynamicProxy.Generators.AttributesToAvoidReplicating.Add<AsyncStateMachineAttribute>();
builder.Services.AddSingleton<IConfiguration>(builder.Configuration); builder.Services.AddSingleton<IConfiguration>(builder.Configuration);
builder.Services.AddSingleton(builder); builder.Services.AddSingleton(builder);
var application = builder.Services.AddApplication<TStartupModule>(opts => var application = builder.Services.AddApplication<TStartupModule>(opts =>
{ {
options?.Invoke(new AbpWebAssemblyApplicationCreationOptions(builder, opts)); options?.Invoke(new AbpWebAssemblyApplicationCreationOptions(builder, opts));
}); });
return application; return application;
} }
public static async Task InitializeAsync( public static async Task InitializeAsync(
[NotNull] this IAbpApplicationWithExternalServiceProvider application, [NotNull] this IAbpApplicationWithExternalServiceProvider application,
[NotNull] IServiceProvider serviceProvider) [NotNull] IServiceProvider serviceProvider)
{ {
Check.NotNull(application, nameof(application)); Check.NotNull(application, nameof(application));
Check.NotNull(serviceProvider, nameof(serviceProvider)); Check.NotNull(serviceProvider, nameof(serviceProvider));
((ComponentsClientScopeServiceProviderAccessor) serviceProvider ((ComponentsClientScopeServiceProviderAccessor)serviceProvider
.GetRequiredService<IClientScopeServiceProviderAccessor>()).ServiceProvider = serviceProvider; .GetRequiredService<IClientScopeServiceProviderAccessor>()).ServiceProvider = serviceProvider;
application.Initialize(serviceProvider); application.Initialize(serviceProvider);
await InitializeModulesAsync(serviceProvider); await InitializeModulesAsync(serviceProvider);
await SetCurrentLanguageAsync(serviceProvider); await SetCurrentLanguageAsync(serviceProvider);
} }
private static async Task InitializeModulesAsync(IServiceProvider serviceProvider) private static async Task InitializeModulesAsync(IServiceProvider serviceProvider)
{
foreach (var service in serviceProvider.GetServices<IAsyncInitialize>())
{ {
foreach (var service in serviceProvider.GetServices<IAsyncInitialize>()) await service.InitializeAsync();
{
await service.InitializeAsync();
}
} }
}
private static async Task SetCurrentLanguageAsync(IServiceProvider serviceProvider) private static async Task SetCurrentLanguageAsync(IServiceProvider serviceProvider)
{
var configurationClient = serviceProvider.GetRequiredService<ICachedApplicationConfigurationClient>();
var utilsService = serviceProvider.GetRequiredService<IAbpUtilsService>();
var configuration = await configurationClient.GetAsync();
var cultureName = configuration.Localization?.CurrentCulture?.CultureName;
if (!cultureName.IsNullOrEmpty())
{ {
var configurationClient = serviceProvider.GetRequiredService<ICachedApplicationConfigurationClient>(); var culture = new CultureInfo(cultureName);
var utilsService = serviceProvider.GetRequiredService<IAbpUtilsService>(); CultureInfo.DefaultThreadCurrentCulture = culture;
var configuration = await configurationClient.GetAsync(); CultureInfo.DefaultThreadCurrentUICulture = culture;
var cultureName = configuration.Localization?.CurrentCulture?.CultureName; }
if (!cultureName.IsNullOrEmpty())
{
var culture = new CultureInfo(cultureName);
CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;
}
if (CultureInfo.CurrentUICulture.TextInfo.IsRightToLeft) if (CultureInfo.CurrentUICulture.TextInfo.IsRightToLeft)
{ {
await utilsService.AddClassToTagAsync("body", "rtl"); await utilsService.AddClassToTagAsync("body", "rtl");
}
} }
} }
} }

15
framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Microsoft/Extensions/DependencyInjection/AbpWebAssemblyServiceCollectionExtensions.cs

@ -2,16 +2,15 @@
using Microsoft.AspNetCore.Components.WebAssembly.Hosting; using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Volo.Abp; using Volo.Abp;
namespace Microsoft.Extensions.DependencyInjection namespace Microsoft.Extensions.DependencyInjection;
public static class AbpWebAssemblyServiceCollectionExtensions
{ {
public static class AbpWebAssemblyServiceCollectionExtensions public static WebAssemblyHostBuilder GetHostBuilder(
[NotNull] this IServiceCollection services)
{ {
public static WebAssemblyHostBuilder GetHostBuilder( Check.NotNull(services, nameof(services));
[NotNull] this IServiceCollection services)
{
Check.NotNull(services, nameof(services));
return services.GetSingletonInstance<WebAssemblyHostBuilder>(); return services.GetSingletonInstance<WebAssemblyHostBuilder>();
}
} }
} }

39
framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/AbpAspNetCoreComponentsWebAssemblyModule.cs

@ -7,31 +7,30 @@ using Volo.Abp.Http.Client;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
using Volo.Abp.UI; using Volo.Abp.UI;
namespace Volo.Abp.AspNetCore.Components.WebAssembly namespace Volo.Abp.AspNetCore.Components.WebAssembly;
[DependsOn(
typeof(AbpAspNetCoreMvcClientCommonModule),
typeof(AbpUiModule),
typeof(AbpAspNetCoreComponentsWebModule)
)]
public class AbpAspNetCoreComponentsWebAssemblyModule : AbpModule
{ {
[DependsOn( public override void PreConfigureServices(ServiceConfigurationContext context)
typeof(AbpAspNetCoreMvcClientCommonModule),
typeof(AbpUiModule),
typeof(AbpAspNetCoreComponentsWebModule)
)]
public class AbpAspNetCoreComponentsWebAssemblyModule : AbpModule
{ {
public override void PreConfigureServices(ServiceConfigurationContext context) PreConfigure<AbpHttpClientBuilderOptions>(options =>
{ {
PreConfigure<AbpHttpClientBuilderOptions>(options => options.ProxyClientBuildActions.Add((_, builder) =>
{ {
options.ProxyClientBuildActions.Add((_, builder) => builder.AddHttpMessageHandler<AbpBlazorClientHttpMessageHandler>();
{
builder.AddHttpMessageHandler<AbpBlazorClientHttpMessageHandler>();
});
}); });
} });
}
public override void ConfigureServices(ServiceConfigurationContext context) public override void ConfigureServices(ServiceConfigurationContext context)
{ {
context.Services context.Services
.GetHostBuilder().Logging .GetHostBuilder().Logging
.AddProvider(new AbpExceptionHandlingLoggerProvider(context.Services)); .AddProvider(new AbpExceptionHandlingLoggerProvider(context.Services));
}
} }
} }

23
framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/AbpWebAssemblyApplicationCreationOptions.cs

@ -1,19 +1,18 @@
using Microsoft.AspNetCore.Components.WebAssembly.Hosting; using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
namespace Volo.Abp.AspNetCore.Components.WebAssembly namespace Volo.Abp.AspNetCore.Components.WebAssembly;
public class AbpWebAssemblyApplicationCreationOptions
{ {
public class AbpWebAssemblyApplicationCreationOptions public WebAssemblyHostBuilder HostBuilder { get; }
{
public WebAssemblyHostBuilder HostBuilder { get; }
public AbpApplicationCreationOptions ApplicationCreationOptions { get; } public AbpApplicationCreationOptions ApplicationCreationOptions { get; }
public AbpWebAssemblyApplicationCreationOptions( public AbpWebAssemblyApplicationCreationOptions(
WebAssemblyHostBuilder hostBuilder, WebAssemblyHostBuilder hostBuilder,
AbpApplicationCreationOptions applicationCreationOptions) AbpApplicationCreationOptions applicationCreationOptions)
{ {
HostBuilder = hostBuilder; HostBuilder = hostBuilder;
ApplicationCreationOptions = applicationCreationOptions; ApplicationCreationOptions = applicationCreationOptions;
}
} }
} }

23
framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/ApplicationConfigurationCache.cs

@ -1,20 +1,19 @@
using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations; using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
namespace Volo.Abp.AspNetCore.Components.WebAssembly namespace Volo.Abp.AspNetCore.Components.WebAssembly;
public class ApplicationConfigurationCache : ISingletonDependency
{ {
public class ApplicationConfigurationCache : ISingletonDependency protected ApplicationConfigurationDto Configuration { get; set; }
{
protected ApplicationConfigurationDto Configuration { get; set; }
public virtual ApplicationConfigurationDto Get() public virtual ApplicationConfigurationDto Get()
{ {
return Configuration; return Configuration;
} }
public void Set(ApplicationConfigurationDto configuration) public void Set(ApplicationConfigurationDto configuration)
{ {
Configuration = configuration; Configuration = configuration;
}
} }
} }

83
framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/Extensibility/WebAssemblyLookupApiRequestService.cs

@ -11,57 +11,56 @@ using Volo.Abp.Http.Client;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Volo.Abp.MultiTenancy; using Volo.Abp.MultiTenancy;
namespace Volo.Abp.AspNetCore.Components.WebAssembly.Extensibility namespace Volo.Abp.AspNetCore.Components.WebAssembly.Extensibility;
public class WebAssemblyLookupApiRequestService : ILookupApiRequestService, ITransientDependency
{ {
public class WebAssemblyLookupApiRequestService : ILookupApiRequestService, ITransientDependency public IHttpClientFactory HttpClientFactory { get; }
public IRemoteServiceHttpClientAuthenticator HttpClientAuthenticator { get; }
public IRemoteServiceConfigurationProvider RemoteServiceConfigurationProvider { get; }
public ICurrentTenant CurrentTenant { get; }
public WebAssemblyLookupApiRequestService(IHttpClientFactory httpClientFactory,
IRemoteServiceHttpClientAuthenticator httpClientAuthenticator,
ICurrentTenant currentTenant,
IRemoteServiceConfigurationProvider remoteServiceConfigurationProvider)
{
HttpClientFactory = httpClientFactory;
HttpClientAuthenticator = httpClientAuthenticator;
CurrentTenant = currentTenant;
RemoteServiceConfigurationProvider = remoteServiceConfigurationProvider;
}
public async Task<string> SendAsync(string url)
{ {
public IHttpClientFactory HttpClientFactory { get; } var client = HttpClientFactory.CreateClient();
public IRemoteServiceHttpClientAuthenticator HttpClientAuthenticator { get; } var requestMessage = new HttpRequestMessage(HttpMethod.Get, url);
public IRemoteServiceConfigurationProvider RemoteServiceConfigurationProvider { get; } AddHeaders(requestMessage);
public ICurrentTenant CurrentTenant { get; }
public WebAssemblyLookupApiRequestService(IHttpClientFactory httpClientFactory, var uri = new Uri(url, UriKind.RelativeOrAbsolute);
IRemoteServiceHttpClientAuthenticator httpClientAuthenticator, if (!uri.IsAbsoluteUri)
ICurrentTenant currentTenant,
IRemoteServiceConfigurationProvider remoteServiceConfigurationProvider)
{ {
HttpClientFactory = httpClientFactory; var remoteServiceConfig = await RemoteServiceConfigurationProvider.GetConfigurationOrDefaultAsync("Default");
HttpClientAuthenticator = httpClientAuthenticator; client.BaseAddress = new Uri(remoteServiceConfig.BaseUrl);
CurrentTenant = currentTenant; await HttpClientAuthenticator.Authenticate(new RemoteServiceHttpClientAuthenticateContext(client, requestMessage, new RemoteServiceConfiguration(remoteServiceConfig.BaseUrl), string.Empty));
RemoteServiceConfigurationProvider = remoteServiceConfigurationProvider;
} }
public async Task<string> SendAsync(string url) var response = await client.SendAsync(requestMessage);
{
var client = HttpClientFactory.CreateClient();
var requestMessage = new HttpRequestMessage(HttpMethod.Get, url);
AddHeaders(requestMessage);
var uri = new Uri(url, UriKind.RelativeOrAbsolute); return await response.Content.ReadAsStringAsync();
if (!uri.IsAbsoluteUri) }
{
var remoteServiceConfig = await RemoteServiceConfigurationProvider.GetConfigurationOrDefaultAsync("Default");
client.BaseAddress = new Uri(remoteServiceConfig.BaseUrl);
await HttpClientAuthenticator.Authenticate(new RemoteServiceHttpClientAuthenticateContext(client, requestMessage, new RemoteServiceConfiguration(remoteServiceConfig.BaseUrl), string.Empty));
}
var response = await client.SendAsync(requestMessage); protected virtual void AddHeaders(HttpRequestMessage requestMessage)
{
return await response.Content.ReadAsStringAsync(); if (CurrentTenant.Id.HasValue)
}
protected virtual void AddHeaders(HttpRequestMessage requestMessage)
{ {
if (CurrentTenant.Id.HasValue) requestMessage.Headers.Add(TenantResolverConsts.DefaultTenantKey, CurrentTenant.Id.Value.ToString());
{ }
requestMessage.Headers.Add(TenantResolverConsts.DefaultTenantKey, CurrentTenant.Id.Value.ToString());
}
var currentCulture = CultureInfo.CurrentUICulture.Name ?? CultureInfo.CurrentCulture.Name; var currentCulture = CultureInfo.CurrentUICulture.Name ?? CultureInfo.CurrentCulture.Name;
if (!currentCulture.IsNullOrEmpty()) if (!currentCulture.IsNullOrEmpty())
{ {
requestMessage.Headers.AcceptLanguage.Add(new (currentCulture)); requestMessage.Headers.AcceptLanguage.Add(new(currentCulture));
}
} }
} }
} }

91
framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/WebAssemblyCachedApplicationConfigurationClient.cs

@ -5,63 +5,62 @@ using Volo.Abp.AspNetCore.Mvc.Client;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.MultiTenancy; using Volo.Abp.MultiTenancy;
namespace Volo.Abp.AspNetCore.Components.WebAssembly namespace Volo.Abp.AspNetCore.Components.WebAssembly;
[ExposeServices(
typeof(WebAssemblyCachedApplicationConfigurationClient),
typeof(ICachedApplicationConfigurationClient),
typeof(IAsyncInitialize)
)]
public class WebAssemblyCachedApplicationConfigurationClient : ICachedApplicationConfigurationClient, ITransientDependency
{ {
[ExposeServices( protected AbpApplicationConfigurationClientProxy ApplicationConfigurationAppService { get; }
typeof(WebAssemblyCachedApplicationConfigurationClient),
typeof(ICachedApplicationConfigurationClient),
typeof(IAsyncInitialize)
)]
public class WebAssemblyCachedApplicationConfigurationClient : ICachedApplicationConfigurationClient, ITransientDependency
{
protected AbpApplicationConfigurationClientProxy ApplicationConfigurationAppService { get; }
protected ApplicationConfigurationCache Cache { get; } protected ApplicationConfigurationCache Cache { get; }
protected ICurrentTenantAccessor CurrentTenantAccessor { get; } protected ICurrentTenantAccessor CurrentTenantAccessor { get; }
public WebAssemblyCachedApplicationConfigurationClient( public WebAssemblyCachedApplicationConfigurationClient(
AbpApplicationConfigurationClientProxy applicationConfigurationAppService, AbpApplicationConfigurationClientProxy applicationConfigurationAppService,
ApplicationConfigurationCache cache, ApplicationConfigurationCache cache,
ICurrentTenantAccessor currentTenantAccessor) ICurrentTenantAccessor currentTenantAccessor)
{ {
ApplicationConfigurationAppService = applicationConfigurationAppService; ApplicationConfigurationAppService = applicationConfigurationAppService;
Cache = cache; Cache = cache;
CurrentTenantAccessor = currentTenantAccessor; CurrentTenantAccessor = currentTenantAccessor;
} }
public virtual async Task InitializeAsync() public virtual async Task InitializeAsync()
{ {
var configurationDto = await ApplicationConfigurationAppService.GetAsync(); var configurationDto = await ApplicationConfigurationAppService.GetAsync();
Cache.Set(configurationDto); Cache.Set(configurationDto);
CurrentTenantAccessor.Current = new BasicTenantInfo( CurrentTenantAccessor.Current = new BasicTenantInfo(
configurationDto.CurrentTenant.Id, configurationDto.CurrentTenant.Id,
configurationDto.CurrentTenant.Name configurationDto.CurrentTenant.Name
); );
} }
public virtual Task<ApplicationConfigurationDto> GetAsync() public virtual Task<ApplicationConfigurationDto> GetAsync()
{ {
return Task.FromResult(GetConfigurationByChecking()); return Task.FromResult(GetConfigurationByChecking());
} }
public virtual ApplicationConfigurationDto Get() public virtual ApplicationConfigurationDto Get()
{ {
return GetConfigurationByChecking(); return GetConfigurationByChecking();
} }
private ApplicationConfigurationDto GetConfigurationByChecking() private ApplicationConfigurationDto GetConfigurationByChecking()
{
var configuration = Cache.Get();
if (configuration == null)
{ {
var configuration = Cache.Get(); throw new AbpException(
if (configuration == null) $"{nameof(WebAssemblyCachedApplicationConfigurationClient)} should be initialized before using it.");
{
throw new AbpException(
$"{nameof(WebAssemblyCachedApplicationConfigurationClient)} should be initialized before using it.");
}
return configuration;
} }
return configuration;
} }
} }

25
framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/WebAssemblyCurrentPrincipalAccessor.cs

@ -4,21 +4,20 @@ using Volo.Abp.AspNetCore.Components.Web.Security;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.Security.Claims; using Volo.Abp.Security.Claims;
namespace Volo.Abp.AspNetCore.Components.WebAssembly namespace Volo.Abp.AspNetCore.Components.WebAssembly;
public class WebAssemblyCurrentPrincipalAccessor : CurrentPrincipalAccessorBase, ITransientDependency
{ {
public class WebAssemblyCurrentPrincipalAccessor : CurrentPrincipalAccessorBase, ITransientDependency protected AbpComponentsClaimsCache ClaimsCache { get; }
{
protected AbpComponentsClaimsCache ClaimsCache { get; }
public WebAssemblyCurrentPrincipalAccessor( public WebAssemblyCurrentPrincipalAccessor(
IClientScopeServiceProviderAccessor clientScopeServiceProviderAccessor) IClientScopeServiceProviderAccessor clientScopeServiceProviderAccessor)
{ {
ClaimsCache = clientScopeServiceProviderAccessor.ServiceProvider.GetRequiredService<AbpComponentsClaimsCache>(); ClaimsCache = clientScopeServiceProviderAccessor.ServiceProvider.GetRequiredService<AbpComponentsClaimsCache>();
} }
protected override ClaimsPrincipal GetClaimsPrincipal() protected override ClaimsPrincipal GetClaimsPrincipal()
{ {
return ClaimsCache.Principal; return ClaimsCache.Principal;
}
} }
} }

11
framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/WebAssemblyCurrentTenantAccessor.cs

@ -1,11 +1,10 @@
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.MultiTenancy; using Volo.Abp.MultiTenancy;
namespace Volo.Abp.AspNetCore.Components.WebAssembly namespace Volo.Abp.AspNetCore.Components.WebAssembly;
[Dependency(ReplaceServices = true)]
public class WebAssemblyCurrentTenantAccessor : ICurrentTenantAccessor, ISingletonDependency
{ {
[Dependency(ReplaceServices = true)] public BasicTenantInfo Current { get; set; }
public class WebAssemblyCurrentTenantAccessor : ICurrentTenantAccessor, ISingletonDependency
{
public BasicTenantInfo Current { get; set; }
}
} }

37
framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/WebAssemblyServerUrlProvider.cs

@ -4,26 +4,25 @@ using Volo.Abp.AspNetCore.Components.Web;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.Http.Client; using Volo.Abp.Http.Client;
namespace Volo.Abp.AspNetCore.Components.WebAssembly namespace Volo.Abp.AspNetCore.Components.WebAssembly;
[Dependency(ReplaceServices = true)]
public class WebAssemblyServerUrlProvider : IServerUrlProvider, ITransientDependency
{ {
[Dependency(ReplaceServices = true)] protected IRemoteServiceConfigurationProvider RemoteServiceConfigurationProvider { get; }
public class WebAssemblyServerUrlProvider : IServerUrlProvider, ITransientDependency
public WebAssemblyServerUrlProvider(
IRemoteServiceConfigurationProvider remoteServiceConfigurationProvider)
{
RemoteServiceConfigurationProvider = remoteServiceConfigurationProvider;
}
public async Task<string> GetBaseUrlAsync(string remoteServiceName = null)
{ {
protected IRemoteServiceConfigurationProvider RemoteServiceConfigurationProvider { get; } var remoteServiceConfiguration = await RemoteServiceConfigurationProvider.GetConfigurationOrDefaultAsync(
remoteServiceName ?? RemoteServiceConfigurationDictionary.DefaultName
);
public WebAssemblyServerUrlProvider( return remoteServiceConfiguration.BaseUrl.EnsureEndsWith('/');
IRemoteServiceConfigurationProvider remoteServiceConfigurationProvider)
{
RemoteServiceConfigurationProvider = remoteServiceConfigurationProvider;
}
public async Task<string> GetBaseUrlAsync(string remoteServiceName = null)
{
var remoteServiceConfiguration = await RemoteServiceConfigurationProvider.GetConfigurationOrDefaultAsync(
remoteServiceName ?? RemoteServiceConfigurationDictionary.DefaultName
);
return remoteServiceConfiguration.BaseUrl.EnsureEndsWith('/');
}
} }
} }

23
framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/AbpAspNetCoreComponentsModule.cs

@ -7,19 +7,18 @@ using Volo.Abp.Modularity;
using Volo.Abp.ObjectMapping; using Volo.Abp.ObjectMapping;
using Volo.Abp.Security; using Volo.Abp.Security;
namespace Volo.Abp.AspNetCore.Components namespace Volo.Abp.AspNetCore.Components;
[DependsOn(
typeof(AbpObjectMappingModule),
typeof(AbpSecurityModule),
typeof(AbpLocalizationModule)
)]
public class AbpAspNetCoreComponentsModule : AbpModule
{ {
[DependsOn( public override void PreConfigureServices(ServiceConfigurationContext context)
typeof(AbpObjectMappingModule),
typeof(AbpSecurityModule),
typeof(AbpLocalizationModule)
)]
public class AbpAspNetCoreComponentsModule : AbpModule
{ {
public override void PreConfigureServices(ServiceConfigurationContext context) DynamicProxyIgnoreTypes.Add<ComponentBase>();
{ context.Services.AddConventionalRegistrar(new AbpWebAssemblyConventionalRegistrar());
DynamicProxyIgnoreTypes.Add<ComponentBase>();
context.Services.AddConventionalRegistrar(new AbpWebAssemblyConventionalRegistrar());
}
} }
} }

231
framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/AbpComponentBase.cs

@ -14,164 +14,157 @@ using Volo.Abp.Localization;
using Volo.Abp.ObjectMapping; using Volo.Abp.ObjectMapping;
using Volo.Abp.Users; using Volo.Abp.Users;
namespace Volo.Abp.AspNetCore.Components namespace Volo.Abp.AspNetCore.Components;
public abstract class AbpComponentBase : OwningComponentBase
{ {
public abstract class AbpComponentBase : OwningComponentBase protected IStringLocalizerFactory StringLocalizerFactory => LazyGetRequiredService(ref _stringLocalizerFactory);
{ private IStringLocalizerFactory _stringLocalizerFactory;
protected IStringLocalizerFactory StringLocalizerFactory => LazyGetRequiredService(ref _stringLocalizerFactory);
private IStringLocalizerFactory _stringLocalizerFactory;
protected IStringLocalizer L protected IStringLocalizer L {
{ get {
get if (_localizer == null)
{ {
if (_localizer == null) _localizer = CreateLocalizer();
{
_localizer = CreateLocalizer();
}
return _localizer;
} }
}
private IStringLocalizer _localizer;
protected Type LocalizationResource return _localizer;
{
get => _localizationResource;
set
{
_localizationResource = value;
_localizer = null;
}
} }
private Type _localizationResource = typeof(DefaultResource); }
private IStringLocalizer _localizer;
protected ILogger Logger => _lazyLogger.Value; protected Type LocalizationResource {
private Lazy<ILogger> _lazyLogger => new Lazy<ILogger>(() => LoggerFactory?.CreateLogger(GetType().FullName) ?? NullLogger.Instance, true); get => _localizationResource;
set {
_localizationResource = value;
_localizer = null;
}
}
private Type _localizationResource = typeof(DefaultResource);
protected ILoggerFactory LoggerFactory => LazyGetRequiredService(ref _loggerFactory); protected ILogger Logger => _lazyLogger.Value;
private ILoggerFactory _loggerFactory; private Lazy<ILogger> _lazyLogger => new Lazy<ILogger>(() => LoggerFactory?.CreateLogger(GetType().FullName) ?? NullLogger.Instance, true);
protected IAuthorizationService AuthorizationService => LazyGetRequiredService(ref _authorizationService); protected ILoggerFactory LoggerFactory => LazyGetRequiredService(ref _loggerFactory);
private IAuthorizationService _authorizationService; private ILoggerFactory _loggerFactory;
protected ICurrentUser CurrentUser => LazyGetRequiredService(ref _currentUser); protected IAuthorizationService AuthorizationService => LazyGetRequiredService(ref _authorizationService);
private ICurrentUser _currentUser; private IAuthorizationService _authorizationService;
protected IUiMessageService Message => LazyGetNonScopedRequiredService(ref _message);
private IUiMessageService _message;
protected IUiNotificationService Notify => LazyGetNonScopedRequiredService(ref _notify); protected ICurrentUser CurrentUser => LazyGetRequiredService(ref _currentUser);
private IUiNotificationService _notify; private ICurrentUser _currentUser;
protected IUserExceptionInformer UserExceptionInformer => LazyGetNonScopedRequiredService(ref _userExceptionInformer);
private IUserExceptionInformer _userExceptionInformer;
protected IAlertManager AlertManager => LazyGetNonScopedRequiredService(ref _alertManager); protected IUiMessageService Message => LazyGetNonScopedRequiredService(ref _message);
private IAlertManager _alertManager; private IUiMessageService _message;
protected AlertList Alerts => AlertManager.Alerts; protected IUiNotificationService Notify => LazyGetNonScopedRequiredService(ref _notify);
private IUiNotificationService _notify;
protected IObjectMapper ObjectMapper protected IUserExceptionInformer UserExceptionInformer => LazyGetNonScopedRequiredService(ref _userExceptionInformer);
{ private IUserExceptionInformer _userExceptionInformer;
get
{
if (_objectMapper != null)
{
return _objectMapper;
}
if (ObjectMapperContext == null)
{
return LazyGetRequiredService(ref _objectMapper);
}
return LazyGetRequiredService(
typeof(IObjectMapper<>).MakeGenericType(ObjectMapperContext),
ref _objectMapper
);
}
}
private IObjectMapper _objectMapper; protected IAlertManager AlertManager => LazyGetNonScopedRequiredService(ref _alertManager);
private IAlertManager _alertManager;
protected Type ObjectMapperContext { get; set; } protected AlertList Alerts => AlertManager.Alerts;
protected TService LazyGetRequiredService<TService>(ref TService reference) => LazyGetRequiredService(typeof(TService), ref reference); protected IObjectMapper ObjectMapper {
get {
protected TRef LazyGetRequiredService<TRef>(Type serviceType, ref TRef reference) if (_objectMapper != null)
{
if (reference == null)
{ {
reference = (TRef)ScopedServices.GetRequiredService(serviceType); return _objectMapper;
} }
return reference; if (ObjectMapperContext == null)
}
protected TService LazyGetService<TService>(ref TService reference) => LazyGetService(typeof(TService), ref reference);
protected TRef LazyGetService<TRef>(Type serviceType, ref TRef reference)
{
if (reference == null)
{ {
reference = (TRef)ScopedServices.GetService(serviceType); return LazyGetRequiredService(ref _objectMapper);
} }
return reference; return LazyGetRequiredService(
typeof(IObjectMapper<>).MakeGenericType(ObjectMapperContext),
ref _objectMapper
);
} }
}
protected TService LazyGetNonScopedRequiredService<TService>(ref TService reference) => LazyGetNonScopedRequiredService(typeof(TService), ref reference); private IObjectMapper _objectMapper;
protected TRef LazyGetNonScopedRequiredService<TRef>(Type serviceType, ref TRef reference) protected Type ObjectMapperContext { get; set; }
{
if (reference == null)
{
reference = (TRef)NonScopedServices.GetRequiredService(serviceType);
}
return reference; protected TService LazyGetRequiredService<TService>(ref TService reference) => LazyGetRequiredService(typeof(TService), ref reference);
protected TRef LazyGetRequiredService<TRef>(Type serviceType, ref TRef reference)
{
if (reference == null)
{
reference = (TRef)ScopedServices.GetRequiredService(serviceType);
} }
protected TService LazyGetNonScopedService<TService>(ref TService reference) => LazyGetNonScopedService(typeof(TService), ref reference);
protected TRef LazyGetNonScopedService<TRef>(Type serviceType, ref TRef reference) return reference;
}
protected TService LazyGetService<TService>(ref TService reference) => LazyGetService(typeof(TService), ref reference);
protected TRef LazyGetService<TRef>(Type serviceType, ref TRef reference)
{
if (reference == null)
{ {
if (reference == null) reference = (TRef)ScopedServices.GetService(serviceType);
{ }
reference = (TRef)NonScopedServices.GetService(serviceType);
} return reference;
}
protected TService LazyGetNonScopedRequiredService<TService>(ref TService reference) => LazyGetNonScopedRequiredService(typeof(TService), ref reference);
return reference; protected TRef LazyGetNonScopedRequiredService<TRef>(Type serviceType, ref TRef reference)
{
if (reference == null)
{
reference = (TRef)NonScopedServices.GetRequiredService(serviceType);
} }
[Inject] return reference;
protected IServiceProvider NonScopedServices { get; set; } }
protected TService LazyGetNonScopedService<TService>(ref TService reference) => LazyGetNonScopedService(typeof(TService), ref reference);
protected virtual IStringLocalizer CreateLocalizer() protected TRef LazyGetNonScopedService<TRef>(Type serviceType, ref TRef reference)
{
if (reference == null)
{ {
if (LocalizationResource != null) reference = (TRef)NonScopedServices.GetService(serviceType);
{ }
return StringLocalizerFactory.Create(LocalizationResource);
}
var localizer = StringLocalizerFactory.CreateDefaultOrNull(); return reference;
if (localizer == null) }
{
throw new AbpException($"Set {nameof(LocalizationResource)} or define the default localization resource type (by configuring the {nameof(AbpLocalizationOptions)}.{nameof(AbpLocalizationOptions.DefaultResourceType)}) to be able to use the {nameof(L)} object!");
}
return localizer; [Inject]
protected IServiceProvider NonScopedServices { get; set; }
protected virtual IStringLocalizer CreateLocalizer()
{
if (LocalizationResource != null)
{
return StringLocalizerFactory.Create(LocalizationResource);
} }
protected async Task HandleErrorAsync(Exception exception) var localizer = StringLocalizerFactory.CreateDefaultOrNull();
if (localizer == null)
{ {
Logger.LogException(exception); throw new AbpException($"Set {nameof(LocalizationResource)} or define the default localization resource type (by configuring the {nameof(AbpLocalizationOptions)}.{nameof(AbpLocalizationOptions.DefaultResourceType)}) to be able to use the {nameof(L)} object!");
await InvokeAsync(async () =>
{
await UserExceptionInformer.InformAsync(new UserExceptionInformerContext(exception));
StateHasChanged();
});
} }
return localizer;
}
protected async Task HandleErrorAsync(Exception exception)
{
Logger.LogException(exception);
await InvokeAsync(async () =>
{
await UserExceptionInformer.InformAsync(new UserExceptionInformerContext(exception));
StateHasChanged();
});
} }
} }

43
framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Alerts/AlertList.cs

@ -5,33 +5,32 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Volo.Abp.AspNetCore.Components.Alerts namespace Volo.Abp.AspNetCore.Components.Alerts;
public class AlertList : ObservableCollection<AlertMessage>
{ {
public class AlertList : ObservableCollection<AlertMessage> public void Add(AlertType type, string text, string title = null, bool dismissible = true)
{ {
public void Add(AlertType type, string text, string title = null, bool dismissible = true) Add(new AlertMessage(type, text, title, dismissible));
{ }
Add(new AlertMessage(type, text, title, dismissible));
}
public void Info(string text, string title = null, bool dismissible = true) public void Info(string text, string title = null, bool dismissible = true)
{ {
Add(new AlertMessage(AlertType.Info, text, title, dismissible)); Add(new AlertMessage(AlertType.Info, text, title, dismissible));
} }
public void Warning(string text, string title = null, bool dismissible = true) public void Warning(string text, string title = null, bool dismissible = true)
{ {
Add(new AlertMessage(AlertType.Warning, text, title, dismissible)); Add(new AlertMessage(AlertType.Warning, text, title, dismissible));
} }
public void Danger(string text, string title = null, bool dismissible = true) public void Danger(string text, string title = null, bool dismissible = true)
{ {
Add(new AlertMessage(AlertType.Danger, text, title, dismissible)); Add(new AlertMessage(AlertType.Danger, text, title, dismissible));
} }
public void Success(string text, string title = null, bool dismissible = true) public void Success(string text, string title = null, bool dismissible = true)
{ {
Add(new AlertMessage(AlertType.Success, text, title, dismissible)); Add(new AlertMessage(AlertType.Success, text, title, dismissible));
}
} }
} }

40
framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Alerts/AlertMessage.cs

@ -1,30 +1,28 @@
using JetBrains.Annotations; using JetBrains.Annotations;
namespace Volo.Abp.AspNetCore.Components.Alerts namespace Volo.Abp.AspNetCore.Components.Alerts;
public class AlertMessage
{ {
public class AlertMessage [NotNull]
{ public string Text {
[NotNull] get => _text;
public string Text set => _text = Check.NotNullOrWhiteSpace(value, nameof(value));
{ }
get => _text; private string _text;
set => _text = Check.NotNullOrWhiteSpace(value, nameof(value));
}
private string _text;
public AlertType Type { get; set; } public AlertType Type { get; set; }
[CanBeNull] [CanBeNull]
public string Title { get; set; } public string Title { get; set; }
public bool Dismissible { get; set; } public bool Dismissible { get; set; }
public AlertMessage(AlertType type, [NotNull] string text, string title = null, bool dismissible = true) public AlertMessage(AlertType type, [NotNull] string text, string title = null, bool dismissible = true)
{ {
Type = type; Type = type;
Text = Check.NotNullOrWhiteSpace(text, nameof(text)); Text = Check.NotNullOrWhiteSpace(text, nameof(text));
Title = title; Title = title;
Dismissible = dismissible; Dismissible = dismissible;
}
} }
} }

25
framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Alerts/AlertType.cs

@ -4,18 +4,17 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Volo.Abp.AspNetCore.Components.Alerts namespace Volo.Abp.AspNetCore.Components.Alerts;
public enum AlertType
{ {
public enum AlertType Default,
{ Primary,
Default, Secondary,
Primary, Success,
Secondary, Danger,
Success, Warning,
Danger, Info,
Warning, Light,
Info, Dark
Light,
Dark
}
} }

9
framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Alerts/IAlertManager.cs

@ -4,10 +4,9 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Volo.Abp.AspNetCore.Components.Alerts namespace Volo.Abp.AspNetCore.Components.Alerts;
public interface IAlertManager
{ {
public interface IAlertManager AlertList Alerts { get; }
{
AlertList Alerts { get; }
}
} }

27
framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/DependencyInjection/AbpWebAssemblyConventionalRegistrar.cs

@ -3,23 +3,22 @@ using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
namespace Volo.Abp.AspNetCore.Components.DependencyInjection namespace Volo.Abp.AspNetCore.Components.DependencyInjection;
public class AbpWebAssemblyConventionalRegistrar : DefaultConventionalRegistrar
{ {
public class AbpWebAssemblyConventionalRegistrar : DefaultConventionalRegistrar protected override bool IsConventionalRegistrationDisabled(Type type)
{ {
protected override bool IsConventionalRegistrationDisabled(Type type) return !IsComponent(type) || base.IsConventionalRegistrationDisabled(type);
{ }
return !IsComponent(type) || base.IsConventionalRegistrationDisabled(type);
}
private static bool IsComponent(Type type) private static bool IsComponent(Type type)
{ {
return typeof(ComponentBase).IsAssignableFrom(type); return typeof(ComponentBase).IsAssignableFrom(type);
} }
protected override ServiceLifetime? GetDefaultLifeTimeOrNull(Type type) protected override ServiceLifetime? GetDefaultLifeTimeOrNull(Type type)
{ {
return ServiceLifetime.Transient; return ServiceLifetime.Transient;
}
} }
} }

37
framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/DependencyInjection/ServiceProviderComponentActivator.cs

@ -1,32 +1,31 @@
using System; using System;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
namespace Volo.Abp.AspNetCore.Components.DependencyInjection namespace Volo.Abp.AspNetCore.Components.DependencyInjection;
public class ServiceProviderComponentActivator : IComponentActivator
{ {
public class ServiceProviderComponentActivator : IComponentActivator public IServiceProvider ServiceProvider { get; }
public ServiceProviderComponentActivator(IServiceProvider serviceProvider)
{
ServiceProvider = serviceProvider;
}
public IComponent CreateInstance(Type componentType)
{ {
public IServiceProvider ServiceProvider { get; } var instance = ServiceProvider.GetService(componentType);
public ServiceProviderComponentActivator(IServiceProvider serviceProvider) if (instance == null)
{ {
ServiceProvider = serviceProvider; instance = Activator.CreateInstance(componentType);
} }
public IComponent CreateInstance(Type componentType) if (!(instance is IComponent component))
{ {
var instance = ServiceProvider.GetService(componentType); throw new ArgumentException($"The type {componentType.FullName} does not implement {nameof(IComponent)}.", nameof(componentType));
if (instance == null)
{
instance = Activator.CreateInstance(componentType);
}
if (!(instance is IComponent component))
{
throw new ArgumentException($"The type {componentType.FullName} does not implement {nameof(IComponent)}.", nameof(componentType));
}
return component;
} }
return component;
} }
} }

13
framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/ExceptionHandling/IUserExceptionInformer.cs

@ -1,11 +1,10 @@
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Volo.Abp.AspNetCore.Components.ExceptionHandling namespace Volo.Abp.AspNetCore.Components.ExceptionHandling;
public interface IUserExceptionInformer
{ {
public interface IUserExceptionInformer void Inform(UserExceptionInformerContext context);
{
void Inform(UserExceptionInformerContext context); Task InformAsync(UserExceptionInformerContext context);
Task InformAsync(UserExceptionInformerContext context);
}
} }

21
framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/ExceptionHandling/NullUserExceptionInformer.cs

@ -1,18 +1,17 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
namespace Volo.Abp.AspNetCore.Components.ExceptionHandling namespace Volo.Abp.AspNetCore.Components.ExceptionHandling;
public class NullUserExceptionInformer : IUserExceptionInformer, ISingletonDependency
{ {
public class NullUserExceptionInformer : IUserExceptionInformer, ISingletonDependency public void Inform(UserExceptionInformerContext context)
{ {
public void Inform(UserExceptionInformerContext context)
{
}
public Task InformAsync(UserExceptionInformerContext context)
{
return Task.CompletedTask;
}
} }
}
public Task InformAsync(UserExceptionInformerContext context)
{
return Task.CompletedTask;
}
}

17
framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/ExceptionHandling/UserExceptionInformerContext.cs

@ -1,16 +1,15 @@
using System; using System;
using JetBrains.Annotations; using JetBrains.Annotations;
namespace Volo.Abp.AspNetCore.Components.ExceptionHandling namespace Volo.Abp.AspNetCore.Components.ExceptionHandling;
public class UserExceptionInformerContext
{ {
public class UserExceptionInformerContext [NotNull]
{ public Exception Exception { get; }
[NotNull]
public Exception Exception { get; }
public UserExceptionInformerContext(Exception exception) public UserExceptionInformerContext(Exception exception)
{ {
Exception = exception; Exception = exception;
}
} }
} }

17
framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Messages/IUiMessageService.cs

@ -1,18 +1,17 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Volo.Abp.AspNetCore.Components.Messages namespace Volo.Abp.AspNetCore.Components.Messages;
public interface IUiMessageService
{ {
public interface IUiMessageService Task Info(string message, string title = null, Action<UiMessageOptions> options = null);
{
Task Info(string message, string title = null, Action<UiMessageOptions> options = null);
Task Success(string message, string title = null, Action<UiMessageOptions> options = null); Task Success(string message, string title = null, Action<UiMessageOptions> options = null);
Task Warn(string message, string title = null, Action<UiMessageOptions> options = null); Task Warn(string message, string title = null, Action<UiMessageOptions> options = null);
Task Error(string message, string title = null, Action<UiMessageOptions> options = null); Task Error(string message, string title = null, Action<UiMessageOptions> options = null);
Task<bool> Confirm(string message, string title = null, Action<UiMessageOptions> options = null); Task<bool> Confirm(string message, string title = null, Action<UiMessageOptions> options = null);
}
} }

45
framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Messages/UiMessageEventArgs.cs

@ -1,35 +1,34 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Volo.Abp.AspNetCore.Components.Messages namespace Volo.Abp.AspNetCore.Components.Messages;
public class UiMessageEventArgs : EventArgs
{ {
public class UiMessageEventArgs : EventArgs public UiMessageEventArgs(UiMessageType messageType, string message, string title, UiMessageOptions options)
{ {
public UiMessageEventArgs(UiMessageType messageType, string message, string title, UiMessageOptions options) MessageType = messageType;
{ Message = message;
MessageType = messageType; Title = title;
Message = message; Options = options;
Title = title; }
Options = options;
}
public UiMessageEventArgs(UiMessageType messageType, string message, string title, UiMessageOptions options, TaskCompletionSource<bool> callback) public UiMessageEventArgs(UiMessageType messageType, string message, string title, UiMessageOptions options, TaskCompletionSource<bool> callback)
{ {
MessageType = messageType; MessageType = messageType;
Message = message; Message = message;
Title = title; Title = title;
Options = options; Options = options;
Callback = callback; Callback = callback;
} }
public UiMessageType MessageType { get; set; } public UiMessageType MessageType { get; set; }
public string Message { get; } public string Message { get; }
public string Title { get; } public string Title { get; }
public UiMessageOptions Options { get; } public UiMessageOptions Options { get; }
public TaskCompletionSource<bool> Callback { get; } public TaskCompletionSource<bool> Callback { get; }
}
} }

99
framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Messages/UiMessageOptions.cs

@ -1,53 +1,52 @@
namespace Volo.Abp.AspNetCore.Components.Messages namespace Volo.Abp.AspNetCore.Components.Messages;
/// <summary>
/// Options to override message dialog appearance.
/// </summary>
public class UiMessageOptions
{ {
/// <summary> /// <summary>
/// Options to override message dialog appearance. /// If true, the message dialogue will be centered on the screen.
/// </summary> /// </summary>
public class UiMessageOptions public bool CenterMessage { get; set; }
{
/// <summary> /// <summary>
/// If true, the message dialogue will be centered on the screen. /// If true, the message dialogue will show the large icon for the current message type.
/// </summary> /// </summary>
public bool CenterMessage { get; set; } public bool ShowMessageIcon { get; set; }
/// <summary> /// <summary>
/// If true, the message dialogue will show the large icon for the current message type. /// Overrides the build-in message icon.
/// </summary> /// </summary>
public bool ShowMessageIcon { get; set; } public object MessageIcon { get; set; }
/// <summary> /// <summary>
/// Overrides the build-in message icon. /// Custom text for the Ok button.
/// </summary> /// </summary>
public object MessageIcon { get; set; } public string OkButtonText { get; set; }
/// <summary> /// <summary>
/// Custom text for the Ok button. /// Custom icon for the Ok button.
/// </summary> /// </summary>
public string OkButtonText { get; set; } public object OkButtonIcon { get; set; }
/// <summary> /// <summary>
/// Custom icon for the Ok button. /// Custom text for the Confirmation button.
/// </summary> /// </summary>
public object OkButtonIcon { get; set; } public string ConfirmButtonText { get; set; }
/// <summary> /// <summary>
/// Custom text for the Confirmation button. /// Custom icon for the Confirmation button.
/// </summary> /// </summary>
public string ConfirmButtonText { get; set; } public object ConfirmButtonIcon { get; set; }
/// <summary> /// <summary>
/// Custom icon for the Confirmation button. /// Custom text for the Cancel button.
/// </summary> /// </summary>
public object ConfirmButtonIcon { get; set; } public string CancelButtonText { get; set; }
/// <summary> /// <summary>
/// Custom text for the Cancel button. /// Custom icon for the Cancel button.
/// </summary> /// </summary>
public string CancelButtonText { get; set; } public object CancelButtonIcon { get; set; }
/// <summary>
/// Custom icon for the Cancel button.
/// </summary>
public object CancelButtonIcon { get; set; }
}
} }

23
framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Messages/UiMessageType.cs

@ -1,14 +1,13 @@
namespace Volo.Abp.AspNetCore.Components.Messages namespace Volo.Abp.AspNetCore.Components.Messages;
/// <summary>
/// Defines the possible ui message types with predefined actions.
/// </summary>
public enum UiMessageType
{ {
/// <summary> Info,
/// Defines the possible ui message types with predefined actions. Success,
/// </summary> Warning,
public enum UiMessageType Error,
{ Confirmation,
Info,
Success,
Warning,
Error,
Confirmation,
}
} }

21
framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Notifications/IUiNotificationService.cs

@ -1,16 +1,15 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Volo.Abp.AspNetCore.Components.Notifications namespace Volo.Abp.AspNetCore.Components.Notifications;
public interface IUiNotificationService
{ {
public interface IUiNotificationService Task Info(string message, string title = null, Action<UiNotificationOptions> options = null);
{
Task Info(string message, string title = null, Action<UiNotificationOptions> options = null); Task Success(string message, string title = null, Action<UiNotificationOptions> options = null);
Task Success(string message, string title = null, Action<UiNotificationOptions> options = null); Task Warn(string message, string title = null, Action<UiNotificationOptions> options = null);
Task Warn(string message, string title = null, Action<UiNotificationOptions> options = null); Task Error(string message, string title = null, Action<UiNotificationOptions> options = null);
Task Error(string message, string title = null, Action<UiNotificationOptions> options = null);
}
} }

37
framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Notifications/NullUiNotificationService.cs

@ -2,27 +2,26 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
namespace Volo.Abp.AspNetCore.Components.Notifications namespace Volo.Abp.AspNetCore.Components.Notifications;
public class NullUiNotificationService : IUiNotificationService, ITransientDependency
{ {
public class NullUiNotificationService : IUiNotificationService, ITransientDependency public Task Info(string message, string title = null, Action<UiNotificationOptions> options = null)
{ {
public Task Info(string message, string title = null, Action<UiNotificationOptions> options = null) return Task.CompletedTask;
{ }
return Task.CompletedTask;
}
public Task Success(string message, string title = null, Action<UiNotificationOptions> options = null) public Task Success(string message, string title = null, Action<UiNotificationOptions> options = null)
{ {
return Task.CompletedTask; return Task.CompletedTask;
} }
public Task Warn(string message, string title = null, Action<UiNotificationOptions> options = null) public Task Warn(string message, string title = null, Action<UiNotificationOptions> options = null)
{ {
return Task.CompletedTask; return Task.CompletedTask;
} }
public Task Error(string message, string title = null, Action<UiNotificationOptions> options = null) public Task Error(string message, string title = null, Action<UiNotificationOptions> options = null)
{ {
return Task.CompletedTask; return Task.CompletedTask;
}
} }
} }

27
framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/Notifications/UiNotificationEventArgs.cs

@ -1,23 +1,22 @@
using System; using System;
namespace Volo.Abp.AspNetCore.Components.Notifications namespace Volo.Abp.AspNetCore.Components.Notifications;
public class UiNotificationEventArgs : EventArgs
{ {
public class UiNotificationEventArgs : EventArgs public UiNotificationEventArgs(UiNotificationType notificationType, string message, string title, UiNotificationOptions options)
{ {
public UiNotificationEventArgs(UiNotificationType notificationType, string message, string title, UiNotificationOptions options) NotificationType = notificationType;
{ Message = message;
NotificationType = notificationType; Title = title;
Message = message; Options = options;
Title = title; }
Options = options;
}
public UiNotificationType NotificationType { get; set; } public UiNotificationType NotificationType { get; set; }
public string Message { get; } public string Message { get; }
public string Title { get; } public string Title { get; }
public UiNotificationOptions Options { get; } public UiNotificationOptions Options { get; }
}
} }

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save