Install .net 7 and PostgreSQL.
Install Entity Framework Core tools
dotnet tool install --global dotnet-ef
dotnet build
dotnet test
There is a Postman Collection file.
You can import it in Postman with File > Import
.
Right click the collection and select Run Collection
.
cd Prosigliere.Blog.WebApi
dotnet ef database update
cd Prosigliere.Blog.WebApi
dotnet run
If you want to run the application with a Fake storage. Modify appsettings.Development.json. Keep in mind that the database will start from scratch each run. If you use this feature, it is not necessary to install Postgres.
{
"Storage": "Fake"
}
- Swagger UI: http://localhost:5041/swagger/index.html.
- Swagger Endpoint: http://localhost:5041/swagger/v1/swagger.json.
The solution contains a collection of projects each one defining an architectural layer.
Class Library. A collection of interfaces defining all possible operations in the application and all the data structures used as inputs and outputs for these operations (DTOs).
- Service Interfaces: Set of interfaces defining all possible operations. Arguments are
RequestObject
and the return type isResult<ResponseObject>
. - Request Objects: Input DTOs. Defined as C# records.
- Response Objects: Output DTOs. Defined as C# records.
- Result Object: Indicates that an operation could return multiple types depending on the situation. Used for error handling without exceptions.
Class Library. The application layer. Contains the business logic of the application.
Implements abstractions in Blog.Api
.
Interfaces with storage using Repository interfaces.
Easy to unit test in isolation from infrastructure, allowing a fast running unit tests suite.
- Service Objects: Implements Service Interfaces. Define business rules interacting in an abstract way with infrastructure.
- Repository Interfaces: Define data access operations in abstract.
- Entities: Persistant data types. Used as arguments and return types for Repository implementations. Used by EntityFramework (The Blog class library does not depend on EntityFramework).
- Validators: Define rules for Request Objects validation using FluentValidation.
WebApi Project. Contains all http, ASP MVC specific logic and EntityFramework implementations of Repositoes.
- Controllers: Define endpoint routes.
Proxies to Service objects.
Translate Result Objects to ASPT MVC
IActionResult
. Define Swagger documentation using Annotations. - Storage: Data access logic specific to EntityFramework.
- Migrations: EntityFramework migrations.
- Config: Connection string and other configurations in appsetting.json and appsettings.Development.json.
Class Library. Contains all the tests for the application logic/business rules. Fast unit tests. It runs isolated from the database. It does not test controllers.
- Tests: xUnit lightweight, behavioral style unit tests, isolated from database. They don't test implementation details. Services are tested as black boxes.
- Samples: Sample objects for testing purposes. Provide data necessary for tests to pass but not relevant for understanding the tests.
Class Library. Contains fake implementations of Repository objects for fast testing purposes. It is also possible to run the WebApi with Fakes.
The following diagram show the dependencies between projects.
- Authentication with JWT Token.
- Authorization.
- Validations to avoid users access data that belongs to another user.
- Update and Delete posts.
- Update and Delete comments.
- Tag Posts.