/// <summary> /// StartJob /// </summary> /// <param name="config"></param> public void StartJob(InfrastructureConfig config) { //NLog.Logger _logger = GlobalConfiguration.Configuration.DependencyResolver.GetServices(typeof(NLog.Logger)).OfType<NLog.Logger>().SingleOrDefault(); //ICacheManager _memCache = GlobalConfiguration.Configuration.DependencyResolver // .GetServices(typeof(IIndex<CacheType, ICacheManager>)).OfType<IIndex<CacheType, ICacheManager>>().SingleOrDefault()[CacheType.MemoryCache]; //IRedisPubSub _redisPubSub = GlobalConfiguration.Configuration.DependencyResolver.GetServices(typeof(IRedisPubSub)).OfType<IRedisPubSub>().SingleOrDefault(); //ICacheManager _objRedisCache = GlobalConfiguration.Configuration.DependencyResolver // .GetServices(typeof(IIndex<CacheType, ICacheManager>)).OfType<IIndex<CacheType, ICacheManager>>().SingleOrDefault()[CacheType.RedisCache]; //if (config.IsUseRedisCache && config.UseAppCache) //{ // _redisPubSub.SubcribeMessage((m) => // { // try // { // if (m?.Length > 0) // { // _memCache.RemoveByPattern(m); // _objRedisCache.RemoveByPattern(m); // _logger.Trace("[" + DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + "]" + Environment.NewLine + "Sub from db " + m); // } // } // catch (Exception ex) // { // //log here // _logger.Trace("[" + DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + "]" + Environment.NewLine + "Sub from db " + m + " " + ex.Message); // } // }); //} }
public void Can_Read_Authenticated() { using (var cfg = new InfrastructureConfig(true)) { var addresses = IOFacadeService.Current.ReadEntityList <Address>(SearchCriteria.Create <AddressDTO>()); Assert.NotEmpty(addresses); Assert.True(addresses.Count == 1); Assert.True(addresses[0].ID == new Guid(MockAddresses.MOCK_ADDRESS_ID)); } }
/// <summary> /// /// </summary> /// <param name="config"></param> public void StartJob_bk(InfrastructureConfig config) { //ICacheManager _memCache = GlobalConfiguration.Configuration.DependencyResolver // .GetServices(typeof(IIndex<CacheType, ICacheManager>)).OfType<IIndex<CacheType, ICacheManager>>().SingleOrDefault()[CacheType.MemoryCache]; //IRedisPubSub _redisPubSub = GlobalConfiguration.Configuration.DependencyResolver.GetServices(typeof(IRedisPubSub)).OfType<IRedisPubSub>().SingleOrDefault(); //if (config.IsUseRedisCache && config.UseAppCache) //{ // _redisPubSub.SubcribeMessage((m) => // { // try // { // if (m?.Length > 0) // { // //Get message from sub chanel redis // string tableName = m.Split(',')[0]; // string tableNameRes = tableName + "Res"; // string dataJson = m.Substring(tableName.Length + 1, m.Length - tableName.Length - 1); // //message is json send from ws via redis pubsub message // //convert message to object // //create instant from table name (table name the same model entity) // foreach (var type in VNMuasam.Business.DTO.Helper.FuncHelper.GetListOfEntryAssemblyWithReferences()) // foreach (var item in type.GetTypes()) // if (item.Name == tableNameRes && item.GetConstructor(Type.EmptyTypes) != null) // { // var itemInstant = Activator.CreateInstance(item); // //Get info itemInstant convert to clear type // Type typeArgument = itemInstant.GetType(); // //genericClass // Type genericClass = typeof(UpdateDatas<>); // // MakeGenericType is badly named // Type constructedClass = genericClass.MakeGenericType(typeArgument); // //Create instant // object created = Activator.CreateInstance(constructedClass); // MethodInfo method = created.GetType().GetMethod("ConvertJsonToListData"); // //execute method // var listData = method.Invoke(created, new object[] { dataJson }); // method = created.GetType().GetMethod("UpdateCache"); // //execute method // method.Invoke(created, new object[] { tableName, listData, _memCache }); // } // //var itemInstant = (from t in VNMuasam.Business.DTO.Helper.FuncHelper.GetListOfEntryAssemblyWithReferences() // // where t.GetTypes().Select(i => i.Name == tableNameRes && i.GetConstructor(Type.EmptyTypes) != null).Count() > 0 // // select Activator.CreateInstance((from t2 in t.GetTypes() where t2.Name == tableNameRes select t2).SingleOrDefault())).SingleOrDefault(); // } // } // catch (Exception ex) // { // //log here // } // }); //} }
public void Cannot_Browse() { using (var cfg = new InfrastructureConfig(false)) { List <Address> addresses = null; Assert.Throws <SOLID.Store.Authorization.AuthorizationException>( () => addresses = IOFacadeService.Current.ReadEntityList <Address>( SearchCriteria.Create <AddressDTO>()) ); } }
public static void RegisterDependencies(IAppBuilder app) { var builder = InfrastructureConfig.Init(); // Register your MVC controllers. builder.RegisterControllers(typeof(MvcApplication).Assembly); // OPTIONAL: Register model binders that require DI. builder.RegisterModelBinders(Assembly.GetExecutingAssembly()); builder.RegisterModelBinderProvider(); // OPTIONAL: Register web abstractions like HttpContextBase. builder.RegisterModule <AutofacWebTypesModule>(); // OPTIONAL: Enable property injection in view pages. builder.RegisterSource(new ViewRegistrationSource()); // OPTIONAL: Enable property injection into action filters. builder.RegisterFilterProvider(); var container = builder.Build(); DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); }
public AzureQueue(IMemoryCache cache, InfrastructureConfig config) { _cache = cache; _infrastructureConfig = config; }
public void Register(InfrastructureConfig config) { var builder = new ContainerBuilder(); builder.RegisterControllers(Assembly.GetExecutingAssembly()); builder.RegisterApiControllers(Assembly.GetExecutingAssembly()); builder.RegisterWebApiFilterProvider(GlobalConfiguration.Configuration); builder.RegisterInstance(config).As <InfrastructureConfig>().SingleInstance(); builder.RegisterInstance(NLog.LogManager.GetCurrentClassLogger()).As <NLog.Logger>().SingleInstance(); builder.RegisterType <NLogger>().As <ILogger>().InstancePerLifetimeScope(); //builder.RegisterType<Core.Log.Implement.EsClient<Core.API.APILogEntry>>().As<IEsClient<Core.API.APILogEntry>>().InstancePerLifetimeScope(); builder.Register(c => new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString)) .As <IDbConnection>().InstancePerLifetimeScope(); builder.RegisterType <DapperReadOnlyRepository>().As <IReadOnlyRepository>().InstancePerLifetimeScope(); builder.RegisterType <DapperRepository>().As <IRepository>().InstancePerLifetimeScope(); if (config.IsUseRedisCache) { builder.RegisterType <RedisConnectionWrapper>().As <IRedisConnectionWrapper>().SingleInstance(); builder.RegisterType <RedisPubSub>().As <IRedisPubSub>().SingleInstance(); builder.RegisterType <RedisCacheManager>().Keyed <ICacheManager>(CacheType.RedisCache).SingleInstance(); builder.RegisterType <CacheHelperUseRedis>().As <ICacheHelper>().SingleInstance(); //builder.Register(c => new APIClient(new HttpClient())).As<IAPIClient>().SingleInstance(); } else { if (config.UseAppCache) { builder.RegisterType <CacheHelperNoRedis>().As <ICacheHelper>().InstancePerLifetimeScope(); } else { builder.RegisterType <DisableCacheHelper>().As <ICacheHelper>().InstancePerLifetimeScope(); } //API client //builder.Register(c => new APIClient(new HttpClient())).As<IAPIClient>().InstancePerLifetimeScope(); } if (config.UseAppCache) { builder.RegisterType <HttpContextCacheManager>().Keyed <ICacheManager>(CacheType.HttpContextCache).InstancePerLifetimeScope(); builder.RegisterType <MemCacheManager>().Keyed <ICacheManager>(CacheType.MemoryCache).InstancePerLifetimeScope(); } else { builder.RegisterType <DisableCache>().Keyed <ICacheManager>(CacheType.HttpContextCache).InstancePerLifetimeScope(); builder.RegisterType <DisableCache>().Keyed <ICacheManager>(CacheType.MemoryCache).InstancePerLifetimeScope(); } if (config.IsUsedKa) { builder.RegisterType <KafkaHelper>().As <IKafkaHelper>().SingleInstance(); builder.RegisterType <KafkaWrapper>().As <IKafkaWrapper>().SingleInstance(); } else { builder.RegisterType <DisableKafkaHelper>().As <IKafkaHelper>().InstancePerLifetimeScope(); } //builder.RegisterType<UserService>().As<IUserService>().InstancePerLifetimeScope(); // Services builder.RegisterAssemblyTypes(typeof(IUserService).Assembly) .Where(t => t.Name.EndsWith("Service")) .AsImplementedInterfaces().InstancePerRequest(); var container = builder.Build(); DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container); }