• Stars
    star
    479
  • Rank 91,752 (Top 2 %)
  • Language SCSS
  • License
    MIT License
  • Created almost 6 years ago
  • Updated almost 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

E-Commerce real world example of run-aspnetcore ASP.NET Core web application. Implemented e-commerce domain with clean architecture for ASP.NET Core reference application, demonstrating a layered application architecture with DDD best practices. Download 100+ page eBook PDF from here ->

Here is implementation of aspnetrun-core base on real-world e-commerce web application project;

Recordit GIF

AspnetRunCoreRealWorld is an implementation of base aspnetrun project which written with clean architecture and best practices. The idea is that how to implement real life projects over the base repository i.e. e-commerce domain implemented with full E&E e-commerce web template. AspnetRunRealWorld is an implementation of e-commerce domain with Northwind database.This managed with layered architecture for building modern web applications with latest ASP.NET Core & Web API & EF Core technologies.

Whats Including In This Repository

We have implemented below features over the run-aspnetcore boilerplate template. You can change real-world features as your business requirements;

  • E&E e-commerce theme implementation
  • Full development of e-commerce use cases of northwind database
  • Business rule check, domain policy apply and validations
  • Authentication, identity module and identity configuration
  • Authorization for Products Page
  • Asp.net core built-in dependency injection
  • Aspnet core razor tools - View Components, partial Views, Tag Helpers, Model Bindings and Validations, Razor Sections etc..
  • Configuration management
  • Custom paging implementation

Also we have a lot of missing features you can check here from our project page and you can develop them. We are waiting for your pull requests.

Give a Star! ⭐

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.

Getting Started

Use these instructions to get the project up and running.

Prerequisites

You will need the following tools:

Installing

Follow these steps to get your development environment set up:

  1. Clone the repository
  2. At the root directory, restore required packages by running:
dotnet restore
  1. Next, build the solution by running:
dotnet build
  1. Next, within the AspnetRun.Web directory, launch the back end by running:
dotnet run
  1. Launch http://localhost:5400/ in your browser to view the Web UI.

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.

Usage

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". 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).

public void ConfigureDatabases(IServiceCollection services)
{
    // use in-memory database
    services.AddDbContext<AspnetRunContext>(c =>
        c.UseInMemoryDatabase("AspnetRunConnection")
        .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking));

    //// use real database
    //services.AddDbContext<AspnetRunContext>(c =>
    //    c.UseSqlServer(Configuration.GetConnectionString("AspnetRunConnection"))
    //    .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking));
}
  1. Ensure your connection strings in appsettings.json point to a local SQL Server instance.

  2. Open a command prompt in the Web folder and execute the following commands:

dotnet restore
dotnet ef database update -c AspnetRunContext -p ../AspnetRun.Infrastructure/AspnetRun.Infrastructure.csproj -s AspnetRun.Web.csproj

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;

update-database

These commands will create aspnetrun database which include Product and Category table. You can see from AspnetRunContext.cs.

  1. Run the application. 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.

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;

add migration YourCustomEntityChanges
update-database

Layered Architecture

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. 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 The below image represents aspnetrun approach of development architecture of run repository series;

DDD_png_pure

Structure of Project

Repository include layers divided by 4 project;

  • Core
    • Entities
    • Interfaces
    • Specifications
    • ValueObjects
    • Exceptions
  • Application
    • Interfaces
    • Services
    • Dtos
    • Mapper
    • Exceptions
  • Infrastructure
    • Data
    • Repository
    • Services
    • Migrations
    • Logging
    • Exceptions
  • Web
    • Interfaces
    • Services
    • Pages
    • ViewModels
    • Extensions
    • Mapper

Core Layer

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.

Entities

Includes Entity Framework Core Entities which creates sql table with Entity Framework Core Code First Aproach. Some Aggregate folders holds entity and aggregates. You can see example of code-first Entity definition as below;

public class Product : BaseEntity
{        
    public string ProductName { get; set; }
    public string QuantityPerUnit { get; set; }
    public decimal? UnitPrice { get; set; }
    public short? UnitsInStock { get; set; }
    public short? UnitsOnOrder { get; set; }
    public short? ReorderLevel { get; set; }
    public bool Discontinued { get; set; }
    public int CategoryId { get; set; }
    public Category Category { get; set; }

    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)
    {
        var product = new Product
        {
            Id = productId,
            CategoryId = categoryId,
            ProductName = name,
            UnitPrice = unitPrice,
            UnitsInStock = unitsInStock,
            UnitsOnOrder = unitsOnOrder,
            ReorderLevel = reorderLevel,
            Discontinued = discontinued
        };
        return product;
    }
}

Applying domain driven approach, Product class responsible to create Product instance.

Interfaces

Abstraction of Repository - Domain repositories (IAsyncRepository - IProductRepository) - Specifications etc.. This interfaces include database operations without any application and ui responsibilities.

Specifications

This folder is implementation of specification pattern. Creates custom scripts with using ISpecification interface. Using BaseSpecification managing Criteria, Includes, OrderBy, Paging. 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.

Infrastructure Layer

Implementation of Core interfaces in this project with Entity Framework Core and other dependencies. 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. 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.

Data

Includes Entity Framework Core Context and tables in this folder. When new entity created, it should add to context and configure in context. 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.

Migrations

EF add-migration classes.

Repository

EF Repository and Specification implementation. This class responsible to create queries, includes, where conditions etc..

Services

Custom services implementation, like email, cron jobs etc.

Application Layer

Development of Domain Logic with implementation. Interfaces drives business requirements and implementations in this layer. Application layer defines that user required actions in app services classes as below way;

public interface IProductAppService
{
    Task<IEnumerable<ProductDto>> GetProductList();
    Task<ProductDto> GetProductById(int productId);
    Task<IEnumerable<ProductDto>> GetProductByName(string productName);
    Task<IEnumerable<ProductDto>> GetProductByCategory(int categoryId);
    Task<ProductDto> Create(ProductDto entityDto);
    Task Update(ProductDto entityDto);
    Task Delete(ProductDto entityDto);
}

Also implementation located same places in order to choose different implementation at runtime when DI bootstrapped.

public class ProductAppService : IProductAppService
{
    private readonly IProductRepository _productRepository;
    private readonly IAppLogger<ProductAppService> _logger;

    public ProductAppService(IProductRepository productRepository, IAppLogger<ProductAppService> logger)
    {
        _productRepository = productRepository ?? throw new ArgumentNullException(nameof(productRepository));
        _logger = logger ?? throw new ArgumentNullException(nameof(logger));
    }

    public async Task<IEnumerable<ProductDto>> GetProductList()
    {
        var productList = await _productRepository.GetProductListAsync();
        var mapped = ObjectMapper.Mapper.Map<IEnumerable<ProductDto>>(productList);
        return mapped;
    }
}

In this layer we can add validation , authorization, logging, exception handling etc. -- cross cutting activities should be handled in here.

Web Layer

Development of UI Logic with implementation. Interfaces drives business requirements and implementations in this layer. 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.

Web layer defines that user required actions in page services classes as below way;

public interface IProductPageService
{
    Task<IEnumerable<ProductViewModel>> GetProducts(string productName);
    Task<ProductViewModel> GetProductById(int productId);
    Task<IEnumerable<ProductViewModel>> GetProductByCategory(int categoryId);
    Task<IEnumerable<CategoryViewModel>> GetCategories();
    Task<ProductViewModel> CreateProduct(ProductViewModel productViewModel);
    Task UpdateProduct(ProductViewModel productViewModel);
    Task DeleteProduct(ProductViewModel productViewModel);
}

Also implementation located same places in order to choose different implementation at runtime when DI bootstrapped.

public class ProductPageService : IProductPageService
{
    private readonly IProductAppService _productAppService;
    private readonly ICategoryAppService _categoryAppService;
    private readonly IMapper _mapper;
    private readonly ILogger<ProductPageService> _logger;

    public ProductPageService(IProductAppService productAppService, ICategoryAppService categoryAppService, IMapper mapper, ILogger<ProductPageService> logger)
    {
        _productAppService = productAppService ?? throw new ArgumentNullException(nameof(productAppService));
        _categoryAppService = categoryAppService ?? throw new ArgumentNullException(nameof(categoryAppService));
        _mapper = mapper ?? throw new ArgumentNullException(nameof(mapper));
        _logger = logger ?? throw new ArgumentNullException(nameof(logger));
    }

    public async Task<IEnumerable<ProductViewModel>> GetProducts(string productName)
    {
        if (string.IsNullOrWhiteSpace(productName))
        {
            var list = await _productAppService.GetProductList();
            var mapped = _mapper.Map<IEnumerable<ProductViewModel>>(list);
            return mapped;
        }

        var listByName = await _productAppService.GetProductByName(productName);
        var mappedByName = _mapper.Map<IEnumerable<ProductViewModel>>(listByName);
        return mappedByName;
    }
}

Test Layer

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. 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.

Technologies

  • .NET Core 3.x
  • ASP.NET Core 3.x
  • Entity Framework Core 3.x
  • .NET Core Native DI
  • Razor Pages
  • AutoMapper

Architecture

  • Clean Architecture
  • Full architecture with responsibility separation of concerns
  • SOLID and Clean Code
  • Domain Driven Design (Layers and Domain Model Pattern)
  • Unit of Work
  • Repository and Generic Repository
  • Multiple Page Web Application (MPA)
  • Monolitic Deployment Architecture
  • Specification Pattern

Disclaimer

  • This repository is not intended to be a definitive solution.
  • This repository not implemented a lot of 3rd party packages, we are try to avoid the over engineering when building on best practices.
  • Beware to use in production way.

Contributing

Please read Contributing.md for details on our code of conduct, and the process for submitting pull requests to us. We have a lot of missing features you can check here from our project page and you can develop them. We are waiting for your pull requests.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Next Releases and RoapMap

For information on upcoming features and fixes, take a look at the product roadmap.

Deployment - AspnetRun Online

This project is deployed on Azure. See the project running on Azure in here.

Pull-Request

Please fork this repository, and send me your findings with pull-requests. This is open-source repository so open to contributions. Get your item from missing features here from our project page and send us your pull requests.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

More Repositories

1

run-aspnetcore-microservices

Microservices on .NET platforms used ASP.NET Web API, Docker, RabbitMQ, MassTransit, Grpc, Yarp API Gateway, PostgreSQL, Redis, SQLite, SqlServer, Marten, Entity Framework Core, CQRS, MediatR, DDD, Vertical and Clean Architecture implementation with using latest features of .NET 8 and C# 12
C#
2,691
star
2

run-aspnetcore

A starter kit for your next ASP.NET Core web application. Boilerplate for ASP.NET Core reference application, demonstrating a layered application architecture with applying Clean Architecture and DDD best practices. Download 100+ page eBook PDF from here ->
C#
570
star
3

run-aspnetcore-cqrs

Real world Enterprise CRM application example of ASP.NET Core + Angular web application. Implemented CQRS Design Pattern for ASP.NET Core + Angular reference application, demonstrating a layered application architecture with DDD best practices. Download 100+ page eBook PDF from here ->
C#
519
star
4

run-aspnet-identityserver4

Secure microservices with using standalone Identity Server 4 and backing with Ocelot API Gateway. Protect our ASP.NET Web MVC and API applications with using OAuth 2 and OpenID Connect in IdentityServer4. Securing your web application and API with tokens, working with claims, authentication and authorization middlewares and applying policies.
SCSS
234
star
5

run-aspnetcore-basics

Implementation of Real-World example in One Solution - One Project for web application development with Asp.Net Core & EF.Core. Only one web application project which used aspnetcore components; razor pages, middlewares, dependency injection, configuration, logging. To create websites with minimum implementation of asp.net core based on HTML5, CSS, and JavaScript. You can use this boilerplate for fast implementation, minimum development, bootstrap your idea, create Minimum Viable Product (MVP), idea validation, startup development implementation for a limited time and limited resources with using latest asp.net core and entity framework core.
C#
190
star
6

run-aspnet-grpc

Using gRPC in Microservices for Building a high-performance Interservice Communication with .Net 5. See gRPC Microservices and Step by Step Implementation on .NET Course w/ discount->
C#
115
star
7

run-devops

Deploying .Net Microservices into Kubernetes, and moving deployments to the cloud Azure Kubernetes Services (AKS) with using Azure Container Registry (ACR) and how to Automating Deployments with Azure DevOps and GitHub.
C#
83
star
8

learn

The best path to .Net Microservices Udemy Learning Path. .Net world evolving to the microservices and Cloud-native systems to provide rapid change, large scale, and resilience cutting-edge systems. Cloud-native microservices empower organizations to build and run scalable applications in modern, dynamic environments such as public, private, and hybrid clouds.
47
star
9

run-aspnetcore-angular_retired

Enterprise Web Application infrastructure for ASP.NET Core and Angular. Boilerplate for ASP.NET Core + Angular reference application, demonstrating a layered application architecture with DDD best practices. Download 100+ page eBook PDF from here ->
C#
41
star
10

run-aspnetcore-blazor

New .Net Core 3.0 Asp.Net Blazor Components SPA Web Application
C#
23
star
11

run-aspnetcore-basics_retired

One Solution - One Project for web application development with Asp.Net Core & EF.Core. Only one web application project which used aspnetcore components; razor pages, middlewares, dependency injection, configuration, logging. To create websites with minimum implementation of asp.net core based on HTML5, CSS, and JavaScript. You can use this boilerplate for fast implementation, minimum development, bootstrap your idea, create Minimum Viable Product (MVP), idea validation, startup development implementation for a limited time and limited resources with using latest asp.net core and entity framework core.
C#
17
star
12

run-aspnetcore-blazor-realworld

Implementation of run-aspnetcore-spa repository
13
star