ASP.NET Core 1.1 Localization Generic Service

Viewed 1157

I'm making a ASP.NET Core 1.1 app and trying to setup localization.

When I make on my ValuesController the implementation of IStringLocalizer it works fine and localize my resource file.

public ValuesController(IStringLocalizer<ValuesController> localizer, IService<BaseEntity> service)
{
    _localizer = localizer;
    _service = service;
}

The code above locate my resources at "Resources/Controllers/ValuesController.en-US.resx".

But, when I try to inject the IStringLocalizer with a generic service it can't find my resource file.

public class Service<T> : IService<T>
    where T : BaseEntity
{
    #region Properties
    protected IRepository Repository { get; set; }
    protected IUnitOfWorkFactory UnitOfWorkFactory { get; set; }
    private readonly ILogger _logger;
    private readonly IStringLocalizer _localizer;

    #endregion

    #region Ctor
    public Service(IRepository repository, IUnitOfWorkFactory unitOfWorkFactory,
        ILogger<Service<T>> logger, IStringLocalizer<Service<T>> localizer)
    {
        Repository = repository;
        UnitOfWorkFactory = unitOfWorkFactory;
        _logger = logger;
        _localizer = localizer;
    }
}

The code above doesn't locate my resource at "Resources/Services/Base/Service.en-US.resx"

Any idea on how to do it ?

--- EDIT

MyControl.Api (Startup.cs)

namespace MyControl.Api

services.AddLocalization(options => options.ResourcesPath = "Resources");

This line is inside "MyControl.Api", with is in the namespace "MyControl.Api".

The resources folder in this aplication work for "Resources/Controllers"

My services are in namespace "MyControl.Services"

The resources folder in this Project (two projects inside same solution) are

"Resources/Services/Base"

The namespace of my service file is "MyControl.Services.Services.Base"

1 Answers
Related