📎 Webclip
Clean Architecture With .NET 6 Using Entity Framework
The article continues a previous clean architecture walkthrough and focuses on adding Entity Framework to a .NET 6 solution with ASP.NET Core Web API. It introduces an AppSetting entity, places the database context interface in the Application layer, and implements the context in Infrastructure so persistence stays outside the core.
It also lists the packages needed for each project, shows how to register the persistence services, add the connection string in the Web API host, and run migration commands to create the database. The article ends by saying the next step will be a CRUD implementation.
Reading notes#
- The article is a continuation of a previous clean architecture post and keeps the same solution structure.
- The business case is an
AppSettingentity for storing application variables and configuration data such as SMTP details. - A generic
BaseEntity<T>holds theIdproperty so entities can reuse it. AppSettinginherits fromBaseEntity<int>and includesReferenceKey,Value,Description, andType.- The Application layer defines
IApplicationDBContextwith aDbSet<AppSetting>andSaveChangesAsync. - The Infrastructure layer implements
ApplicationDBContextby inheriting fromDbContextandIApplicationDBContext. - The solution uses SQL Server through Entity Framework Core packages installed in the Application, Infrastructure, and Web API projects.
- The Infrastructure
DependencyInjectionclass registersApplicationDBContextwithUseSqlServerand mapsIApplicationDBContextto it. - The Web API host stores the
RijsatDatabaseconnection string inappsettings.json. - The article instructs running
Add-Migration "DB Initialize"andUpdate-Databasewith Infrastructure as the default project and Web API as the startup project. - It says the database is created successfully and the next article will cover CRUD operations and Swagger testing.
