我应该将哪种模式用于查找表?

时间:2012-06-29 09:25:44

标签: repository repository-pattern lookup-tables

我有四个查找表(现在只读)我需要一个模式在我的代码中使用这个表。 我像这样实现了Repository Pattern:

public interface ICellRepository
    {
        IEnumerable<CellLookup> GetCells();
    }

public class CsvCellRepository
        : ICellRepository
    {
        private readonly string _file;

        public CsvCellRepository(string file)
        {
            _file = file;
        }

        #region Implementation of ICellRepository

        public IEnumerable<CellLookup> GetCells()
        {
            if (string.IsNullOrEmpty(_file) || File.Exists(_file) == false)
            {
                throw new FileNotFoundException(string.Format("File not found:{0}", _file));
            }

            return File.ReadLines(_file)
                .Skip(1) // skip header
                .Select(s =>
                    {
                        var values = s.Split(',');
                        return new CellLookup
                                   {
                                       RncName = values[0],
                                       RncId = int.Parse(values[1]),
                                       NodeBId = string.IsNullOrEmpty(values[2]) == false ? int.Parse(values[2]) : 0,
                                       CellName = values[3],
                                       CellId = int.Parse(values[4]),
                                       Psc = int.Parse(values[5])
                                   };
                    });
        }

        #endregion
    }

这个实现解决了我的问题但是当我需要从数据库,WCF,从缓存或外部源读取查找时,我应该使用哪种模式?当我从IoC容器更改查找源时,代码无需进行任何更改。

0 个答案:

没有答案
相关问题