Web Api Clean Architecture

This serivce is an example of Clean Architure. This microservice's responsiblity is to manage things related to a Users & Roles.

This microservice solves all its goals. - a "... well-factored, SOLID applications using .NET Core."

It will demonstrate all SOLID principles. 1. reference link 1 2. reference link 2 3. reference link 3

Example of Clean Architecture

  1. SOLID

  2. N-Tiered Architecture

  3. Core Components - CGE.CleanCode.Common link

    a. Enums - Shared Enums used in solution projects.

    b. Extensions- Shared Extensions used in solution projects.

    c. Models -

    1. Dto - Data Transfer Objects - Used by the Web Api to represnent Database Resources.
    2. Patches - Models used for HTTPPatch requests.
  4. SharedKernel Project - .Common is our Shared Nuget package used by multiple Microservices.

  5. Infrastructure Project - CGE.CleanCode.Services - This is our Logic layer, the layer with all our Business Logic (Insfrastructure).

  6. Web Project - CGE.CleanCode.Api - This is our internet facing service - the WebApi.

Notes

Web Project - CGE.CleanCode.Api

1. `BaseController` ([link](https://github.com/DocGreenRob/clean-.net6-webapi-architecture/blob/main/src/CGE.CleanCode.Api/Controllers/BaseController.cs)) - used to hold objects that are common to all controllers (i.e., `TelemetryClient`, `Configuration`)

2.  Lightweight Controller Methods
[HttpDelete("{id}")]
		public async Task<IActionResult> DeleteAsync(string id)
		{
			await _branchService.DeleteAsync(id);
			await _serviceBusService.SendMessage(new BranchDto() { Id = id }, PayloadType.BranchDeleted.ToString());

			return Ok();
		}
  • no try/catch logic and heavy controller methods

  • should use Global Exception handler vs try/catch

  • business logic should not be in controller

a. link 1

b. link 2