Bài viết khá hay về ASP.NET Core, có thể tham khảo về kiến trúc
A Visual Studio 2015 project which shows how to perform the create, read, update and delete operations in the ASP.NET Core MVC application using onion architecture with Entity Framework Core Code First approach.
The code illustrates the following topics:
- Listings, create, update and delete operations.
- One to one relationship in Entity Framework Core.
- Create, Update and Delete operations perform in bootstrap modal pop up with tag helpers.
- Database design using entity framework core code first approach with fluent API.
- Entity classes and repository in separate class library project and use migration to create database from it.
- Dependency injection for DbContext, Repository and service.
Article: Onion Architecture In ASP.NET Core MVC
To build and run this sample as-is, you must have Visual Studio 2015 installed. In most cases you can run the application by following these steps:
- Download and extract the .zip file.
- Open the solution file in Visual Studio.
- Change connection string in the appsettings.json file of the web project.
- Choose OA.Repo project in package manager console and run the following command for migration and create database.
- Tools –> NuGet Package Manager –> Package Manager Console
- PM> Add-Migration MyFirstMigration
- PM> Update-Database
- Run the application.
Running the Sample
To run the sample, hit F5 or choose the Debug | Start Debugging menu command. You will see the user list screen. From this screen you have user listing screen as shown in below figure.
Figure 1: User listing
Now click on “Add User” button to add new user in the application as per following screen.
Figure 2: Add User
As per figure 1, Edit button uses to edit individual user as per following figure.
Figure 3: Edit User
As per figure 1, Delete button uses to delete individual user as per following figure.
Figure 4: Delete User
Source Code Overview
Most of folders play same role as in MVC application but there are following more folder and files.
- wwwroot: It holds static js and css files.
- OA.Data: It’s separate class library project. It holds Entities and table configuration classes which create database.
- OA.Repo: It’s a class libraray project which holds DataContext and Repository.
- OA.Service: It’s a class libraray project which holds service interface which communicates to UI.
- appsettings.json:It holds database connection string.
- Migrations: It holds database migration files.