【发布时间】:2019-05-21 01:12:07
【问题描述】:
我有一个自定义约定,需要在其中包含本地化字符串。 AFAIK 实例化 IStringLocalizer 的唯一方法是 DependencyInjection。
如何在我的 CustomConvention 中使用 IStringLocalizer?
约定是这样注册的
public void ConfigureServices(IServiceCollection services)
{
//First I register the localization settings
services.AddLocalization(o =>
{
o.ResourcesPath = "Resources";
});
services.AddMvc(options =>
{
//My custom convention, I would need to inject an IStringLocalizer
//into constructor here, but I can' instantiate it
options.Conventions.Add(new LocalizationRouteConvention());
})
}
【问题讨论】:
标签: asp.net-mvc asp.net-core .net-core