Controller-Service architecture. What is service?
I'm developing an ASP.NET REST API and use the Controller-Service architecture (I don't have a data layer). And I have the following question: what is a service? Is it a facade object for the controller? In this case, I have two main groups of objects: Services and Controllers, each of which is in its own namespace(folder), where, in this case, should I put the rest of the classes that the service uses? In 'Model'? In 'Core'?
4 Replies
If anything, it's the controller that's a facade for the service
Controllers, ideally, should just do
@ВОСТОЧНЫЙ КАЛИМАНТАН the core concept is you follow single responsibility principle. Controller Or yourweb project to deal with Http, authentication,caching, configuration etc (it is basically a host for your business logic).
Then create a project for you business process (eg: UserService, OrderService, CheckoutService)
finally create a infrastructure project to deal with external dependencies (eg:DB, cache server, Payment gateway api)
The idea is you can change the host anytime (API, or MVC pages application, Desktop application)
Same way you can also change the infra (i.e. change SQL to cosmos db, or switching to new payment gateway). Changing host or infra will not impact your business logic.
this is just a basic setup, you can extend or trim based on your need. Don't spend to much time on this, there are some good templates you can use it. https://github.com/ardalis/CleanArchitecture
GitHub
GitHub - ardalis/CleanArchitecture: Clean Architecture Solution Tem...
Clean Architecture Solution Template: A starting point for Clean Architecture with ASP.NET Core - GitHub - ardalis/CleanArchitecture: Clean Architecture Solution Template: A starting point for Clea...
Thanks!
controller is the part that exposes commands of your application via http and generically deals with http stuff
ideally if you have more than one way of callings commands (let's say http and telnet) you could have an AppService layer that implements the commands and then the i/o stuff calls that layer