Giter VIP home page Giter VIP logo

aspnetcore-ddd's Introduction

Diagram

Overview

Architecture

Dependencies

Project dependencies

Code flow

Repository & Unit Of Work

Techical Stack

  • ASP.NET Core 8.0 (with .NET 8.0)
  • ASP.NET WebApi Core
  • ASP.NET Identity Core
  • Entity Framework Core
  • .NET Core Native DI
  • AutoMapper
  • FluentValidation
  • MediatR
  • Swagger UI
  • MSSQL
  • xUnit
  • Moq
  • FluentAssertions
  • Polly
  • Refit
  • DbUp
  • NPOI
  • Quartz
  • StyleCop

Design Patterns

  • Domain Driven Design
  • Domain Events
  • Domain Notification
  • CQRS
  • Event Sourcing
  • Unit Of Work
  • Repository & Generic Repository
  • Inversion of Control / Dependency injection
  • ORM
  • Mediator
  • Specification Pattern
  • Options Pattern

Pre-Configuration

  • Config User Secret:

    • Find <user_secrets_id> at DDD.Services.Api.csproj > UserSecretsId (Free to change to any GUID/UUID)
    • Windows: C:\Users\[UserName]\AppData\Roaming\Microsoft\UserSecrets\<user_secrets_id>\secrets.json
    • Linux / macOS: ~/.microsoft/usersecrets/<user_secrets_id>/secrets.json
  • secrets.json for Windows:

{
  "ConnectionStrings": {
    "DefaultConnection": "Server=(localdb)\\MSSQLLocalDB;Database=DDD;Trusted_Connection=True;MultipleActiveResultSets=true"
  }
}
  • LocalDB is a packaging mechanism for SQL Server Express Edition, and is only available for Windows, use Microsoft SQL Server or Azure SQL Edge for Linux / macOS

  • secrets.json for Linux / macOS:

{
  "ConnectionStrings": {
    "DefaultConnection": "Data Source=<ip_address>,1433;Initial Catalog=aspnetcore-ddd;User ID=SA;pwd=<YourNewStrong@Passw0rd>;Integrated Security=False;ConnectRetryCount=0;MultipleActiveResultSets=True"
  }
}

How to run

  • For Visual Studio: Select profile > Run (F5)
  • For VSCode: Select configuration > Run (F5)
  • For Terminal:
dotnet build Src/DDD.Services.Api/DDD.Services.Api.csproj
dotnet run --project Src/DDD.Services.Api/DDD.Services.Api.csproj --launch-profile Dev
dotnet watch --project Src/DDD.Services.Api/DDD.Services.Api.csproj run

Testing

  • Terminal: dotnet test

Docker

docker build -t aspnetcore-docker-image .
docker run -it --rm -p 3000:80 --name aspnetcore-docker-container aspnetcore-docker-image
docker run -d -p 3000:80 --name aspnetcore-docker-container aspnetcore-docker-image
docker compose up -d
docker compose ps
docker compose stop

Podman

podman build -t aspnetcore-docker-image .
podman run -it --rm -p 3000:80 --name aspnetcore-docker-container aspnetcore-docker-image
podman run -d -p 3000:80 --name aspnetcore-docker-container aspnetcore-docker-image
podman-compose up -d
podman-compose ps
podman-compose stop

Swagger (Dev env only)

Health check (Staging & Prod env only)

TODO

  • Use multiple environments
  • Transaction (Unit of Work)
  • Validation (FluentValidation)
  • Response wrapper
  • Async/Await
  • REST
  • JWT
  • Mapping (AutoMapper)
  • API Specification, API Definition (Swagger)
  • ORM {Entity Framework Core}
  • Middleware
  • CORS
  • Pagination
  • Sorting
  • Error Handling, Global Exception
  • HealthCheck
  • Mail
  • Http
  • Database Auditing: CreatedAt/UpdatedAt CreatedBy/UpdatedBy
  • Soft Delete
  • Common: Constants, Helpers
  • Docker, Docker Compose, Github Container Registry
  • EF: Shadow Properties
  • Events
  • Unit Testing
  • Integration Testing
  • Scoped over Transient
  • Use abstract keyword to appropriate class
  • Use IQueryable, IEnumerable, IList interfaces
  • Use NetStandard 2.1 for Class Library
  • Hashing
  • AnalysisLevel: Automatically find latent bugs (It was enabled by default for .NET 5 or above)
  • Migration (DbUp)
  • User Secrets
  • API Versioning
  • API Versioning with Swagger
  • Kubernetes
  • AKS
  • Hot reload
  • SignalR
  • Notifications
  • Webhook
  • Task scheduling & Queues: Quartz
  • Quartz: Fire-and-forget
  • NPOI
  • REST Client
  • StyleCopAnalyzers (Use default rules set and disable 9 rules: SA0001, SA1200, SA1201, SA1309, SA1400, SA1512, SA1600, SA1601, SA1633)
  • RoslynAnalyzers (It was enabled by default for .NET 5 or above)
  • Secret Manager
  • OmniSharp Roslyn
  • sonar-dotnet
  • docfx
  • Autofac
  • Bogus
  • Scaffold
  • Data Seeding
  • Logging
  • OAuth2, OIDC (OpenId Connect)
  • Search
  • Kafka, RabbitMQ
  • Microservices, API Gateway (Ocelot, yarp)
  • Multi-tenancy
  • Primary Key to Integer
  • File storage: Upload/Download
  • Globalization & Localization
  • Caching
  • Kestrel
  • Session & Cookie
  • Encryption
  • EF: No-tracking queries
  • Dapper, Dapper Contrib (Optional)
  • RepoDB
  • BulkInsert, BulkUpdate, Async method for IRepository

References

aspnetcore-ddd's People

Contributors

ntxinh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aspnetcore-ddd's Issues

very nice but is not working

Using Visual Studio 2019 starts but only work Swagger. I get:

Microsoft.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

When trying any api url.

I tried adding to appsetings.json

"ConnectionStrings": {
"DefaultConnection": "Data Source=.;Initial Catalog=ddd1;Integrated Security=True"
}

with a new empty database, but I'm getting the same error

Running with docker doesn't work

> docker build -t aspnetcore-docker-image .
Sending build context to Docker daemon  1.248MB
Step 1/17 : FROM mcr.microsoft.com/dotnet/core/sdk:6.0-alpine AS build
manifest for mcr.microsoft.com/dotnet/core/sdk:6.0-alpine not found: manifest unknown: manifest tagged by "6.0-alpine" is not found

That I solved by changing images to mcr.microsoft.com/dotnet/sdk:6.0 and mcr.microsoft.com/dotnet/aspnet:6.0 respecitvely.

Then...

> docker run -it --rm -p 3000:80 --name aspnetcore-docker-container aspnetcore-docker-image
Unhandled exception. System.ArgumentNullException: String reference not set to an instance of a String. (Parameter 's')
   at System.Text.Encoding.GetBytes(String s)
   at DDD.Services.Api.StartupExtensions.AuthExtension.AddCustomizedAuth(IServiceCollection services, IConfiguration configuration) in /app/DDD.Services.Api/StartupExtensions/AuthExtension.cs:line 21
   at DDD.Services.Api.Startup.ConfigureServices(IServiceCollection services) in /app/DDD.Services.Api/Startup.cs:line 31
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.InvokeCore(Object instance, IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass9_0.<Invoke>g__Startup|0(IServiceCollection serviceCollection)
   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.Invoke(Object instance, IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass8_0.<Build>b__0(IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.UseStartup(Type startupType, HostBuilderContext context, IServiceCollection services, Object instance)
   at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass13_0.<UseStartup>b__0(HostBuilderContext context, IServiceCollection services)
   at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()
   at Microsoft.Extensions.Hosting.HostBuilder.Build()
   at DDD.Services.Api.Program.Main(String[] args) in /app/DDD.Services.Api/Program.cs:line 10

^ This seems like having problem with finding SecretKey in configuration, when I replicated the SecretKey from appsettings.Development.json to other configurations I get...

docker run -it --rm -p 3000:80 --name aspnetcore-docker-container aspnetcore-docker-image
warn: Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository[60]
      Storing keys in a directory '/root/.aspnet/DataProtection-Keys' that may not be persisted outside of the container. Protected data will be unavailable when container is destroyed.
warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
      No XML encryptor configured. Key {cc7de1c8-e75f-4641-a180-9d2015388bc5} may be persisted to storage in unencrypted form.
Unhandled exception. System.TypeLoadException: Method 'GetServiceProviderHashCode' in type 'ExtensionInfo' from assembly 'Microsoft.EntityFrameworkCore.InMemory, Version=5.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' does not have an implementation.
   at Microsoft.EntityFrameworkCore.InMemory.Infrastructure.Internal.InMemoryOptionsExtension.get_Info()
   at Microsoft.EntityFrameworkCore.DbContextOptions.GetHashCode()
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd[TArg](TKey key, Func`3 valueFactory, TArg factoryArgument)
   at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.GetOrAdd(IDbContextOptions options, Boolean providerRequired)
   at Microsoft.EntityFrameworkCore.DbContext..ctor(DbContextOptions options)
   at HealthChecks.UI.Core.Data.HealthChecksDb..ctor(DbContextOptions`1 options)
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite callSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass2_0.<RealizeService>b__0(ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
   at HealthChecks.UI.Core.HostedService.UIInitializationHostedService.InitializeDatabase(IServiceProvider sp)
   at HealthChecks.UI.Core.HostedService.UIInitializationHostedService.StartAsync(CancellationToken cancellationToken)
   at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
   at DDD.Services.Api.Program.Main(String[] args) in /app/DDD.Services.Api/Program.cs:line 10

And here.. no idea..

How to map with AutoMapper for AspNet Identity Core

For example if I have:

var Users = await UserManager.Users.ToListAsync();
return Response(Users);

This exposes all the fields of the ApplicationUser entity, however I only want to expose a few fields and would like to do using AutoMapper.

Help me please. Thanks!

Create LoginCommandHandler

Hi @ntxinh ,
I would like to be able to move all the login logic to a command following the CQRS pattern. I think that such command should be created in the "Infra.CrossCutting.Identity" layer. What I want is that the logic of the "AccountController" is simple.
Sorry for my English, I speak Spanish.
Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.