我有一个DAO、DTO和BO。下面的代码是结果:
// Instantiate a new user repository.
UserRepository rep = new UserRepository();
// Retrieve user by ID (returns DTO) and convert to business object.
User user = rep.GetById(32).ToBusiness<User>();
// Perform business logic.
user.ResetPassword();
user.OtherBusinessLogic("test");
user.FirstName = "Bob";
// Convert business object back to a DTO to save to the database.
rep.Save(user.ToDataTransfer<Data.DTO.User>());
所以我试图分离关注点,但我想要摆脱这段代码中的“converts”。在业务逻辑层中(DTO层不知道业务逻辑层),“converts”实际上作为扩展对象存储。DTO本身仅存储数据,没有任何业务逻辑。UserRepository调用DAO,并在GetById结束时使用AutoMapper从DAO映射到DTO。“converts”(ToBusiness和ToDataTransfer)正如它们描述的那样。
我的一位同事认为我可能需要一个业务库,但认为这可能有点笨重。你有什么想法吗?