diff --git a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs index 4a611f780f..0da0d28b4c 100644 --- a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs +++ b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs @@ -17,6 +17,7 @@ using Microsoft.AspNetCore.Mvc.ViewComponents; using Microsoft.Extensions.DependencyInjection.Extensions; using Volo.Abp.AspNetCore.Mvc.Conventions; using Volo.Abp.AspNetCore.Mvc.DependencyInjection; +using Volo.Abp.AspNetCore.Mvc.Localization; using Volo.Abp.AspNetCore.VirtualFileSystem; using Volo.Abp.Http; using Volo.Abp.Http.Modeling; @@ -65,12 +66,23 @@ namespace Volo.Abp.AspNetCore.Mvc }); var mvcCoreBuilder = services.AddMvcCore(); - services.GetPreConfigureActions().Configure(mvcCoreBuilder); + services.ExecutePreConfiguredActions(mvcCoreBuilder); - var mvcBuilder = services.AddMvc().AddControllersAsServices(); - services.GetPreConfigureActions().Configure(mvcBuilder); + var mvcBuilder = services.AddMvc() + .AddDataAnnotationsLocalization(options => + { + var assemblyResources = services.ExecutePreConfiguredActions(new AbpMvcDataAnnotationsLocalizationOptions()).AssemblyResources; + + options.DataAnnotationLocalizerProvider = (type, factory) => + { + var resourceType = assemblyResources.GetOrDefault(type.Assembly); + return factory.Create(resourceType ?? type); + }; + }); + + services.ExecutePreConfiguredActions(mvcBuilder); - //TODO: AddLocalization and AddViewLocalization by default..? + //TODO: AddViewLocalization by default..? services.TryAddSingleton(); services.TryAddSingleton(); diff --git a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Localization/AbpMvcDataAnnotationsLocalizationOptions.cs b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Localization/AbpMvcDataAnnotationsLocalizationOptions.cs new file mode 100644 index 0000000000..e1da69f3d5 --- /dev/null +++ b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Localization/AbpMvcDataAnnotationsLocalizationOptions.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Reflection; +using JetBrains.Annotations; + +namespace Volo.Abp.AspNetCore.Mvc.Localization +{ + public class AbpMvcDataAnnotationsLocalizationOptions + { + public IDictionary AssemblyResources { get; } + + public AbpMvcDataAnnotationsLocalizationOptions() + { + AssemblyResources = new Dictionary(); + } + + public void AddAssemblyResource([NotNull] Type resourceType, [CanBeNull] Assembly assembly = null) + { + if (assembly == null) + { + assembly = resourceType.Assembly; + } + + AssemblyResources[assembly] = resourceType; + } + } +} \ No newline at end of file diff --git a/src/Volo.Abp.Identity.Web/AbpIdentityWebModule.cs b/src/Volo.Abp.Identity.Web/AbpIdentityWebModule.cs index 3985d1199e..e63983ea9c 100644 --- a/src/Volo.Abp.Identity.Web/AbpIdentityWebModule.cs +++ b/src/Volo.Abp.Identity.Web/AbpIdentityWebModule.cs @@ -1,4 +1,7 @@ -using Microsoft.Extensions.DependencyInjection; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.AspNetCore.Mvc; +using Volo.Abp.AspNetCore.Mvc.Localization; using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap; using Volo.Abp.AutoMapper; using Volo.Abp.Identity.Web.Areas.Identity.Localization.Resource; @@ -15,6 +18,14 @@ namespace Volo.Abp.Identity.Web [DependsOn(typeof(AbpAspNetCoreMvcUiBootstrapModule))] public class AbpIdentityWebModule : AbpModule { + public override void PreConfigureServices(IServiceCollection services) + { + services.PreConfigure(options => + { + options.AddAssemblyResource(typeof(IdentityResource)); + }); + } + public override void ConfigureServices(IServiceCollection services) { services.AddAssemblyOf(); diff --git a/src/Volo.Abp.Identity.Web/Pages/Identity/Users/CreateModal.cshtml.cs b/src/Volo.Abp.Identity.Web/Pages/Identity/Users/CreateModal.cshtml.cs index 4adb000da0..70fcd1f365 100644 --- a/src/Volo.Abp.Identity.Web/Pages/Identity/Users/CreateModal.cshtml.cs +++ b/src/Volo.Abp.Identity.Web/Pages/Identity/Users/CreateModal.cshtml.cs @@ -49,19 +49,23 @@ namespace Volo.Abp.Identity.Web.Pages.Identity.Users { [Required] [MaxLength(IdentityUserConsts.MaxUserNameLength)] + [Display(Name = "UserName")] public string UserName { get; set; } [Required] [MaxLength(IdentityUserConsts.MaxPasswordLength)] [DataType(DataType.Password)] + [Display(Name = "Password")] public string Password { get; set; } [Required] [EmailAddress] [MaxLength(IdentityUserConsts.MaxEmailLength)] + [Display(Name = "EmailAddress")] public string Email { get; set; } [MaxLength(IdentityUserConsts.MaxPhoneNumberLength)] + [Display(Name = "PhoneNumber")] public string PhoneNumber { get; set; } } diff --git a/src/Volo.Abp.Identity.Web/Pages/Identity/Users/EditModal.cshtml.cs b/src/Volo.Abp.Identity.Web/Pages/Identity/Users/EditModal.cshtml.cs index c82c855c37..bdf49f4159 100644 --- a/src/Volo.Abp.Identity.Web/Pages/Identity/Users/EditModal.cshtml.cs +++ b/src/Volo.Abp.Identity.Web/Pages/Identity/Users/EditModal.cshtml.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; -using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc.RazorPages; @@ -62,14 +61,17 @@ namespace Volo.Abp.Identity.Web.Pages.Identity.Users [Required] [MaxLength(IdentityUserConsts.MaxUserNameLength)] + [Display(Name = "UserName")] public string UserName { get; set; } [Required] [EmailAddress] [MaxLength(IdentityUserConsts.MaxEmailLength)] + [Display(Name = "EmailAddress")] public string Email { get; set; } [MaxLength(IdentityUserConsts.MaxPhoneNumberLength)] + [Display(Name = "PhoneNumber")] public string PhoneNumber { get; set; } } diff --git a/src/Volo.Abp/Microsoft/Extensions/DependencyInjection/ServiceCollectionPreConfigureExtensions.cs b/src/Volo.Abp/Microsoft/Extensions/DependencyInjection/ServiceCollectionPreConfigureExtensions.cs index c5f9c68814..b1b819495b 100644 --- a/src/Volo.Abp/Microsoft/Extensions/DependencyInjection/ServiceCollectionPreConfigureExtensions.cs +++ b/src/Volo.Abp/Microsoft/Extensions/DependencyInjection/ServiceCollectionPreConfigureExtensions.cs @@ -12,6 +12,12 @@ namespace Microsoft.Extensions.DependencyInjection return services; } + public static TOptions ExecutePreConfiguredActions(this IServiceCollection services, TOptions options) + { + services.GetPreConfigureActions().Configure(options); + return options; + } + public static PreConfigureActionList GetPreConfigureActions(this IServiceCollection services) { var actionList = services.GetSingletonInstanceOrNull>>()?.Value;