I have the following project structure and have a query with how best to expose the registered cache provider to them.
- Data Projects
– Data.Project.1 - Cache Projects
– CacheManager - Web Service Projects
– Web.Service.Project.1
The Data project is responsible for retrieving information from 3rd parties. These responses are then cached (in redis).
Web service and Data projects have a dependency on the Cache Manager project.
In the web service project, the cache provider is registered:
// cache
container.Register<IRedisClientsManager>(c => new PooledRedisClientManager("connection string"));
container.Register(c => c.Resolve<IRedisClientsManager>().GetCacheClient());
I then set a reference to the container in the cache manager project so anyone else who needs access to the cache can:
// set the container for cache to use
CacheManager.SetContainer(container);
The cache manager then looks something as follows:
public static class CacheManager
{
private static ICacheClient _client;
private static ICacheClient Client
{
get
{
if (_client == null)
{
_client = Container == null ? new MemoryCacheClient() : Container.Resolve<ICacheClient>();
}
return _client;
}
}
private static Container Container;
public static void SetContainer(Container container)
{
Container = container;
}
}
Now any projects that reference the cache manager project can go:
CacheManager.Client.Add("test", new List<int>());
What I want to find out is if this is the right way to go about this?