Web API Business Layer Architecture and its responsibilities

3.3k Views Asked by At

I have following classes in my web api business layer, i was wondering if GatewayService class should be in Business layer or should i put that in separate project called BusinessService? because its not being directly called in controller class and it doesn't depend on data repository ?

Business Layer

  • GatewayService (referencing < dll file > methods and making calls to external web service and returning list of transactions)
  • UserService (returns a list of all users from production database using < repository class > from data layer)
  • TransactionService ( get a list of all users from < UserService > and then get all their transactions from < Gateway Service > )

Here is what Transaction Controller doing;

Transaction Controller

Getting a list of users from < UserService >

Passing a list of Users to < TransactionService > which will then return a list of user transactions

Passing a list of all transactions to < TransactionService > to process them through a data repository class

2

There are 2 best solutions below

6
On

In case of N-Layer architecture

TransactionService should be in an Application layer, then your GatewayService can be part of the Business Layer.

enter image description here

In case of Clean Architecture

GatewayService should be part of Presistence or Infrastracture layer so it is not a business layer (here domain and application).

enter image description here

0
On

It would be a part of the business layer. The business layer is where you would implement the external requirements for your system fx. logistics and so. Which falls under the same category as your gateway service.