Last active
August 29, 2015 13:58
-
-
Save blair55/10183918 to your computer and use it in GitHub Desktop.
ServiceStack.Redis and StructureMap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Configuration; | |
using ServiceStack.Redis; | |
using StructureMap; | |
using StructureMap.Configuration.DSL; | |
namespace Example.IoC | |
{ | |
public class InfrastructureRegistry : Registry | |
{ | |
public InfrastructureRegistry() | |
{ | |
Scan(scan => | |
{ | |
scan.TheCallingAssembly(); | |
scan.WithDefaultConventions(); | |
}); | |
For<IRedisClientsManager>().Singleton().Use(() => | |
{ | |
var redisHost = ConfigurationManager.AppSettings["redisHost"]; | |
return new PooledRedisClientManager(redisHost) { ConnectTimeout = 1000 }; | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using ServiceStack.Redis; | |
namespace Example.Infrastructure | |
{ | |
public class DbManager : IDbManager | |
{ | |
private readonly IRedisClientsManager _redisClientsManager; | |
public DbManager(IRedisClientsManager redisClientsManager) | |
{ | |
_redisClientsManager = redisClientsManager; | |
} | |
public void ClearCache() | |
{ | |
using (var redisClient = _redisClientsManager.GetClient()) | |
{ | |
redisClient.FlushAll(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment