简体   繁体   中英

Asp.Net Mvc service layer

I work on a MVC 5 web application. We have two projects, in one project there is a domain model, and everything else is in the other (service layer, controllers, views, etc).

That worked fine until we made a new WebApi project to expose some functionalities.

Now when we need some services from main project in our WebApi we need to copy paste service from main project to new web api project so we have duplicated code.

What I want to know is, is it a good practice to move whole service layer to the new project(dll) and then include it in main application and web api? Should we do this?

Avoid copying/past code, it will not help you in the future if you need maintain this project.

What I want to know is, is it a good practice to move whole service layer to the new project(dll) and then include it in main application and web api? Should we do this?

Yes, it is a good pratice and you could create a new assembly (a class library project) in your solution and reference and use it on the web and web api, or more projects you need it (windows, wpf, windows service ... for sample)

Look the image bellow, you could do something like this, separating you Domain Model, the Data Access Layer, Busines Layes (probably your service layer) and UI:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM