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

网站数据库名称怎么改wordpress怎么连接数据库配置文件

网站数据库名称怎么改,wordpress怎么连接数据库配置文件,网页设计代码步骤,徐州简欧室内设计公司排名概述#xff1a;_对象之间的关系_是使代码库难以理解和难以维护的原因。为了更好地理解它#xff0c;我们求助于马丁福勒#xff08;Martin Fowler#xff09;#xff1a;事件聚合器是间接的简单元素。在最简单的形式中#xff0c;您可以让它注册到您感兴趣的所有源对象_对象之间的关系_是使代码库难以理解和难以维护的原因。为了更好地理解它我们求助于马丁·福勒Martin Fowler事件聚合器是间接的简单元素。在最简单的形式中您可以让它注册到您感兴趣的所有源对象并让所有目标对象注册到事件聚合器。事件聚合器通过将源对象中的任何事件传播到目标对象来响应该事件。事件聚合器有很多好处。在本文中我将展示事件聚合器如何使我们更容易扩展应用程序。给我一个理由为了展示它如何使我们的代码更易于理解请查看以下模型public class User { public string Id { get; set; } public bool IsMarried_对象之间的关系_是使代码库难以理解和难以维护的原因。 想了解更多游戏开发知识,可以扫描下方二维码,免费领取游戏开发4天训练营课程 为了更好地理解它我们求助于马丁·福勒Martin Fowler 事件聚合器是间接的简单元素。在最简单的形式中您可以让它注册到您感兴趣的所有源对象并让所有目标对象注册到事件聚合器。事件聚合器通过将源对象中的任何事件传播到目标对象来响应该事件。 事件聚合器有很多好处。在本文中我将展示事件聚合器如何使我们更容易扩展应用程序。 给我一个理由 为了展示它如何使我们的代码更易于理解请查看以下模型 public class User {public string Id { get; set; }public bool IsMarried { get; set; } } public class Resume {public string Description { get; set; }public string UserId { get; set; }public bool IsUserMarried { get; set; } } public class Store {public string Title { get; set; }public string OwnerId { get; set; }public bool IsOwnerMarried { get; set; } }在这里并将用户的当前婚姻状况存储在一个名为 的字段中。假设每个实体都是一个聚合根因此每个实体都有自己的服务ResumeStoreIsUserMarried public class ResumeService {private readonly ICollectionResume db new ListResume {new Resume {Description My current resume,UserId 1,IsUserMarried false}};public void SetMaritalStatus(string userId, bool isMarried) {foreach (var resume in db.Where(a a.UserId.Equals(userId))) {resume.IsUserMarried isMarried;}} } public class StoreService {private readonly ICollectionStore db new ListStore {new Store {Title Restaurant,OwnerId 1,IsOwnerMarried false}};public void SetMaritalStatus(string ownerId, bool isMarried) {foreach (var store in db.Where(a a.OwnerId.Equals(ownerId))) {store.IsOwnerMarried isMarried;}} } public class UserService {private readonly ICollectionUser db new ListUser {new User {Id 1,IsMarried false}};private readonly ResumeService resumeService;private readonly StoreService storeService;public UserService(ResumeService resumeService, StoreService storeService) {this.resumeService resumeService;this.storeService storeService;}public void GotMarried(string userId) {var user db.First(a a.Id.Equals(userId));user.IsMarried true;// propagate changes to other parts of the coderesumeService.SetMaritalStatus(userId, true);storeService.SetMaritalStatus(userId, true);} }ResumeService并且两者都有一个更新用户婚姻状况的方法 。正如你所看到的对这两个服务都有依赖性因为当一个用户结婚时想要通知其他服务。此代码有效但有两个缺点StoreServiceSetMaritalStatusUserServiceUserService 1-实际上不依赖或执行其操作假依赖关系UserServiceResumeServiceStoreService 2-每当我们添加存储用户婚姻状况的新实体时我们必须记住更新难以扩展GotMarriedUserService 解决方案事件聚合器 与其引入依赖项其他服务不如调整定义一个事件UserService public class MaritalStatusChanged : IEvent { public MaritalStatusChanged(string userId, bool isMarried) { UserId userId; IsMarried isMarried; } public string UserId { get; } public bool IsMarried { get; } }然后我们需要更新.首先删除依赖项然后更新方法UserServiceGotMarried public class UserService { private readonly ICollectionUser db new ListUser { new User { Id 1, IsMarried false } }; private readonly IEventEmitter eventEmitterpublic UserService(IEventEmitter eventEmitter) { this.eventEmitter eventEmitter; } public void GotMarried(string userId) { var user db.First(a a.Id.Equals(userId)); user.IsMarried true; // propagate changes to other parts of the code eventEmitter.Publish(new MaritalStatusChanged(userId, true)); } }所以现在它只取决于事件发射器。活动发射器是我们的活动总线它在整个域中发布事件。现在如果想要了解此事件我们只需创建一个处理程序。例如这是一个添加到正文中的处理程序ResumeService public class MaritalStatusChangedHandler : IEventHandlerMaritalStatusChanged { private readonly ResumeService service; public MaritalStatusChangedHandler(ResumeService service) { this.service service; } public Task Handle(MaritalStatusChanged ev) { service.SetMaritalStatus(ev.UserId, ev.IsMarried); return Task.CompletedTask; } }将它们粘在一起 // 1- create an event bus var bus new DefaultEventBus(); // 2- create services var userService new UserService(bus); var resumeService new ResumeService(); var storeService new StoreService(); // 3- subscribe bus.SubscribeMaritalStatusChanged, ResumeService.MaritalStatusChangedHandler(new ResumeService.MaritalStatusChangedHandler(resumeService)); bus.SubscribeMaritalStatusChanged, StoreService.MaritalStatusChangedHandler(new StoreService.MaritalStatusChangedHandler(storeService)); // 4- someone got married userService.GotMarried(1);1- 这将创建事件总线。事件总线实现 IEventEmitter 和 IEventSink。 发布事件并允许您订阅事件。 完整代码 using libc.eventbus.System; using libc.eventbus.Types; using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks;namespace libc.eventbus.tests {[TestClass]public class Showcase2{[TestMethod]public void Showcase(){// 1- create an event busvar bus new DefaultEventBus();// 2- create servicesvar userService new UserService(bus);var resumeService new ResumeService();var storeService new StoreService();// 3- subscribebus.SubscribeMaritalStatusChanged, ResumeService.MaritalStatusChangedHandler(new ResumeService.MaritalStatusChangedHandler(resumeService));bus.SubscribeMaritalStatusChanged, StoreService.MaritalStatusChangedHandler(new StoreService.MaritalStatusChangedHandler(storeService));// 4- someone got marrieduserService.GotMarried(1);}public class UserService{private readonly ICollectionUser _db new ListUser{new User{Id 1,IsMarried false}};private readonly IEventEmitter _eventEmitter;public UserService(IEventEmitter eventEmitter){_eventEmitter eventEmitter;}public void GotMarried(string userId){var user _db.First(a a.Id.Equals(userId));user.IsMarried true;// propagate changes to other parts of the code_eventEmitter.Publish(new MaritalStatusChanged(userId, true));}}public class ResumeService{private readonly ICollectionResume _db new ListResume{new Resume{Description My current resume,UserId 1,IsUserMarried false}};public void SetMaritalStatus(string userId, bool isMarried){foreach (var resume in _db.Where(a a.UserId.Equals(userId))) resume.IsUserMarried isMarried;Console.WriteLine(${userId} is {(isMarried ? married : single)} now);}public class MaritalStatusChangedHandler : IEventHandlerMaritalStatusChanged{private readonly ResumeService _service;public MaritalStatusChangedHandler(ResumeService service){_service service;}public Task Handle(MaritalStatusChanged ev){_service.SetMaritalStatus(ev.UserId, ev.IsMarried);return Task.CompletedTask;}}}public class StoreService{private readonly ICollectionStore _db new ListStore{new Store{Title Restaurant,OwnerId 1,IsOwnerMarried false}};public void SetMaritalStatus(string userId, bool isMarried){foreach (var store in _db.Where(a a.OwnerId.Equals(userId))) store.IsOwnerMarried isMarried;Console.WriteLine(${userId} is {(isMarried ? married : single)} now);}public class MaritalStatusChangedHandler : IEventHandlerMaritalStatusChanged{private readonly StoreService _service;public MaritalStatusChangedHandler(StoreService service){_service service;}public Task Handle(MaritalStatusChanged ev){_service.SetMaritalStatus(ev.UserId, ev.IsMarried);return Task.CompletedTask;}}}public class MaritalStatusChanged : IEvent{public MaritalStatusChanged(string userId, bool isMarried){UserId userId;IsMarried isMarried;}public string UserId { get; }public bool IsMarried { get; }}public class User{public string Id { get; set; }public bool IsMarried { get; set; }}public class Resume{public string Description { get; set; }public string UserId { get; set; }public bool IsUserMarried { get; set; }}public class Store{public string Title { get; set; }public string OwnerId { get; set; }public bool IsOwnerMarried { get; set; }}} }
http://www.pierceye.com/news/84292/

相关文章:

  • 北京海淀网站建设网站建设 数据上传 查询
  • 网站下方一般放什么网上卖东西哪个平台好
  • 帝国cms怎么生成网站地图农业网站设计
  • 柯桥区住房和城乡建设局网站不合理的网站
  • 酒店网站建设趋势购买网站域名
  • 唐山APP小程序网站开发湖州网站建设培训教程
  • 肥东建设局网站做网站什么公司
  • 360网站卖东西怎么做网站开发 需求清单
  • 网站登录超时怎么解决网站首页404
  • 云南网站建设崇左西安将军山网站建设
  • 用手机做网站好学吗分类目录seo wordpress
  • 外贸网站的作用有哪些wordpress vue网站
  • 平谷手机网站建设个人做网络推广哪个网站好
  • 网站改版合同朝阳区手机网站设计服务
  • 莆田的外贸网站网站建设需求分析报告撰写
  • react用于做PC网站什么网站有高端定制案例
  • 如何自己做公司网站怎样做音乐网站
  • 用什么网站可以做链接百度账号快速注册入口
  • 一般网站使用什么做的外链工厂
  • 扬中网站网站建设windows wordpress 安装
  • 中国字体设计网站wordpress网站慢
  • 贵州网站制作建一个网站素材哪里来
  • 优秀的图片设计网站怎么做一个公众号微信
  • 榆次小学网站建设永久免费不收费的软件app
  • 全国建设项目验收信息网站站长工具域名查询
  • 双滦区seo整站排名建网站需要什么知识
  • 厦门建设厅查询网站首页做原创音乐的网站
  • 海南房地产网站页面设计大赛
  • 哪些网站可以做微商企业建设好一个网站后 如何进行网站推广
  • 网站建设这个郑州经济技术开发区政务服务中心