Exemple #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            var services = new ServiceCollection();

            services.AddStackExchangeRedisCache(options =>
            {
                options.InstanceName = "RedisCluster";
                var config           = new ConfigurationOptions()
                {
                    Password = "******"
                };
                config.EndPoints.Add("localhost:6379");
                config.EndPoints.Add("localhost:6378");
                options.ConfigurationOptions = config;
            });
            services.AddMemoryCache();
            services.AddSingleton <ICachingService, DistributedCachingService>();
            services.AddSingleton <IStringConverter>(StringConverterFactory.Create());

            var serviceProvider = services.BuildServiceProvider();
            var cache           = serviceProvider.GetRequiredService <ICachingService>();

            var item = cache.GetOrCreate("test1", () => "Hello World");
        }
Exemple #2
0
        public void ConvertStringTest(object input)
        {
            var converter = StringConverterFactory.Create(input.GetType());
            var toString  = converter.ToString(input);
            var toSource  = converter.ToObject(toString);

            Assert.Equal(input, toSource);
        }
 /// <summary>
 /// Returns converter for current type
 /// </summary>
 /// <returns></returns>
 protected IStringConverter <T> GetConverter()
 {
     return(StringConverterFactory.Create <T>(ConverterProvider));
 }
Exemple #4
0
 /// <summary>
 /// Set the target property and corresponding mapping data
 /// </summary>
 /// <param name="target">Target property info on the target type</param>
 /// <param name="mappingAttribute">Mapping attribute</param>
 public void SetTarget(PropertyInfo target, TextFileMappingAttribute mappingAttribute)
 {
     this.TargetProperty   = target;
     this.MappingAttribute = mappingAttribute;
     _converter            = StringConverterFactory <T> .Get(this.TargetProperty, this.MappingAttribute);
 }
 public DistrobutedCachingServiceTests()
 {
     _distributedCache = new Mock <IDistributedCache>();
     _converter        = StringConverterFactory.Create();
     _cachingService   = new DistributedCachingService(_distributedCache.Object, _memoryCache, _converter);
 }