Skip to content

Commit 5e55cb5

Browse files
committed
2 parents 1f26d05 + ede959d commit 5e55cb5

File tree

1 file changed

+344
-3
lines changed

1 file changed

+344
-3
lines changed

README.md

Lines changed: 344 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,347 @@
1+
# What is AspnetRun ?
2+
A **starter kit** for your next **ASP.NET Core** web application. Boilerplate for **ASP.NET Core reference application** with **Entity Framework Core**, demonstrating a layered application architecture with DDD best practices. Implements NLayer **Hexagonal architecture** (Core, Application, Infrastructure and Presentation Layers) and **Domain Driven Design** (Entities, Repositories, Domain/Application Services, DTO's...)
3+
and aimed to be a **Clean Architecture**, with applying **SOLID principles** in order to use for a project template.
4+
Also implements **best practices** like **loosely-coupled, dependency-inverted** architecture and using **design patterns** such as **Dependency Injection**, logging, validation, exception handling, localization and so on.
5+
6+
You can check full repository documentations and step by step development of **[100+ page eBook PDF](http://www.aspnetrun.com/Book)** from here - **http://www.aspnetrun.com/Book**. Also detail introduction of book and project structure exists on **[50+ page of github wiki](https://github.com/aspnetrun/run-core/wiki)**. You can follow **aspnetrun repositories** for building **step by step** asp.net core **web development skills**.
7+
8+
# AspnetRun Repositories
9+
Here you can find all of the **aspnetrun repositories from easy to difficult**, Also this list can be track a **learning path** of asp.net core respectively;
10+
* **[run-aspnetcore-basic](https://github.com/aspnetrun/run-aspnetcore-basic)** - intented to building Multi-Page Web Applications(MPA) using ASP.NET Core Default Web Application template with EF.Core. This solution **only one solution one project** fastest **idea generation** with Asp.Net Core. **YOU ARE HERE.**
11+
* **[run-aspnetcore](https://github.com/aspnetrun/run-aspnetcore)** - intented to building traditional Multi-Page Web Applications(MPA) using ASP.NET Core & EF.Core and **Razor Pages** templates with default aspnet core server-side rendering approach.
12+
* **[run-aspnetcore-spa](https://github.com/aspnetrun/run-aspnetcore-spa)** - intented to building **Single-Page Web Applications(SPA)** using only ASP.NET Core **without any frontend framework**.This comes with **Blazor** framework from Microsoft which basically using **SSB (Server-Side Blazor)** templates.
13+
* **[run-angular](https://github.com/aspnetrun/run-angular)** - intented to building Single-Page Web Applications(SPA) using ASP.NET Core & EF.Core, Web API Project and **Angular** for frontend framework.
14+
15+
And there are crucial repositories which are **implemented base repository** and **applying real-world examples** with developing new enterprice features for example Identity, Paging, Localization etc..
16+
* **[run-aspnetcore-basic-realworld](https://github.com/aspnetrun/run-aspnetcore-basic-realworld)** - implemented this repository and build **sample of eCommerce reference application** on Multi-Page Web Applications(MPA) using ASP.NET Core in a **one solution one project for fastest idea implementations**.
17+
* **[run-aspnetcore-realworld](https://github.com/aspnetrun/run-aspnetcore-realworld)** - implemented run-aspnetcore repository and build **sample of eCommerce reference application** on Multi-Page Web Applications(MPA) using ASP.NET Core Razor Pages templates.
18+
* **[run-aspnetcore-spa-realworld](https://github.com/aspnetrun/run-aspnetcore-spa-realworld)** - implemented run-aspnetcore-spa repository and build **sample of eCommerce reference application** on **Single-Page Web Applications(SPA)** using ASP.NET Core Blazor Pages templates.
19+
* **[run-angular-realworld](https://github.com/aspnetrun/run-angular-realworld)** - implemented run-angular repository and build **sample of eCommerce reference application** on Single Page Web Application(SPA) architecture using **ASP.NET Core + Angular**.
20+
21+
These repositories are **updated regularly**. We are following Microsoft Web Technologies very closely so we will update all these repositories accordingly with **Microsoft Web Application stacks**.
22+
123
# run-aspnetcore-basic
2-
One Solution - One Project for fastest idea generation with Asp.Net Core
24+
Here is CRUD operations of aspnetrun-core-basic template project;
25+
26+
![Recordit GIF](http://g.recordit.co/LJCyYfQEpX.gif)
27+
28+
**run-aspnetcore-basic** is a general purpose to implement the **Default Web Application template of .Net** with **one solution one project for fastest idea implementations** to building modern web applications with latest ASP.NET Core & Web API & EF Core technologies.
29+
30+
## Give a Star! :star:
31+
If you liked the project or if AspnetRun helped you, please **give a star**. And also please **fork** this repository and send us **pull-requests**. If you find any problem please open **issue**.
32+
33+
## Getting Started
34+
Use these instructions to get the project up and running.
35+
36+
### Prerequisites
37+
You will need the following tools:
38+
39+
* [Visual Studio 2019](https://visualstudio.microsoft.com/downloads/)
40+
* [.Net Core 2.2 or later](https://dotnet.microsoft.com/download/dotnet-core/2.2)
41+
* EF Core 2.2 or later
42+
43+
### Installing
44+
Follow these steps to get your development environment set up:
45+
1. Clone the repository
46+
2. At the root directory, restore required packages by running:
47+
```csharp
48+
dotnet restore
49+
```
50+
3. Next, build the solution by running:
51+
```csharp
52+
dotnet build
53+
```
54+
4. Next, within the AspnetRun.Web directory, launch the back end by running:
55+
```csharp
56+
dotnet run
57+
```
58+
5. Launch http://localhost:5400/ in your browser to view the Web UI.
59+
60+
If you have **Visual Studio** after cloning Open solution with your IDE, AspnetRun.Web should be the start-up project. Directly run this project on Visual Studio with **F5 or Ctrl+F5**. You will see index page of project, you can navigate product and category pages and you can perform crud operations on your browser.
61+
62+
### Usage
63+
After cloning or downloading the sample you should be able to run it using an In Memory database immediately. The default configuration of Entity Framework Database is **"InMemoryDatabase"**.
64+
If you wish to use the project with a persistent database, you will need to run its Entity Framework Core **migrations** before you will be able to run the app, and update the ConfigureDatabases method in **Startup.cs** (see below).
65+
66+
```csharp
67+
public void ConfigureDatabases(IServiceCollection services)
68+
{
69+
// use in-memory database
70+
services.AddDbContext<AspnetRunContext>(c =>
71+
c.UseInMemoryDatabase("AspnetRunConnection")
72+
.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking));
73+
74+
//// use real database
75+
//services.AddDbContext<AspnetRunContext>(c =>
76+
// c.UseSqlServer(Configuration.GetConnectionString("AspnetRunConnection"))
77+
// .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking));
78+
}
79+
```
80+
81+
1. Ensure your connection strings in ```appsettings.json``` point to a local SQL Server instance.
82+
83+
2. Open a command prompt in the Web folder and execute the following commands:
84+
85+
```csharp
86+
dotnet restore
87+
dotnet ef database update -c AspnetRunContext -p ../AspnetRun.Infrastructure/AspnetRun.Infrastructure.csproj -s AspnetRun.Web.csproj
88+
```
89+
Or you can direct call ef commands from Visual Studio **Package Manager Console**. Open Package Manager Console, set default project to AspnetRun.Infrastructure and run below command;
90+
```csharp
91+
update-database
92+
```
93+
These commands will create aspnetrun database which include Product and Category table. You can see from **AspnetRunContext.cs**.
94+
1. Run the application.
95+
The first time you run the application, it will seed aspnetrun sql server database with a few data such that you should see products and categories.
96+
97+
If you modify-change or add new some of entities to Core project, you should run ef migrate commands in order to update your database as the same way but below commands;
98+
```csharp
99+
add migration YourCustomEntityChanges
100+
update-database
101+
```
102+
103+
## Layered Architecture
104+
AspnetRun implements NLayer **Hexagonal architecture** (Core, Application, Infrastructure and Presentation Layers) and **Domain Driven Design** (Entities, Repositories, Domain/Application Services, DTO's...). Also implements and provides a good infrastructure to implement **best practices** such as Dependency Injection, logging, validation, exception handling, localization and so on.
105+
Aimed to be a **Clean Architecture** also called **Onion Architecture**, with applying **SOLID principles** in order to use for a project template. Also implements and provides a good infrastructure to implement **best practices** like **loosely-coupled, dependency-inverted** architecture
106+
The below image represents aspnetrun approach of development architecture of run repository series;
107+
108+
![DDD_png_pure](https://user-images.githubusercontent.com/1147445/54773098-e1efe700-4c19-11e9-9150-74f7e770de42.png)
109+
110+
### Structure of Project
111+
Repository include layers divided by **4 project**;
112+
* Core
113+
* Entities
114+
* Interfaces
115+
* Specifications
116+
* ValueObjects
117+
* Exceptions
118+
* Application
119+
* Interfaces
120+
* Services
121+
* Dtos
122+
* Mapper
123+
* Exceptions
124+
* Infrastructure
125+
* Data
126+
* Repository
127+
* Services
128+
* Migrations
129+
* Logging
130+
* Exceptions
131+
* Web
132+
* Interfaces
133+
* Services
134+
* Pages
135+
* ViewModels
136+
* Extensions
137+
* Mapper
138+
139+
### Core Layer
140+
Development of Domain Logic with abstraction. Interfaces drives business requirements with light implementation. The Core project is the **center of the Clean Architecture** design, and all other project dependencies should point toward it.
141+
142+
#### Entities
143+
Includes Entity Framework Core Entities which creates sql table with **Entity Framework Core Code First Aproach**. Some Aggregate folders holds entity and aggregates.
144+
You can see example of **code-first** Entity definition as below;
145+
146+
```csharp
147+
public class Product : BaseEntity
148+
{
149+
public string ProductName { get; set; }
150+
public string QuantityPerUnit { get; set; }
151+
public decimal? UnitPrice { get; set; }
152+
public short? UnitsInStock { get; set; }
153+
public short? UnitsOnOrder { get; set; }
154+
public short? ReorderLevel { get; set; }
155+
public bool Discontinued { get; set; }
156+
public int CategoryId { get; set; }
157+
public Category Category { get; set; }
158+
159+
public static Product Create(int productId, int categoryId, string name, decimal? unitPrice = null, short? unitsInStock = null, short? unitsOnOrder = null, short? reorderLevel = null, bool discontinued = false)
160+
{
161+
var product = new Product
162+
{
163+
Id = productId,
164+
CategoryId = categoryId,
165+
ProductName = name,
166+
UnitPrice = unitPrice,
167+
UnitsInStock = unitsInStock,
168+
UnitsOnOrder = unitsOnOrder,
169+
ReorderLevel = reorderLevel,
170+
Discontinued = discontinued
171+
};
172+
return product;
173+
}
174+
}
175+
```
176+
Applying domain driven approach, Product class responsible to create Product instance.
177+
178+
#### Interfaces
179+
Abstraction of Repository - Domain repositories (IAsyncRepository - IProductRepository) - Specifications etc.. This interfaces include database operations without any application and ui responsibilities.
180+
181+
#### Specifications
182+
This folder is implementation of **[specification pattern](https://en.wikipedia.org/wiki/Specification_pattern)**. Creates custom scripts with using **ISpecification** interface. Using BaseSpecification managing Criteria, Includes, OrderBy, Paging.
183+
This specs runs when EF commands working with passing spec. This specs implemented SpecificationEvaluator.cs and creates query to AspnetRunRepository.cs in ApplySpecification method.This helps create custom queries.
184+
185+
### Infrastructure Layer
186+
Implementation of Core interfaces in this project with **Entity Framework Core** and other dependencies.
187+
Most of your application's dependence on external resources should be implemented in classes defined in the Infrastructure project. These classes must implement the interfaces defined in Core. If you have a very large project with many dependencies, it may make sense to have more than one Infrastructure project (eg Infrastructure.Data), but in most projects one Infrastructure project that contains folders works well.
188+
This could be includes, for example, **e-mail providers, file access, web api clients**, etc. For now this repository only dependend sample data access and basic domain actions, by this way there will be no direct links to your Core or UI projects.
189+
190+
#### Data
191+
Includes **Entity Framework Core Context** and tables in this folder. When new entity created, it should add to context and configure in context.
192+
The Infrastructure project depends on Microsoft.**EntityFrameworkCore.SqlServer** and EF.Core related nuget packages, you can check nuget packages of Infrastructure layer. If you want to change your data access layer, it can easily be replaced with a lighter-weight ORM like Dapper.
193+
194+
#### Migrations
195+
EF add-migration classes.
196+
#### Repository
197+
EF Repository and Specification implementation. This class responsible to create queries, includes, where conditions etc..
198+
#### Services
199+
Custom services implementation, like email, cron jobs etc.
200+
201+
### Application Layer
202+
Development of **Domain Logic with implementation**. Interfaces drives business requirements and implementations in this layer.
203+
Application layer defines that user required actions in app services classes as below way;
204+
205+
```csharp
206+
public interface IProductAppService
207+
{
208+
Task<IEnumerable<ProductDto>> GetProductList();
209+
Task<ProductDto> GetProductById(int productId);
210+
Task<IEnumerable<ProductDto>> GetProductByName(string productName);
211+
Task<IEnumerable<ProductDto>> GetProductByCategory(int categoryId);
212+
Task<ProductDto> Create(ProductDto entityDto);
213+
Task Update(ProductDto entityDto);
214+
Task Delete(ProductDto entityDto);
215+
}
216+
```
217+
Also implementation located same places in order to choose different implementation at runtime when DI bootstrapped.
218+
```csharp
219+
public class ProductAppService : IProductAppService
220+
{
221+
private readonly IProductRepository _productRepository;
222+
private readonly IAppLogger<ProductAppService> _logger;
223+
224+
public ProductAppService(IProductRepository productRepository, IAppLogger<ProductAppService> logger)
225+
{
226+
_productRepository = productRepository ?? throw new ArgumentNullException(nameof(productRepository));
227+
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
228+
}
229+
230+
public async Task<IEnumerable<ProductDto>> GetProductList()
231+
{
232+
var productList = await _productRepository.GetProductListAsync();
233+
var mapped = ObjectMapper.Mapper.Map<IEnumerable<ProductDto>>(productList);
234+
return mapped;
235+
}
236+
}
237+
```
238+
In this layer we can add validation , authorization, logging, exception handling etc. -- cross cutting activities should be handled in here.
239+
240+
### Web Layer
241+
Development of UI Logic with implementation. Interfaces drives business requirements and implementations in this layer.
242+
The application's main **starting point** is the ASP.NET Core web project. This is a classical console application, with a public static void Main method in Program.cs. It currently uses the default **ASP.NET Core project template** which based on **Razor Pages** templates. This includes appsettings.json file plus environment variables in order to stored configuration parameters, and is configured in Startup.cs.
243+
244+
Web layer defines that user required actions in page services classes as below way;
245+
```csharp
246+
public interface IProductPageService
247+
{
248+
Task<IEnumerable<ProductViewModel>> GetProducts(string productName);
249+
Task<ProductViewModel> GetProductById(int productId);
250+
Task<IEnumerable<ProductViewModel>> GetProductByCategory(int categoryId);
251+
Task<IEnumerable<CategoryViewModel>> GetCategories();
252+
Task<ProductViewModel> CreateProduct(ProductViewModel productViewModel);
253+
Task UpdateProduct(ProductViewModel productViewModel);
254+
Task DeleteProduct(ProductViewModel productViewModel);
255+
}
256+
```
257+
Also implementation located same places in order to choose different implementation at runtime when DI bootstrapped.
258+
```csharp
259+
public class ProductPageService : IProductPageService
260+
{
261+
private readonly IProductAppService _productAppService;
262+
private readonly ICategoryAppService _categoryAppService;
263+
private readonly IMapper _mapper;
264+
private readonly ILogger<ProductPageService> _logger;
265+
266+
public ProductPageService(IProductAppService productAppService, ICategoryAppService categoryAppService, IMapper mapper, ILogger<ProductPageService> logger)
267+
{
268+
_productAppService = productAppService ?? throw new ArgumentNullException(nameof(productAppService));
269+
_categoryAppService = categoryAppService ?? throw new ArgumentNullException(nameof(categoryAppService));
270+
_mapper = mapper ?? throw new ArgumentNullException(nameof(mapper));
271+
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
272+
}
273+
274+
public async Task<IEnumerable<ProductViewModel>> GetProducts(string productName)
275+
{
276+
if (string.IsNullOrWhiteSpace(productName))
277+
{
278+
var list = await _productAppService.GetProductList();
279+
var mapped = _mapper.Map<IEnumerable<ProductViewModel>>(list);
280+
return mapped;
281+
}
282+
283+
var listByName = await _productAppService.GetProductByName(productName);
284+
var mappedByName = _mapper.Map<IEnumerable<ProductViewModel>>(listByName);
285+
return mappedByName;
286+
}
287+
}
288+
```
289+
### Test Layer
290+
For each layer, there is a test project which includes intended layer dependencies and mock classes. So that means Core-Application-Infrastructure and Web layer has their own test layer. By this way this test projects also divided by **unit, functional and integration tests** defined by in which layer it is implemented.
291+
Test projects using **xunit and Mock libraries**. xunit, because that's what ASP.NET Core uses internally to test the product. Moq, because perform to create fake objects clearly and its very modular.
292+
293+
294+
## Technologies
295+
* .NET Core 2.2
296+
* ASP.NET Core 2.2
297+
* Entity Framework Core 2.2
298+
* .NET Core Native DI
299+
* Razor Pages
300+
* AutoMapper
301+
302+
## Architecture
303+
* Clean Architecture
304+
* Full architecture with responsibility separation of concerns
305+
* SOLID and Clean Code
306+
* Domain Driven Design (Layers and Domain Model Pattern)
307+
* Unit of Work
308+
* Repository and Generic Repository
309+
* Multiple Page Web Application (MPA)
310+
* Monolitic Deployment Architecture
311+
* Specification Pattern
312+
313+
## Disclaimer
314+
315+
* This repository is not intended to be a definitive solution.
316+
* This repository not implemented a lot of 3rd party packages, we are try to avoid the over engineering when building on best practices.
317+
* Beware to use in production way.
318+
319+
## Contributing
320+
321+
Please read [Contributing.md](https://gist.github.com/PurpleBooth/b24679402957c63ec426) for details on our code of conduct, and the process for submitting pull requests to us.
322+
323+
## Versioning
324+
325+
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/aspnetrun/run-core/tags).
326+
327+
## Next Releases and RoapMap
328+
329+
For information on upcoming features and fixes, take a look at the [product roadmap](https://github.com/aspnetrun/run-core/projects).
330+
331+
## Deployment - AspnetRun Online
332+
333+
This project is deployed on Azure. See the project running on Azure in [here](aspnetrun.com).
334+
335+
## Pull-Request
336+
337+
Please fork this repository, and send me your findings with pull-requests. This is open-source repository so open to contributions.
338+
339+
## Authors
340+
341+
* **Mehmet Ozkaya** - *Initial work* - [mehmetozkaya](https://github.com/mehmetozkaya)
342+
343+
See also the list of [contributors](https://github.com/aspnetrun/run-core/contributors) who participated in this project.
3344

345+
## License
4346

5-
This repo has only 1 solution and one project for Razor Pages.
6-
But asp.net core will be also create spa so this repo also add a new 1 project for spa web application and these projects are indepent from each other, one would be for mpa and one for spa.
347+
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details

0 commit comments

Comments
 (0)