-2

I'm going to start a new project which has the architecture below:

  1. Entities (only entities like Customer) - Class Library
  2. BLL (Business logics for Customer - models) - Class Library
  3. DAL (SQL calls from this layer) - Class Library
  4. CommonUtilities (Enums, common functions) - Class Library
  5. MVC Web project - has views & controllers - Web project

Question 1: Is it a good practice to use this architecture? or should I improve something more to it?

Question 2: What is Web API and should I use it as a separate layer too?

Please let me know if you have better architecture for code maintainability.

Haytam
  • 4,643
  • 2
  • 20
  • 43
Kavi
  • 140
  • 1
  • 9

1 Answers1

1

Question 1: Is this a good practice to use this architecture? or Should I improve something more to it?

Yes. It makes all the parts of your software loosely coupled, which means you can swap an implementation of a layer by another implementation, without having the trouble of having to heavily refactor your code. You could, with this architecture, easily add a smartphone application that reuses all layers that the ASP.NET web application uses now.

Question 2: & what is Web API, Should I use it as a separate layer too?

This would mean that your web application uses a web service layer that exposes all your application functionality: the web application talks with the Web API layer by means of a web service protocol like REST, the Web API layer then uses the business logic layer. So it's an extra layer.

It might be interesting to add it if you want to allow other developers to use your business logic, or when you plan to make an extra frontend application later, for example for smartphone, of which you know you won't be able for some reason to program it in .NET, meaning you already know you won't be able to call your business logic layer directly. In that case you would need web services in between for sure.

Also, if you don't have a web service layer in between, you'll have to recompile your frontend applications everytime you have changed the implementation of one of your lower layers. If your frontend applications, however, just consume a web service, this is not the case: your application is no longer consuming DLLs, but just passing messages back and forth over an internet connection.

This does not mean you must create a Web API layer between your application and business logic layer every time. It is overkill when you know this application will be the only frontend you'll ever build for this use case, and when a API to other developers will not be required either. If you don't know for sure, or think chances are little these requirements will come, start simple, without a Web API layer. You can add that layer later if it becomes necessary.

Sander Vanden Hautte
  • 2,138
  • 3
  • 22
  • 36
  • So currently I don't need it. thanks a lot. Do you have any idea why did I get -2 here? I'm surprised. – Kavi Feb 24 '18 at 14:17
  • You're welcome. You were downvoted because a lot of Stackoverflow members flag questions when they think the question will attract a lot of answers based on opinions instead of facts. My answer to your question could be seen as an opinion: someone else could've answered your first question with: "No. If you're developing a simple project, then just write all your code in your MVC Controller.". Or even someone else could've stated that he thought you should not use the layers you proposed, but just an application layer and a helper classes layer. And so on. – Sander Vanden Hautte Feb 24 '18 at 14:46
  • @KaviYarasan: I personally **do** think, however, that you posted a good question, useful to a lot of people. I also think that if a question would attract opinionated answers, it would still be OK as long as the opinionated answers have a clear reasoning that can be reacted to in the comments, or can be discussed in other answers, on condition that these, again, have clear reasoning, and so on. StackOverflow states, though, that it doesn't want to be a forum and that there's forums enough. Check the debate: https://meta.stackoverflow.com/questions/278500/where-can-i-post-opinionated-questions – Sander Vanden Hautte Feb 24 '18 at 15:31