当前位置: 首页 > news >正文

韩国优秀网站设计网站备案不通过

韩国优秀网站设计,网站备案不通过,默认wordpress菜单去除,wordpress 文章标题列表前言#xff1a; 作为领域模型中最重要的环节之一的Repository#xff0c;其通过对外暴露接口屏蔽了内部的复杂性#xff0c;又有其隐式写时复制的巧妙代码设计#xff0c;完美的将DDD中的Repository的概念与代码相结合#xff01;Repository资源库通常标识一个存储的区域…前言 作为领域模型中最重要的环节之一的Repository其通过对外暴露接口屏蔽了内部的复杂性又有其隐式写时复制的巧妙代码设计完美的将DDD中的Repository的概念与代码相结合Repository资源库通常标识一个存储的区域提供读写功能。通常我们将实体存放在资源库中之后通过该资源库来获取相同的实体每一个实体都搭配一个资源库。如果你修改了某个实体也需要通过资源库去持久化。当然你也可以通过资源库去删除某一个实体。资源库对外部是屏蔽了存储细节的资源库内部去处理 cache、es、db。数据操作流程Repository解除了client的巨大负担使client只需与一个简单的、易于理解的接口进行对话并根据模型向这个接口提出它的请求。要实现所有这些功能需要大量复杂的技术基础设施但接口却很简单而且在概念层次上与领域模型紧密联系在一起。隐式写时复制通常我们通过资源库读取一个实体后再对这个实体进行修改。那么这个修改后的持久化是需要知道实体的哪些属性被修改然后再对应的去持久化被修改的属性。注意商品实体的changes商品被修改某个属性对应的Repository就持久化相应的修改。这么写有什么好处呢如果不这么做那只能在service里调用orm指定更新列但是这样做的话Repository的价值就完全被舍弃了可以说写时复制是Repository和领域模型的桥梁//商品实体type Goods struct {changes map[string]interface{} //被修改的属性Name string//商品名称Price int// 价格Stock int// 库存}// SetPrice .func (obj *Goods) SetPrice(price int) {obj.Price priceobj.changes[price] price //写时复制}// SetStock .func (obj *Goods) SetStock(stock int) {obj.Stock stockobj.changes[stock] stock //写时复制}//示例func main() {goodsEntity : GoodsRepository.Get(1)goodsEntity.SetPrice(1000)GoodsRepositorySave(goodsEntity) //GoodsRepository 会内部处理商品实体的changes}工厂和创建创建商品实体需要唯一ID和已知的属性名称等可以使用实体工厂去生成唯一ID和创建在交给资源库去持久化这也是的作者推荐的方式但这种方式更适合文档型数据库唯一ID是Key和实体序列化是值。“底层技术可能会限制我们的建模选择。例如关系数据库可能对复合对象结构的深度有实际的限制(领域驱动设计软件核心复杂性应对之道 Eric Evans)但我们更多的使用的是关系型数据库这样资源库就需要创建的行为。实体的唯一ID就是聚簇主键。一个实体或许是多张表组成毕竟我们还要考虑垂直分表。我认为DDD的范式和关系型数据库范式后者更重要。有时候我们还要为Repository 实现一些统计select count(*)的功能。根据所使用的持久化技术和基础设施不同Repository的实现也将有很大的变化。理想的实现是向客户隐藏所有内部工作细节(尽管不向客户的开发人员隐藏这些细节)这样不管数据是存储在对象数据库中还是存储在关系数据库中或是简单地保持在内存中客户代码都相同。Repository将会委托相应的基础设施服务来完成工作。将存储、检索和查询机制封装起来是Repository实现的最基本的特性。实践https://github.com/8treenet/freedom/tree/master/example/fshop/adapter/repository实体的缓存这个是缓存组件的接口可以读写实体实体的key 使用必须实现的Identity 方法。一级缓存是基于请求的首先会从一级缓存查找实体生命周期是一个请求的开始和结束。二级缓存是基于redis。组件已经做了幂等的防击穿处理。SetSource设置持久化的回调函数当一、二级缓存未命中会读取回调函数并反写一、二级缓存。// freedom.Entitytype Entity interface {DomainEvent(string, interface{},...map[string]string)Identity() stringGetWorker() WorkerSetProducer(string)Marshal() []byte}// infra.EntityCachetype EntityCache interface {//获取实体GetEntity(freedom.Entity) error//删除实体缓存Delete(result freedom.Entity, async ...bool) error//设置数据源SetSource(func(freedom.Entity) error) EntityCache//设置前缀SetPrefix(string) EntityCache//设置缓存时间默认5分钟SetExpiration(time.Duration) EntityCache//设置异步反写缓存。默认关闭缓存未命中读取数据源后的异步反写缓存SetAsyncWrite(bool) EntityCache//设置防击穿默认开启SetSingleFlight(bool) EntityCache//关闭二级缓存. 关闭后只有一级缓存生效CloseRedis() EntityCache}以下实现了一个商品的资源库package repositoryimport (timegithub.com/8treenet/freedom/infra/storegithub.com/8treenet/freedom/example/fshop/domain/pogithub.com/8treenet/freedom/example/fshop/domain/entitygithub.com/8treenet/freedom)func init() {freedom.Prepare(func(initiator freedom.Initiator) {initiator.BindRepository(func() *Goods {return Goods{}})})}// Goods .type Goods struct {freedom.Repository //资源库必须继承这样是为了约束 db、redis、http等的访问Cache store.EntityCache //依赖注入实体缓存组件}// BeginRequestfunc (repo *Goods) BeginRequest(worker freedom.Worker) {repo.Repository.BeginRequest(worker)//设置缓存的持久化数据源,旁路缓存模型如果缓存未有数据将回调该函数。repo.Cache.SetSource(func(result freedom.Entity) error {return findGoods(repo, result)})//缓存30秒, 不设置默认5分钟repo.Cache.SetExpiration(30 * time.Second)//设置缓存前缀repo.Cache.SetPrefix(freedom)}// Get 通过id 获取商品实体.func (repo *Goods) Get(id int) (goodsEntity *entity.Goods, e error) {goodsEntity entity.Goods{}goodsEntity.Id id//注入基础Entity 包含运行时和领域事件的producerrepo.InjectBaseEntity(goodsEntity)//读取缓存 Identity() 会返回 id缓存会使用它当keyreturn goodsEntity, repo.Cache.GetEntity(goodsEntity)}// Save 持久化实体.func (repo *Goods) Save(entity *entity.Goods) error {_, e : saveGoods(repo, entity) //写库saveGoods是脚手架生成的函数会做写时复制的处理。//清空缓存repo.Cache.Delete(entity)return e}func (repo *Goods) FindsByPage(page, pageSize int, tag string) (entitys []*entity.Goods, e error) {build : repo.NewORMDescBuilder(id).NewPageBuilder(page, pageSize) //创建分页器e findGoodsList(repo, po.Goods{Tag: tag}, entitys, build)if e ! nil {return}//注入基础Entity 包含运行时和领域事件的producerrepo.InjectBaseEntitys(entitys)return}func (repo *Goods) New(name, tag string, price, stock int) (entityGoods *entity.Goods, e error) {goods : po.Goods{Name: name, Price: price, Stock: stock, Tag: tag, Created: time.Now(), Updated: time.Now()}_, e createGoods(repo, goods) //写库createGoods是脚手架生成的函数。if e ! nil {return}entityGoods entity.Goods{Goods: goods}repo.InjectBaseEntity(entityGoods)return}领域服务使用仓库package domainimport (github.com/8treenet/freedom/example/fshop/domain/dtogithub.com/8treenet/freedom/example/fshop/adapter/repositorygithub.com/8treenet/freedom/example/fshop/domain/aggregategithub.com/8treenet/freedom/example/fshop/domain/entitygithub.com/8treenet/freedom/infra/transactiongithub.com/8treenet/freedom)func init() {freedom.Prepare(func(initiator freedom.Initiator) {initiator.BindService(func() *Goods {return Goods{}})initiator.InjectController(func(ctx freedom.Context) (service *Goods) {initiator.GetService(ctx, service)return})})}// Goods 商品领域服务.type Goods struct {Worker freedom.Worker //依赖注入请求运行时对象。GoodsRepo repository.Goods //依赖注入商品仓库}// New 创建商品func (g *Goods) New(name string, price int) (e error) {g.Worker.Logger().Info(创建商品)_, e g.GoodsRepo.New(name, entity.GoodsNoneTag, price, 100)return}// Items 分页商品列表func (g *Goods) Items(page, pagesize int, tag string) (items []dto.GoodsItemRes, e error) {entitys, e : g.GoodsRepo.FindsByPage(page, pagesize, tag)if e ! nil {return}for i : 0; i len(entitys); i {items append(items, dto.GoodsItemRes{Id: entitys[i].Id,Name: entitys[i].Name,Price: entitys[i].Price,Stock: entitys[i].Stock,Tag: entitys[i].Tag,})}return}// AddStock 增加商品库存func (g *Goods) AddStock(goodsId, num int) (e error) {entity, e : g.GoodsRepo.Get(goodsId)if e ! nil {return}entity.AddStock(num) //增加库存entity.DomainEvent(Goods.Stock, entity) //发布增加商品库存的领域事件return g.GoodsRepo.Save(entity)}项目代码 https://github.com/8treenet/freedom/tree/master/example/fshop
http://www.yutouwan.com/news/350826/

相关文章:

  • 高端网站建设专家评价WordPress京东淘宝主题
  • 网站开发模板下载苏州网站建设排名
  • 个人主页网站模板免费wordpress 评论框 提示
  • 建设网站培训wordpress菜单管理
  • 网站建设合同要交印花吗wordpress繁体
  • 网站建设比较合理的流程软件开发项目管理文档
  • 网站建设哪里有学网站推广120种方法
  • 购物网站开发的必要性给手机做网站的公司
  • 网站建设 项目书 框架提供设计网站效果图
  • 法语网站建站公司定制化网站一般价格
  • 东莞有什么比较好的网站公司电子商务网站建设基础项目实训
  • 静态网站如何入侵有人有片吗视频免费的
  • 徐州模板建站定制网站wordpress给栏目页加后缀
  • 营销型网站建设申请域名免费开源小程序商城源码
  • 天津站内关键词优化c语言开发网站后端
  • 建设专业网站电话咨询公司网站需要修改
  • 贵州安顺建设局网站翻译网页
  • 网站建设三合一 500元多语言网站seo
  • 工商网站查询企业seo网站优化专员
  • 大连零基础网站建设培训中心wordpress 头部 固定
  • 网站为什么维护中在那些网站上做企业宣传好
  • 福州做网站软件汾阳做网站的公司
  • 一个人做网站难吗wordpress 清理插件
  • 怎么做网站模块网站关键词seo费用
  • 西安做网站的工资怎么样啊品牌网站建设公司有哪些
  • 莱芜网站开发免费推广网店
  • 给网站做路由wordpress调用7天热门文章
  • 开封做网站推广seo查询爱站
  • 做网站代码Sweipe wordpress
  • 宁远做网站ftontpage如何做网站