All Projects → kimcu-on-thenet → ddd-net-ef-core

kimcu-on-thenet / ddd-net-ef-core

Licence: other
Self study: DDD, .net core, entity framework core

Programming Languages

C#
18002 projects
powershell
5483 projects

Projects that are alternatives of or similar to ddd-net-ef-core

Sample Dotnet Core Cqrs Api
Sample .NET Core REST API CQRS implementation with raw SQL and DDD using Clean Architecture.
Stars: ✭ 1,273 (+3004.88%)
Mutual labels:  cqrs, domain-driven-design, entity-framework-core, dapper
fake-survey-generator
A slightly more-than-trivial full-stack application built with DDD & CQRS concepts
Stars: ✭ 49 (+19.51%)
Mutual labels:  cqrs, domain-driven-design, entity-framework-core, mediatr
MonolithicArchitecture
This repository presents an approach on how to build an application using Monolithic architecture, ASP.NET Core, EntityFrameworkCore, Identity Server, CQRS, DDD
Stars: ✭ 18 (-56.1%)
Mutual labels:  cqrs, domain-driven-design, entity-framework-core
Happysocialmedia
Microservices Social Media / Network / Chatt, with .net core 2.2, Docker, Implement with Domain Driven Design with all best practices design and architetural patterns as DDD, CrossCutting IoC, SOLID, etc
Stars: ✭ 28 (-31.71%)
Mutual labels:  domain-driven-design, entity-framework-core, dapper
Cqrswithmediatr
CQRS implementation in .NET Core with MediaTR tutorial
Stars: ✭ 71 (+73.17%)
Mutual labels:  cqrs, domain-driven-design, netcore
Revo
Event Sourcing, CQRS and DDD framework for C#/.NET Core.
Stars: ✭ 162 (+295.12%)
Mutual labels:  cqrs, domain-driven-design, netcore
Modular Monolith With Ddd
Full Modular Monolith application with Domain-Driven Design approach.
Stars: ✭ 6,210 (+15046.34%)
Mutual labels:  cqrs, domain-driven-design, entity-framework-core
Dotnetcore Microservices Poc
Very simplified insurance sales system made in a microservices architecture using .NET Core
Stars: ✭ 1,304 (+3080.49%)
Mutual labels:  cqrs, netcore, dapper
Stove
Domain Driven Design oriented application framework, meets CRUD needs
Stars: ✭ 160 (+290.24%)
Mutual labels:  cqrs, domain-driven-design, dapper
EcommerceDDD
Experimental full-stack application using Domain-Driven Design, CQRS, and Event Sourcing.
Stars: ✭ 178 (+334.15%)
Mutual labels:  cqrs, domain-driven-design, netcore
RCM
RCM is a simple CRM application designed for Auto Parts Store made with ASP.NET Core based on DDD, CQRS and SOLID Principles.
Stars: ✭ 29 (-29.27%)
Mutual labels:  cqrs, entity-framework-core, mediatr
hexagonal-clean-architecture
Clean architecture focused on microservices with .NET Core 3.1 and C# 8
Stars: ✭ 47 (+14.63%)
Mutual labels:  domain-driven-design, entity-framework-core
DDD
Domain-Driven Design example
Stars: ✭ 116 (+182.93%)
Mutual labels:  cqrs, domain-driven-design
Kodkod
https://github.com/alirizaadiyahsi/Nucleus Web API layered architecture startup template with ASP.NET Core 2.1, EF Core 2.1 and Vue Client
Stars: ✭ 45 (+9.76%)
Mutual labels:  netcore, entity-framework-core
cqrs-event-sourcing-example
Example of a list-making Web API using CQRS, Event Sourcing and DDD.
Stars: ✭ 28 (-31.71%)
Mutual labels:  cqrs, domain-driven-design
Plastic
This project provides encapsulation of things like Domain, Application Rules, Business Rules or Business Logic in Application.
Stars: ✭ 30 (-26.83%)
Mutual labels:  cqrs, domain-driven-design
eav-bundle
A Symfony bundle for basic EAV management
Stars: ✭ 19 (-53.66%)
Mutual labels:  cqrs, domain-driven-design
Distributed-eStore
Ecommerce SPA application with a microservices architecture implemented from scratch. Tech stack - Docker, Consul, Fabio, RabbitMQ, .Net Core, Mediatr, CQRS, React, Redux. .NET Core Microservices template, .NET React Redux, .NET RabbitMQ, .NET Distributed, Docker, .NET Core with Docker.
Stars: ✭ 99 (+141.46%)
Mutual labels:  cqrs, mediatr
MediatrTutorial
CQRS implementation in ASP.NET Core using MediatR in .NET 5
Stars: ✭ 88 (+114.63%)
Mutual labels:  cqrs, mediatr
CleanArchitecture-Template
This is a solution template for Clean Architecture and CQRS implementation with ASP.NET Core.
Stars: ✭ 60 (+46.34%)
Mutual labels:  cqrs, mediatr

An Example of using DDD with .NET Core 3.1

Build Status

  • Domain Driven Design (aka DDD)
  • .NET Core 3.1
  • EntityFramework Core 3.1

Overview

Domain Models

In the Product Catalog bounded context, I have a following Aggregate-Roots, Entities and Value Objects

  1. Aggregate-Roots:

    1. Product
    2. Category
    3. Catalog
  2. Entities:

    1. CatalogCategory
    2. CatalogProduct
  3. Value Objects:

    1. CategoryId
    2. ProductId
    3. CatalogId
    4. CatalogCategoryId
    5. CatalogProductId

Aggregate Root Relationships

  1. Catalog and Category

    • The CatalogCategory represents the instance of Category in specific Catalog
  2. Category and Category

    • In specific Catalog, the categories can be organized as tree structure. Therefore, the CatalogCategory can have another as its parent.
  3. Product, Category and Catalog

    • The CatalogProduct represents the instance of Product in specific CatalogCategory

CQRS

  1. DDDEfCore.ProductCatalog.Services.Commands: for Create, Update and delete operators by consuming repositories.
  2. DDDEfCore.ProductCatalog.Services.Queries: for all of the query operators by using Dapper

Highlighted Points

Strongly-Typed Entities Id

I want to use Strongly-Typed Ids for all models (i.e. CatalogId, CatalogCategoryId and so on) because of the benefits that described very well in the series of Using strongly-typed entity IDs to avoid primitive obsession part 1, part-2, part-3. Therefore, I have to add some advance steps to accomplish this need

  1. For EntityFramework Core
  • Use Value Conversion feature to define the mapping.

            builder
                .Property(x => x.Id)
                .UsePropertyAccessMode(PropertyAccessMode.Field)
                .HasConversion(x => x.Id, id => (CatalogId)id);
  1. For Dapper
  • Custom SqlMapper.TypeHandler

        public class StronglyTypedIdMapper<TIdenity> : SqlMapper.TypeHandler<TIdenity> where TIdenity : IdentityBase
        {
            #region Overrides of TypeHandler<TIdenityType>
    
            public override void SetValue(IDbDataParameter parameter, TIdenity value)
            {
                parameter.Value = value.Id;
            }
    
            public override TIdenity Parse(object value)
            {
                return IdentityFactory.Create<TIdenity>(value);
            }
    
            #endregion
        }
  1. For .NET Core
  • Custom TypeConverter

        public class StronglyTypedIdConverter<TIdentity> : TypeConverter where TIdentity : IdentityBase
        {
            #region Overrides of TypeConverter
    
            public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
            {
                return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
            }
    
            public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
            {
                var stringValue = value as string;
                if (!string.IsNullOrEmpty(stringValue) && Guid.TryParse(stringValue, out var guid))
                {
                    return IdentityFactory.Create<TIdentity>(guid);
                }
    
                return base.ConvertFrom(context, culture, value);
            }
    
            #endregion
        }
  • Custom JsonConverter

        public class IdentityJsonConverter<TIdentity> : JsonConverter<TIdentity> where TIdentity : IdentityBase
        {
            public override bool CanConvert(Type typeToConvert)
            {
                return typeToConvert == typeof(TIdentity);
            }
    
            public override TIdentity Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
            {
                return IdentityFactory.Create<TIdentity>(reader.GetGuid());
            }
    
            public override void Write(Utf8JsonWriter writer, TIdentity value, JsonSerializerOptions options)
            {
                writer.WriteStringValue(value.Id);
            }
        }

For CQRS

For Testing

About Test Projects

  1. DDDEfCore.ProductCatalog.Core.DomainModels.Tests

    • Unit Test for the behaviors of Domain Models
  2. DDDEfCore.ProductCatalog.Infrastructure.EfCore.Tests

    • Integration Test with EntityFramework Core and SqlServer for repositories of Aggregate-Roots
  3. DDDEfCore.ProductCatalog.Services.Commands.Tests

  4. DDDEfCore.ProductCatalog.Services.Queries.Tests

    • Integration Test with Dapper and SqlServer for Query Handlers.
  5. DDDEfCore.ProductCatalog.WebApi.Tests

    • Integration Test with Web Api by consuming Microsoft.AspNetCore.TestHost

Interesting Points

For every test project, I use the following packages

  • Shoudly: Should testing for .NET - the way Asserting Should be!
  • AutoFixture: AutoFixture is an open source library for .NET designed to minimize the 'Arrange' phase of your unit tests in order to maximize maintainability. Its primary goal is to allow developers to focus on what is being tested rather than how to setup the test scenario, by making it easier to create object graphs containing test data.
  • Respawn: Intelligent database cleaner for integration tests

How to run

Run Test Projects

  • In every integration test project, there are appsettings.json files that store connectstrings value. You have to change these values before running.

Test Results

Run via swagger from Visual Studio

  • You have to change the connectionstring value in appsettings.Development.json under DDDEfCore.ProductCatalog.WebApi

  • After run the WebApi by Ctrl+F5 from Visual Studio, assume the Url is http://localhost:[port]

    • Switch to swagger via swagger

    Swagger

How to see the codecoverage report

  • Use PowerShell, change location to cake; then execute the following command
.\build.ps1
  • After run successfully, go to code_coverage folder, and open the index.html by browser to see the report

Give a Star!

If you liked this project or if it helped you, please give a star for this repository. Thank you!!!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].