RickStrahl / Westwind.Globalization

Database driven resource localization for .NET applications
543 stars 135 forks source link

Reload Resources programmatically in .NET Core? (please close) #178

Open Puliczek opened 5 years ago

Puliczek commented 5 years ago

How can I force to reload resources (clear cache) programmatically in .NET Core MVC?

if Namespace Westwind.Globalization.Web.Administration does not exist?

Right now Westwind works perfectly! Nonetheless, I have to restart app to get new Values from resources.

I have to do it programmatically because Westwind Admin Panel is in a different projects. I have second app only for admins stuff.

I would love to create API to clear cache in main app :P

Thanks for help!

Puliczek commented 5 years ago

Ok my answer:

    public class CacheService : ICacheService
    {
        private readonly DbResourceConfiguration _config;

        public CacheService(DbResourceConfiguration config)
        {
            _config = config;
        }

        public async Task ResetAsync()
        {
            DbResourceConfiguration.ClearResourceCache(); // resource provider

            DbResInstance DbIRes = new DbResInstance(_config);
            DbIRes.ClearResources(); // resource manager

            await Task.CompletedTask;
        }
    }