Skip to content

DorijanH/dotnet-starter

 
 

Repository files navigation

logo

Enterwell .NET starter

ASP.NET Core Web API using .NET 7 and PostgreSQL with Entity Framework Core following the principles of Clean Architecture.

Test .NET Starter CodeQL GitHub issues GitHub contributors GitHub pull requests

📖 Table of contents

🚀 Technologies

🛠 Prerequisites

🔰 Getting started

Downloading the starter

The easiest way to get started is to scaffold a copy of the repository by using degit.

If you don't already have it, you can easily install it by using the following command (assuming you have Node.js installed)

npm install --global degit

Now you can download the repository without any hassle and unnecessary git history using the following command

degit https://github.com/Enterwell/dotnet-starter dotnet-starter

Running the application

Set the Acme.Interface.WebAPI as the startup project, build and run the application.

Web API is available at https://localhost:7090 and the interactive Web API Swagger documentation at the https://localhost:7090/swagger.

PostgreSQL

By default, application will try to connect to PostgreSQL server running locally with the following configuration:

  • Port: 5432
  • Username: postgres
  • Password: password

If you have your server configured differently, change the connection string in the Acme.Interface.WebAPI/appsettings.Development.json file.

Database initialization (initial migration)

If the application was started for the first time, database needs to be initialized by executing the migrations.

  • After starting the application go to the Web API Swagger documentation available at https://localhost:7090/swagger.
  • You can see two ApplicationManagement endpoints:
    • /assert-migrations - used to remotely check if the database is up-to-date with the migrations
    • /migrate - used to remotely run the migrations
  • Execute the /migrate endpoint using Swagger docs
  • You can check if the migrations were ran by asserting once again
  • After running the migrations, database is seeded with a single admin user:

Generating new migrations

Generate a new migration using Visual Studio Package Manager Console (from menu: Tools -> NuGet Package Manager -> Package Manager Console):

  • Verify that the Acme.Infrastructure.EF.PostgreSql is selected as a default project
PM> Add-Migration <MIGRATION_NAME>

🏛 Project structure

Core

Core encapsulate enterprise wide business rules or, in simpler terms, core entities that are the business objects of the application. They encapsulate the most general and high-level rules. They are the least likely to change when something external changes. This contains all entities, enums, exceptions, interfaces, types and logic specific to the "domain" layer. This layer stands on its own and does not depend on any other layer or project.

Application

Layer that encapsulates and implements all of the use cases of the system, or to put it simply, all application logic. It is dependent on the Core layer and has no dependencies on any other layer or project. This layer contains classes that are based on the interfaces defined within the Core layer.

Infrastructure

Layer that contains classes for accessing external resources such as file systems, web services, SMTP, databases and so on. In this starter, we have Infrastructure.EF.PostgreSql layer that contains the Entity Framework logic for accessing PostgreSQL database. It is dependent on the Core layer and has no dependencies on any other layer or project. This layer also contains classes that are based on the interfaces defined within the Core layer.

Interface

Layer that acts as a set of adapters that convert data from the format most convenient for the use case and entities to the format most convenient for some external resource like the web API or CLI. In this starter, we have Infrastructure.WebAPI layer that contains the logic for mapping domain logic entities into DTOs used by the controllers for providing RESTful API to the web. This layer depends on both the Application and Infrastructure layers, however, the dependency on the Infrastructure layer is here only to support dependency injection.

So, to be frank, only Program.cs is referencing Infrastructure and for that reason, we previously had a separate layer called Interface.WebAPI.Starter that would be bootstrapping the application and its' DI container. But, to reduce the number of layers, we stopped with that practice.

☎ Support

If you are having problems, please let us know by raising a new issue.

🪪 License

This project is licensed with the MIT License.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%