鸟随凤鸾,人伴贤良,得以共之,我之幸也。说的是鸟随着鸾凤可以飞的更高远,人和比自己境界高的相处,自己也会得到熏染进步。
分享出来简单的心得,望探讨
依赖倒置
依赖注入
Adapter模式
Null模式
二、快速示例
从一个简单的示例开始,业务流程Client通过Service查询产品,基础大概框架如下
关键代码:
1 class ProductService 2 { 3 4 private ProductRepository _productRepository; 5 6 public ProductService() 7 { 8 _productRepository=new ProductRepository(); 9 } 10 11 public IList<Product> GerAllProductsIn(int category) 12 { 13 IList<Product> products; 14 string storagekey = string.Format("product_category_id_{0}",category); 15 products =(List<Product>) HttpContext.Current.Cache.Get(storagekey); 16 17 if (products==null) 18 { 19 products=_productRepository.GetAllProductsIn(category); 20 HttpContext.Current.Cache.Insert(storagekey,products); 21 } 22 return products; 23 } 24 }