public static IStorage <T> GetStorage()
        {
            IStorage <T> res      = null;
            var          typeName = typeof(T).Name;

            //Check if we have a store in the warehouse
            if (Warehouse.ContainsKey(typeof(T).Name))
            {
                res = (IStorage <T>)Warehouse[typeof(T).Name];
            }

            //If not then create a new one
            if (res == null)
            {
                var config = Global.GetConfig <StorageConfig>("StorageConfig");

                var typeStorageConfig = config.Types[typeName];

                var storageRepos = new List <IDataRepository <T> >();

                if (typeStorageConfig == null)
                {
                    typeStorageConfig = config.Types["Default"];
                }

                foreach (ReproItem repro in typeStorageConfig.Repros)
                {
                    IDataRepository <T> storageRepro = null;
                    switch (repro.Name)
                    {
                    case "WebCache":
                        storageRepro = new WebCacheRepository <T>();
                        break;

                    case "AzureCache":
                        storageRepro = new AzureWebCacheRepository <T>();
                        break;

                    //case "EditModelMemCache":
                    //    storageRepro = new EditModelMemcacheRepository<T>();
                    //    break;
                    case "MemCache":
                        storageRepro = new MemcacheRepository <T>();
                        break;

                    case "RavenDB":
                        storageRepro = new RavenDatabaseRepository <T>();
                        break;

                    case "Database":
                        storageRepro = DatabaseRepositoryFactory.GetRep <T>();
                        break;
                    }

                    storageRepos.Add(storageRepro);
                }

                res = new Storage <T>(storageRepos.ToArray <IDataRepository <T> >());

                if (!Warehouse.ContainsKey(typeof(T).Name))
                {
                    Warehouse.Add(typeof(T).Name, res);
                }
            }

            return(res);
        }
示例#2
0
 /// <summary>
 /// Always return default DatabaseRepository()
 /// </summary>
 /// <returns></returns>
 public static IDataRepository <object> GetRep()
 {
     return(DatabaseRepositoryFactory.GetRep <object>());
 }