private static void RegisterCacheService(ContainerBuilder builder)
{
try
{
if (Config.Cache.CacheType != CacheServiceType.Custom)
{
builder.RegisterType<HttpRuntimeCacheService>().As<ICacheService>().SingleInstance();
}
else
{
string customCacheTypeName = Config.Cache.GetValue("typeName");
if (!string.IsNullOrEmpty(customCacheTypeName))
{
Type customCacheType = Type.GetType(customCacheTypeName);
if (customCacheType == null)
{
throw new CmsException(string.Format("Failed to register a cache service. A specified type '{0}' was not found.", customCacheTypeName));
}
if (typeof(ICacheService).IsAssignableFrom(customCacheType))
{
builder.RegisterType(customCacheType).As<ICacheService>().SingleInstance();
}
else
{
throw new CmsException(string.Format("Failed to register a cache service. Specified type {0} is not inherited from the {1} interface.", customCacheTypeName, typeof(ICacheService).FullName));
}
}
else
{
throw new CmsException(
"Failed to register a cache service. The type name of the custom cache service is not specified. Please add to cms.config under cache section <add key=\"typeName\" value=\"your.full.custom.type.name\" />");
}
}
}
catch (Exception ex)
{
throw new CmsException("Failed to register a cache service.", ex);
}
}