eShopOnContainers
Cross-platform .NET sample microservices and container based application that runs on Linux Windows and macOS. Powered by .NET 7, Docker Containers and Azure Kubernetes Services. Supports Visual Studio, VS for Mac and CLI based environments with Docker CLI, dotnet CLI, VS Code or any other code editor. Moved to https://github.com/dotnet/eShop.
Top Related Projects
ASP.NET Boilerplate - Web Application Framework
The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
Clean Architecture Solution Template for ASP.NET Core
Open-source web application framework for ASP.NET Core! Offers an opinionated architecture to build enterprise software solutions with best practices on top of the .NET. Provides the fundamental infrastructure, cross-cutting-concern implementations, startup templates, application modules, UI themes, tooling and documentation.
Quick Overview
eShopOnContainers is a comprehensive reference application for .NET microservices and container-based application architecture. It demonstrates best practices for building scalable, resilient, and maintainable distributed systems using modern technologies such as .NET, Docker, and Kubernetes.
Pros
- Provides a complete, production-ready microservices architecture example
- Implements various design patterns and best practices for distributed systems
- Offers detailed documentation and guidance for implementation
- Supports multiple deployment options, including local development, Azure, and on-premises
Cons
- Can be overwhelming for beginners due to its complexity
- Requires significant resources to run the entire system locally
- May not cover all specific use cases or industry-specific requirements
- Regular updates might be needed to keep up with rapidly evolving technologies
Code Examples
// Example of using MediatR for CQRS pattern
public class CreateOrderCommandHandler : IRequestHandler<CreateOrderCommand, bool>
{
private readonly IOrderRepository _orderRepository;
public CreateOrderCommandHandler(IOrderRepository orderRepository)
{
_orderRepository = orderRepository;
}
public async Task<bool> Handle(CreateOrderCommand request, CancellationToken cancellationToken)
{
var order = new Order(request.UserId, request.UserName, request.City, request.Street, request.State, request.Country, request.ZipCode);
return await _orderRepository.AddAsync(order);
}
}
// Example of using API Gateway pattern with Ocelot
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddOcelot(Configuration);
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseOcelot().Wait();
}
}
// Example of implementing resilience with Polly
public static class HttpClientExtensions
{
public static IHttpClientBuilder AddRetryPolicy(this IHttpClientBuilder builder)
{
return builder.AddPolicyHandler(GetRetryPolicy());
}
private static IAsyncPolicy<HttpResponseMessage> GetRetryPolicy()
{
return HttpPolicyExtensions
.HandleTransientHttpError()
.OrResult(msg => msg.StatusCode == System.Net.HttpStatusCode.NotFound)
.WaitAndRetryAsync(6, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)));
}
}
Getting Started
-
Clone the repository:
git clone https://github.com/dotnet-architecture/eShopOnContainers.git
-
Install Docker Desktop and enable Kubernetes
-
Navigate to the
src
folder and run:docker-compose build docker-compose up
-
Access the application at
http://localhost:5100
for the Web MVC app orhttp://localhost:5104
for the Web SPA
Note: For detailed setup instructions and deployment options, refer to the project's documentation.
Competitor Comparisons
ASP.NET Boilerplate - Web Application Framework
Pros of aspnetboilerplate
- Comprehensive framework with built-in modules for common application features
- Supports multiple database providers and ORMs out of the box
- Extensive documentation and community support
Cons of aspnetboilerplate
- Steeper learning curve due to its extensive feature set
- Less focus on microservices architecture
- May be overkill for smaller projects or simple applications
Code Comparison
aspnetboilerplate:
public class PersonAppService : AsyncCrudAppService<Person, PersonDto, int, PagedPersonResultRequestDto, CreatePersonDto, UpdatePersonDto>, IPersonAppService
{
public PersonAppService(IRepository<Person, int> repository) : base(repository)
{
}
}
eShopOnContainers:
public class CatalogController : ControllerBase
{
private readonly CatalogContext _catalogContext;
private readonly IOptionsSnapshot<CatalogSettings> _settings;
public CatalogController(CatalogContext context, IOptionsSnapshot<CatalogSettings> settings)
{
_catalogContext = context;
_settings = settings;
}
}
The aspnetboilerplate example showcases its CRUD application service pattern, while eShopOnContainers demonstrates a more traditional controller setup. aspnetboilerplate provides more built-in functionality, but eShopOnContainers offers greater flexibility in implementation.
The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
Pros of NSwag
- Focused tool for API documentation and client code generation
- Lightweight and easy to integrate into existing projects
- Supports multiple languages and frameworks for client generation
Cons of NSwag
- Limited scope compared to eShopOnContainers' full e-commerce solution
- Lacks comprehensive architectural patterns and best practices
- Not designed as a reference application for microservices
Code Comparison
NSwag (OpenAPI/Swagger generation):
services.AddSwaggerDocument(config =>
{
config.PostProcess = document =>
{
document.Info.Version = "v1";
document.Info.Title = "My API";
};
});
eShopOnContainers (API configuration):
services.AddCustomMvc(Configuration)
.AddCustomDbContext(Configuration)
.AddCustomSwagger(Configuration)
.AddCustomIntegrations(Configuration)
.AddCustomConfiguration(Configuration)
.AddEventBus(Configuration);
NSwag focuses on API documentation and client generation, while eShopOnContainers provides a comprehensive microservices architecture for e-commerce applications. NSwag is more suitable for projects requiring API documentation and client generation, whereas eShopOnContainers serves as a reference implementation for complex, distributed systems.
Clean Architecture Solution Template for ASP.NET Core
Pros of CleanArchitecture
- Simpler and more lightweight, making it easier to understand and implement
- Focuses on clean architecture principles, promoting better separation of concerns
- Includes a comprehensive test suite, demonstrating best practices in unit and integration testing
Cons of CleanArchitecture
- Less comprehensive in terms of microservices and distributed systems patterns
- Lacks advanced features like API gateways, message brokers, and container orchestration
- May not be as suitable for large-scale, enterprise-level applications
Code Comparison
CleanArchitecture:
public class CreateTodoItemCommand : IRequest<int>
{
public int ListId { get; set; }
public string Title { get; set; }
}
eShopOnContainers:
public class CreateOrderCommand : IRequest<bool>
{
public string BuyerId { get; set; }
public IEnumerable<OrderItemDTO> OrderItems { get; set; }
}
Both examples demonstrate the use of CQRS pattern with MediatR, but eShopOnContainers tends to have more complex command structures due to its larger scope and microservices architecture.
Open-source web application framework for ASP.NET Core! Offers an opinionated architecture to build enterprise software solutions with best practices on top of the .NET. Provides the fundamental infrastructure, cross-cutting-concern implementations, startup templates, application modules, UI themes, tooling and documentation.
Pros of abp
- Comprehensive modular architecture with pre-built application modules
- Extensive documentation and community support
- Built-in multi-tenancy support
Cons of abp
- Steeper learning curve due to its extensive framework
- Less focus on microservices architecture compared to eShopOnContainers
- May be overkill for smaller projects
Code Comparison
abp:
public class BookAppService : ApplicationService, IBookAppService
{
private readonly IRepository<Book, Guid> _bookRepository;
public BookAppService(IRepository<Book, Guid> bookRepository)
{
_bookRepository = bookRepository;
}
}
eShopOnContainers:
public class CatalogController : ControllerBase
{
private readonly CatalogContext _catalogContext;
private readonly IOptionsSnapshot<CatalogSettings> _settings;
public CatalogController(CatalogContext context, IOptionsSnapshot<CatalogSettings> settings)
{
_catalogContext = context;
_settings = settings;
}
}
The abp framework uses a more abstracted approach with application services and repositories, while eShopOnContainers follows a more traditional controller-based structure. abp's code demonstrates its focus on modularity and domain-driven design, whereas eShopOnContainers emphasizes microservices and containerization.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
eShop has moved!
As of November 2023, the eShop sample application has been updated and moved to https://github.com/dotnet/eShop. Active development will continue there.
This repo is now a read-only archive. If you'd like to refer to the old code that was in here, you can find it in the "dev" branch.
Top Related Projects
ASP.NET Boilerplate - Web Application Framework
The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
Clean Architecture Solution Template for ASP.NET Core
Open-source web application framework for ASP.NET Core! Offers an opinionated architecture to build enterprise software solutions with best practices on top of the .NET. Provides the fundamental infrastructure, cross-cutting-concern implementations, startup templates, application modules, UI themes, tooling and documentation.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot