在域服务中设置 LocalizationSourceName

Moh*_*ehr 5 c# aspnetboilerplate

我有一个扩展 DomainService 抽象类的类,如下所示:

public class ScheduleManager : DomainService, IScheduleManager
Run Code Online (Sandbox Code Playgroud)

以下行不起作用:

throw new UserFriendlyException(L("ScheduleIsNotValid"));
Run Code Online (Sandbox Code Playgroud)

因为:Abp.AbpException:必须先设置LocalizationSourceName,才能获取LocalizationSource

只是想知道设置 LocalizationSourceName 的正确位置在哪里,就像在 MyCarParkControllerBase 中设置但在核心(域)层中设置一样?

顺便说一下,UserRegistrationManager 类中有两种本地化用法:

Line 96 >>> throw new UserFriendlyException(L("UnknownTenantId{0}", tenantId));
Line  101 >>> throw new UserFriendlyException(L("TenantIdIsNotActive{0}", tenantId));
Run Code Online (Sandbox Code Playgroud)

由于同样的问题而失败!

干杯,

Geo*_*ann 0

只是为了更清楚:

AbpServiceBase实施属性LocalizationSourceName

protected string LocalizationSourceName { get; set; }
Run Code Online (Sandbox Code Playgroud)

核心模块PreInitialize中,您可以在本地化配置器中找到:

MyProjectLocalizationConfigurer.Configure(Configuration.Localization);
Run Code Online (Sandbox Code Playgroud)

在该Configure方法中,您可以看到本地化的名称,该名称需要在构造函数中使用,如 @Alber Ebicoglu 已经显示的那样。

像这样:

public AbpLoginResultTypeHelper(IAccountAppService accountAppService)
{
    LocalizationSourceName = MyProjectConsts.LocalizationSourceName; //Localization name
    _accountAppService = accountAppService;
}
Run Code Online (Sandbox Code Playgroud)