In order to use the IStringLocalizer
service in your AutoMapper profile, you can inject it into your profile constructor like this:
main.cs460 chars17 lines
In this example, I'm injecting the IStringLocalizer
service into the profile constructor and storing it in a private field. Then, in the CreateMap
method, I'm using the ForMember
method to map the SomeProperty
property of my FooDto
to a localized string. The []
indexer of the _localizer
object is used to retrieve the localized text, and the second parameter is the default text to use if the requested localization isn't found.
Make sure that you have setup localization correctly in your application, by configuring the supported cultures and local resource files.
Note: Please keep in mind that, injecting services directly into Profiles is not a recommended practice. Rather, you should map IStringLocalizer to a custom type and inject that type in your Profile.
gistlibby LogSnag