标签:efault 自动 数据库 bsp open 取数 phrase 控制 pos
//cache managers
if (config != null && config.RedisCachingEnabled)
{
builder.RegisterType<RedisConnectionWrapper>().As<IRedisConnectionWrapper>().SingleInstance();
builder.RegisterType<RedisCacheManager>().As<ICacheManager>().Named<ICacheManager>("nop_cache_static").InstancePerLifetimeScope();
}
else
{
builder.RegisterType<MemoryCacheManager>().As<ICacheManager>().Named<ICacheManager>("nop_cache_static").SingleInstance();
}
builder.RegisterType<PerRequestCacheManager>().As<ICacheManager>().Named<ICacheManager>("nop_cache_per_request").InstancePerLifetimeScope();
protected virtual IList<ActivityLogTypeForCaching> GetAllActivityTypesCached()
{
//cache
string key = string.Format(ACTIVITYTYPE_ALL_KEY);
return _cacheManager.Get(key, () =>
{
var result = new List<ActivityLogTypeForCaching>();
var activityLogTypes = GetAllActivityTypes();
foreach (var alt in activityLogTypes)
{
var altForCaching = new ActivityLogTypeForCaching
{
Id = alt.Id,
SystemKeyword = alt.SystemKeyword,
Name = alt.Name,
Enabled = alt.Enabled
};
result.Add(altForCaching);
}
return result;
});
}
public class SettingsSource : IRegistrationSource
{
static readonly MethodInfo BuildMethod = typeof(SettingsSource).GetMethod(
"BuildRegistration",
BindingFlags.Static | BindingFlags.NonPublic);
public IEnumerable<IComponentRegistration> RegistrationsFor(
Service service,
Func<Service, IEnumerable<IComponentRegistration>> registrations)
{
var ts = service as TypedService;
if (ts != null && typeof(ISettings).IsAssignableFrom(ts.ServiceType))
{
var buildMethod = BuildMethod.MakeGenericMethod(ts.ServiceType);
yield return (IComponentRegistration)buildMethod.Invoke(null, null);
}
}
static IComponentRegistration BuildRegistration<TSettings>() where TSettings : ISettings, new()
{
return RegistrationBuilder
.ForDelegate((c, p) =>
{
////var currentStoreId = c.Resolve<IStoreContext>().CurrentStore.Id;
//uncomment the code below if you want load settings per store only when you have two stores installed.
//var currentStoreId = c.Resolve<IStoreService>().GetAllStores().Count > 1
// c.Resolve<IStoreContext>().CurrentStore.Id : 0;
//although it‘s better to connect to your database and execute the following SQL:
//DELETE FROM [Setting] WHERE [StoreId] > 0
return c.Resolve<ISettingService>().LoadSetting<TSettings>();
})
.InstancePerLifetimeScope()
.CreateRegistration();
}
public bool IsAdapterForIndividualComponents { get { return false; } }
}
public class CommonSettings : ISettings
{
public CommonSettings()
{
IgnoreLogWordlist = new List<string>();
}
/// <summary>
/// Gets or sets a value indicating whether stored procedures are enabled (should be used if possible)
/// </summary>
public bool UseStoredProceduresIfSupported { get; set; }
/// <summary>
/// Gets or sets a value indicating whether to use stored procedure (if supported) for loading categories (it‘s much faster in admin area with a large number of categories than the LINQ implementation)
/// </summary>
public bool UseStoredProcedureForLoadingCategories { get; set; }
/// <summary>
/// Gets or sets a value indicating whether 404 errors (page or file not found) should be logged
/// </summary>
public bool Log404Errors { get; set; }
/// <summary>
/// Gets or sets ignore words (phrases) to be ignored when logging errors/messages
/// </summary>
public List<string> IgnoreLogWordlist { get; set; }
}
public class HomeController : Controller
{
public ILogger _logger;
public IUserActivityService _userActivityService;
public CommonSettings _commonSettings;
public HomeController(
ILogger logger,
IUserActivityService userActivityService,
CommonSettings commonSetting)
{
_logger = logger;
_userActivityService = userActivityService;
_commonSettings = commonSettings;
}
public ActionResult Index()
{
TestSettings();
TestLogger();
return View();
}
private void TestSettings()
{
var s = _commonSettings.IgnoreLogWordlist;
}
private void TestLogger()
{
_logger.InsertLog(LogLevel.Information, "index visit");
_userActivityService.InsertActivity(ActivityLogTypeEnum.AddUser, "添加用户{0},{1}", new string[2] { "aaaa", "bbb" });
}
}
DataProvider: sqlserver
DataConnectionString: Data Source=.;Initial Catalog=nopFramework;Integrated Security=False;Persist Security Info=False;User ID=sa;Password=sa1234
private void TestLogger()
{
_logger.InsertLog(LogLevel.Information, "index visit");
_userActivityService.InsertActivity(ActivityLogTypeEnum.AddUser, "添加用户{0},{1}", new string[2] { "aaaa", "bbb" });
}
基于NopCommerce的开发框架——缓存、网站设置、系统日志、用户操作日志
标签:efault 自动 数据库 bsp open 取数 phrase 控制 pos
原文地址:http://www.cnblogs.com/dreling/p/6958829.html