IStringLocalizer
接口。
修饰符“async”对此项无效
public async LocalizedString this[string name] => new LocalizedString(name, await I(name));
如何实施
IString定位器
使用EF核心异步数据访问的接口?
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
/// <summary>
/// Translation service.
/// Retrieves localized strings from database
/// </summary>
public sealed class Localizer : IStringLocalizer
{
readonly EevaContext ctx;
public Localizer(EevaContext ctx)
{
this.ctx = ctx;
}
async Task<string> I(string str)
{
return await ctx.Strings
.Where((s) => s.Est == estString.)
.SingleOrDefaultAsync();
}
#region interface implementation
public async LocalizedString this[string name] => new LocalizedString(name, await I(name));
public LocalizedString this[string name, params object[] arguments] => throw new NotImplementedException();
}
回答
async Indexer in C#