1

I have a requirement to create register-login application with mvc and this application needs to be multilayered.

I don't know so much about the multi layer architecture, i have just read about it few times. So i believe in a standart mvc application:

Presentation layer - my views Bussiness layer - Controls

and where should i put my data access layer? In my application when user clicks register, model comes into action. I check if the model is valid, put it into the database using entity framework and redirect user to welcome page but data access layer is missing in this architecture.

Where should i put my data access and what responsibilities i should give to it?

For example, should i move all entity framework code into some other class or just move the code that is putting user into database to model itself?

4

2 回答 2

1

您可以创建一个单独的项目作为数据访问层。将其连接到数据库并在本项目中使用 EF,并编写类以使用 EF 执行所有业务操作。您还可以将业务逻辑与实际的数据库访问逻辑分离,并将它们放在单独的项目中,但我认为这是不必要的,因为 EF 本身是一个 ORM,并且具有所有数据访问逻辑。

现在,在您的 MVC 项目中引用此项目,其中视图是您的表示层。模型可以是视图模型或业务模型。无论如何,您需要管理表示层和业务层之间的转换。不要在控制器中执行此操作。遵循 MVC 的“胖模型,瘦控制器”理念,创建一个单独的转换器类来执行此操作。

于 2014-08-18T14:31:08.110 回答
-2

您的视图是您的表示层,您的业务层必须是您的控制器。每个视图都与控制器交互,控制器与实体框架进行通信。

我建议您更准确地阅读 MVC 模型及其工作原理。

于 2014-08-18T14:16:21.180 回答