Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork210
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 ->
License
aspnetrun/run-aspnetcore-realworld
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Here isimplementation of aspnetrun-core base on real-worlde-commerce web application project;
AspnetRunCoreRealWorld is an implementation of base aspnetrun project which written withclean architecture and best practices. The idea is thathow to implement real life projects over the base repository i.e.e-commerce domain implemented with fullE&E e-commerce web template. AspnetRunRealWorld is an implementation ofe-commerce domain withNorthwind database.This managed withlayered architecture for building modern web applications with latest ASP.NET Core & Web API & EF Core technologies.
We have implemented belowfeatures over the run-aspnetcore boilerplate template. You can changereal-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 ofmissing features you can checkhere from our project page and you can develop them. We are waiting for your pull requests.
If you liked the project or if AspnetRun helped you, pleasegive a star. And also pleasefork this repository and send uspull-requests. If you find any problem please openissue.
Use these instructions to get the project up and running.
You will need the following tools:
- Visual Studio 2019
- .Net Core 3.x or later
- EF Core 3.x or later
Follow these steps to get your development environment set up:
- Clone the repository
- At the root directory, restore required packages by running:
dotnetrestore
- Next, build the solution by running:
dotnetbuild
- Next, within the AspnetRun.Web directory, launch the back end by running:
dotnetrun
- Launchhttp://localhost:5400/ in your browser to view the Web UI.
If you haveVisual Studio after cloning Open solution with your IDE, AspnetRun.Web should be the start-up project. Directly run this project on Visual Studio withF5 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.
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 Coremigrations before you will be able to run the app, and update the ConfigureDatabases method inStartup.cs (see below).
publicvoidConfigureDatabases(IServiceCollectionservices){// use in-memory databaseservices.AddDbContext<AspnetRunContext>(c=>c.UseInMemoryDatabase("AspnetRunConnection").UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking));//// use real database//services.AddDbContext<AspnetRunContext>(c =>// c.UseSqlServer(Configuration.GetConnectionString("AspnetRunConnection"))// .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking));}
Ensure your connection strings in
appsettings.json
point to a local SQL Server instance.Open a command prompt in the Web folder and execute the following commands:
dotnetrestoredotnet ef database update-c AspnetRunContext-p ../AspnetRun.Infrastructure/AspnetRun.Infrastructure.csproj-s AspnetRun.Web.csproj
Or you can direct call ef commands from Visual StudioPackage 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 fromAspnetRunContext.cs.
- 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;
addmigration YourCustomEntityChangesupdate-database
AspnetRun implements NLayerHexagonal architecture (Core, Application, Infrastructure and Presentation Layers) andDomain Driven Design (Entities, Repositories, Domain/Application Services, DTO's...). Also implements and provides a good infrastructure to implementbest practices such as Dependency Injection, logging, validation, exception handling, localization and so on.Aimed to be aClean Architecture also calledOnion Architecture, with applyingSOLID principles in order to use for a project template. Also implements and provides a good infrastructure to implementbest practices likeloosely-coupled, dependency-inverted architectureThe below image represents aspnetrun approach of development architecture of run repository series;
Repository include layers divided by4 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
Development of Domain Logic with abstraction. Interfaces drives business requirements with light implementation. The Core project is thecenter of the Clean Architecture design, and all other project dependencies should point toward it.
Includes Entity Framework Core Entities which creates sql table withEntity Framework Core Code First Aproach. Some Aggregate folders holds entity and aggregates.You can see example ofcode-first Entity definition as below;
publicclassProduct:BaseEntity{publicstringProductName{get;set;}publicstringQuantityPerUnit{get;set;}publicdecimal?UnitPrice{get;set;}publicshort?UnitsInStock{get;set;}publicshort?UnitsOnOrder{get;set;}publicshort?ReorderLevel{get;set;}publicboolDiscontinued{get;set;}publicintCategoryId{get;set;}publicCategoryCategory{get;set;}publicstaticProductCreate(intproductId,intcategoryId,stringname,decimal?unitPrice=null,short?unitsInStock=null,short?unitsOnOrder=null,short?reorderLevel=null,booldiscontinued=false){varproduct=newProduct{Id=productId,CategoryId=categoryId,ProductName=name,UnitPrice=unitPrice,UnitsInStock=unitsInStock,UnitsOnOrder=unitsOnOrder,ReorderLevel=reorderLevel,Discontinued=discontinued};returnproduct;}}
Applying domain driven approach, Product class responsible to create Product instance.
Abstraction of Repository - Domain repositories (IAsyncRepository - IProductRepository) - Specifications etc.. This interfaces include database operations without any application and ui responsibilities.
This folder is implementation ofspecification pattern. Creates custom scripts with usingISpecification 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.
Implementation of Core interfaces in this project withEntity 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.
IncludesEntity 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.
EF add-migration classes.
EF Repository and Specification implementation. This class responsible to create queries, includes, where conditions etc..
Custom services implementation, like email, cron jobs etc.
Development ofDomain 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;
publicinterfaceIProductAppService{Task<IEnumerable<ProductDto>>GetProductList();Task<ProductDto>GetProductById(intproductId);Task<IEnumerable<ProductDto>>GetProductByName(stringproductName);Task<IEnumerable<ProductDto>>GetProductByCategory(intcategoryId);Task<ProductDto>Create(ProductDtoentityDto);TaskUpdate(ProductDtoentityDto);TaskDelete(ProductDtoentityDto);}
Also implementation located same places in order to choose different implementation at runtime when DI bootstrapped.
publicclassProductAppService:IProductAppService{privatereadonlyIProductRepository_productRepository;privatereadonlyIAppLogger<ProductAppService>_logger;publicProductAppService(IProductRepositoryproductRepository,IAppLogger<ProductAppService>logger){_productRepository=productRepository??thrownewArgumentNullException(nameof(productRepository));_logger=logger??thrownewArgumentNullException(nameof(logger));}publicasyncTask<IEnumerable<ProductDto>>GetProductList(){varproductList=await_productRepository.GetProductListAsync();varmapped=ObjectMapper.Mapper.Map<IEnumerable<ProductDto>>(productList);returnmapped;}}
In this layer we can add validation , authorization, logging, exception handling etc. -- cross cutting activities should be handled in here.
Development of UI Logic with implementation. Interfaces drives business requirements and implementations in this layer.The application's mainstarting 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 defaultASP.NET Core project template which based onRazor 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;
publicinterfaceIProductPageService{Task<IEnumerable<ProductViewModel>>GetProducts(stringproductName);Task<ProductViewModel>GetProductById(intproductId);Task<IEnumerable<ProductViewModel>>GetProductByCategory(intcategoryId);Task<IEnumerable<CategoryViewModel>>GetCategories();Task<ProductViewModel>CreateProduct(ProductViewModelproductViewModel);TaskUpdateProduct(ProductViewModelproductViewModel);TaskDeleteProduct(ProductViewModelproductViewModel);}
Also implementation located same places in order to choose different implementation at runtime when DI bootstrapped.
publicclassProductPageService:IProductPageService{privatereadonlyIProductAppService_productAppService;privatereadonlyICategoryAppService_categoryAppService;privatereadonlyIMapper_mapper;privatereadonlyILogger<ProductPageService>_logger;publicProductPageService(IProductAppServiceproductAppService,ICategoryAppServicecategoryAppService,IMappermapper,ILogger<ProductPageService>logger){_productAppService=productAppService??thrownewArgumentNullException(nameof(productAppService));_categoryAppService=categoryAppService??thrownewArgumentNullException(nameof(categoryAppService));_mapper=mapper??thrownewArgumentNullException(nameof(mapper));_logger=logger??thrownewArgumentNullException(nameof(logger));}publicasyncTask<IEnumerable<ProductViewModel>>GetProducts(stringproductName){if(string.IsNullOrWhiteSpace(productName)){varlist=await_productAppService.GetProductList();varmapped=_mapper.Map<IEnumerable<ProductViewModel>>(list);returnmapped;}varlistByName=await_productAppService.GetProductByName(productName);varmappedByName=_mapper.Map<IEnumerable<ProductViewModel>>(listByName);returnmappedByName;}}
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 byunit, functional and integration tests defined by in which layer it is implemented.Test projects usingxunit 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.
- .NET Core 3.x
- ASP.NET Core 3.x
- Entity Framework Core 3.x
- .NET Core Native DI
- Razor Pages
- AutoMapper
- 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
- 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.
Please readContributing.md for details on our code of conduct, and the process for submitting pull requests to us.We have a lot ofmissing features you can checkhere from our project page and you can develop them. We are waiting for your pull requests.
We useSemVer for versioning. For the versions available, see thetags on this repository.
For information on upcoming features and fixes, take a look at theproduct roadmap.
This project is deployed on Azure. See the project running on Azure inhere.
Please fork this repository, and send me your findings with pull-requests. This is open-source repository so open to contributions.Get your item frommissing featureshere from our project page and send us your pull requests.
- Mehmet Ozkaya -Initial work -mehmetozkaya
See also the list ofcontributors who participated in this project.
This project is licensed under the MIT License - see theLICENSE.md file for details
About
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 ->
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Uh oh!
There was an error while loading.Please reload this page.