我需要根据用户所在的国家/地区对银行帐号进行格式设置。因此,而不是传递地点每次我需要的价值,e.g为:创建服务以根据用户会话确定字符串格式
Account.FormatBankAccountNumber("AU", bsb, accountNumber)
我想创建其内容从用户会话的位置(这是我们自定义存储的位置)服务的。
到目前为止,这是我:
public class AccountUtilityService : Service
{
public string FormatBankAccountNumber(string bsb, string accountNumber, bool obfuscate = false)
{
var session = base.SessionAs<CustomAuthSession>();
if (obfuscate) {
accountNumber = accountNumber.ObfuscationSensitiveInformation();
}
if (session.Region == RegionCodes.AU) {
return string.Format("({0}) - {1}", bsb, accountNumber);
}
return accountNumber;
}
}
那我就只需要自动线它像这样:
container.RegisterAutoWired<AccountDetailUtilityService>().ReusedWithin(Funq.ReuseScope.None);
所以现在需要这可能只是有服务注入AccountUtilityService,它将根据用户的会话自动返回格式,而不必指定用户的位置。
这有效,但只是想看看别人是否有更好的方式来做到这一点的想法?
只是想知道,BSB和账号不在澳大利亚才有意义吗?这不会使FormatBankAccountNumber非常通用。 – YetAnotherCoder
你说得对,我猜我认为这可能是许多这类逻辑之一。这个例子可能不是一个很好的例子。 – vonec