Node.js应用程序中的域驱动设计 [英] Domain Driven Design in Node.js Application

查看:100
本文介绍了Node.js应用程序中的域驱动设计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TL; DR;
我正在寻找DDD node.js应用程序的典型示例。

我要创建节点应用程序。我想知道我找不到任何在域中分离业务逻辑的应用程序示例。

I'm going to create node application. I wonder that I can not find any example of application with business logic separated in domain.

好的,有一些例子:
https://github.com/adrai/node-cqrs-domain - 但这是整个CQRS与事件采购实现。

OK, there are some examples like: https://github.com/adrai/node-cqrs-domain - but this is whole CQRS with event sourcing implementation.

我的想法是这样做:

//domain/book.js
function Book(title, author)
{
  this._title = title;
  this._author = author;
}

// domain methods ...

//infrastructure/persistance/repository/book-repository.js
function BookRepository()
{}

BookRepository.prototype.save(book)
{
  var bookModel = mappers.mapToOrm(book);
  return bookModel.save();
}

// [...] get, getAll, getNextId

//infrastructure/persistance/orm/book.js
//using http://bookshelfjs.org/
var Book = bookshelf.Model.extend({
  tableName: 'books'
});

//infrastructure/mappers/book-mapper.js
function mapToOrm(book) {
  //mapping [...]
  return new persistance.Book();
}

function mapToDomain(domain) {
  //mapping [...]
  return new domain.Book();
}

但另一方面我从未见过任何类似的解决方案(带域名)模型,orm模型,存储库和映射器)。我是以正确的方式思考的吗?也许没有理由在node.js应用程序中分离域中的业务逻辑。如果是这样,为什么?如果没有,你能给我一个DDD实现的例子或改进我的代码吗?

but on the other hand I've never seen any similar solution (with domain model, orm model, repository and mappers). Am I thinking in the right way? Maybe there is no reason to separate business logic in domain in node.js applications. If so, why? If not, can you send me an example of DDD implementation or improve my code?

[2017/01/13]

我在TypeScript中创建了示例应用程序。目前没有存储库,没有太多服务。欢迎提出问题和拉取请求。
https://github.com/dawiddominiak/ddd-typescript -bin-packing-problem-solution

I've created sample application in TypeScript. For now without repositories and not much services. Issues and pull requests are welcome. https://github.com/dawiddominiak/ddd-typescript-bin-packing-problem-solution

推荐答案

我是Node.js世界的新手。

I'm very new to Node.js world.

但我相信如果你使用 TypeScript with Node 进行工作,你可以强制使用大多数DDD原则。

But I believe if you do your work using TypeScript with Node you can force most of DDD principles to be used.

node.js中的问题和同时的优势没有像我们在C#或Java等OOP语言中那样的限制。这种自由和凌乱的JavaScript 使得创建强大复杂的DomainModel和业务逻辑非常困难

The problem "and advantage in the same time" in node.js that there aren't so restrictions like we have in OOP languages like C# or Java. and this freedom "and messy" of JavaScript making create robust complex DomainModel and Business logic very hard

这篇关于Node.js应用程序中的域驱动设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆