[英]Can I use viewmodels in my MVC(.net core 3.0) project in my ApplicationLogic project (net standard 2.1)
I have an MVC app where all my view models are in. I added a Business Logic layer project, which is a class library project net standard 2.1, where all my interfaces and services are.我有一个 MVC 应用程序,我的所有视图模型都在其中。我添加了一个业务逻辑层项目,这是一个 class 库项目网络标准 2.1,我的所有接口和服务都在其中。 I am trying to use my viewmodels in the business logic project, but I can not reference them there.
我正在尝试在业务逻辑项目中使用我的视图模型,但我无法在那里引用它们。 I wanted to know can I reference an MVC app in a class library, if not where can I put my view models if I don't want to add DTOs because my app is not a very big project.
我想知道是否可以在 class 库中引用 MVC 应用程序,如果我不想添加 DTO,我可以将我的视图模型放在哪里,因为我的应用程序不是一个很大的项目。
There's a lot of confusion here.这里有很多混乱。 First, there's nothing magical about a view model or DTO, and the names are merely descriptive of a particular context of usage.
首先,视图 model 或 DTO 并没有什么神奇之处,其名称只是对特定使用上下文的描述。 At the end of the day, you have a class that represents some collection of data in a particular context: that is all.
归根结底,您有一个 class 代表特定上下文中的一些数据集合:仅此而已。 Second, business logic is not application logic.
其次,业务逻辑不是应用程序逻辑。 Application logic is about presentation and user interaction, whereas business logic is about raw data.
应用程序逻辑是关于表示和用户交互的,而业务逻辑是关于原始数据的。 Those two things should not cross because business rules should not determine presentation and presentation should not determine business rules.
这两件事不应该交叉,因为业务规则不应该决定展示,展示也不应该决定业务规则。
The business layer should not know anything about your view models in your application layer (the MVC app), as that would create a tight coupling (and a circular reference, FWIW).业务层不应该对应用层(MVC 应用程序)中的视图模型一无所知,因为这会产生紧密耦合(以及循环引用,FWIW)。 The logic for mapping to/from the view models in the application layer to the entities in the business layer is the domain of the application layer alone.
将应用层中的视图模型映射到/从应用层中的实体映射到业务层中的实体的逻辑仅是应用层的领域。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.