essentially we don’t use layers in the n-tier sense
This would be a pretty simple but typical example of a Web API solution
Code:
Model
DbContexts
Models
Infrastructure
Things that arent business-specific, but are needed.
Basically "glue" code in a way. It references none of the other projects
Generic extension methods to linq, eg ForEachAsync, PaginatedListAsync
Maybe you need an abstraction to add messages to a queue e.g. IQueueService, RabbitMqQueueService: IQueueService
Maybe you want to send emails. IEmailClient/Service, SendGridEmailService/Client
Application
This is where the magic happens, and it starts with Feature folders. What's important to note is that this is all autowired
Customers
GetAll.cs //here you name space
public class GetAll {
public class Request {}
public class Model {} //yes, you can choose to use a shared model/response e.g your GetAll returns a list of the same model that your GetById uses. or you can duplicate, really depends
public class Handler {}
}
GetById.cs
Orders
GetByCustomer //alternate way to go a folder deeper and split classes into their own files
Request.cs
Response/Model.cs
Handler.cs
MappingProfile.vs
WebApi
Controllers
CustomerController.cs
public class CustomerController {
[HttpGet]
public async Task<ActionResult> Get()
{
// ALL controllers end up following the same 2 line pattern, controllers become irrelavent, they convert an http request into a Query or a Command
var result = await _mediator.Send(new MyQuery());
return Ok(result);
}
}
Startup.cs
etc
So here is the crazy/controversial part - put
EVERYTHING in your handler... WHAT!!! just try it
Standard clean code rules apply.
When smells appear, refactor, red, green.
Just because 2 things look that same doesn't mean they are the same.