君不见长松卧壑困风霜,时来屹立扶明堂。这篇文章主要讲述如何将IStringLocalizer注入IApplicationModelConvention?相关的知识,希望能为你提供帮助。
我有一个自定义约定,需要在其中的本地化字符串。 AFAIK实例化IStringLocalizer的唯一方法是DependencyInjection。
如何在CustomConvention中使用IStringLocalizer?
【如何将IStringLocalizer注入IApplicationModelConvention()】该惯例是这样注册的
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());
})
}
答案我的解决方案并不漂亮。
您可以执行类似的操作,构建服务提供程序以获取StringLocalizer的实例。
public void ConfigureServices(IServiceCollection services)
{
//First I register the localization settings
services.AddLocalization(o =>
{
o.ResourcesPath = "Resources";
});
var stringLocalizer = services.BuildServiceProvider().GetService<
IStringLocalizer<
Resource>
>
();
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(stringLocalizer));
})
}
推荐阅读
- 将形状添加到LinearLayout Android
- 考虑在配置中定义类型为“com.gisapp.gisapp.dao.IUserDAO”的bean
- 如何在Spring Boot Application中使用JPA删除/ getList
- 带有@RequestParam和@RequestBody的Spring @GetMapping因HttpMessageNotReadableException而失败
- Xcode 8 App安装失败,出现未知错误
- Ad Hoc发布Xcode 10,App无法正常工作
- 是否有Eclipse的IntelliJ Keymapping插件()
- Android导出(如何创建.keystore文件())
- 在Ruby on Rails中集成Stripe和PayPal付款方式