├── DomainDrivenDesignUdemy.WebApi ├── appsettings.Development.json ├── appsettings.json ├── Program.cs ├── Controllers │ ├── OrdersController.cs │ ├── ProductsController.cs │ ├── UsersController.cs │ └── CategoriesController.cs ├── DomainDrivenDesignUdemy.WebApi.csproj └── Properties │ └── launchSettings.json ├── DomainDrivenDesignUdemy.Domain ├── Abstractions │ ├── IUnitOfWork.cs │ └── Entity.cs ├── Orders │ ├── CreateOrderDto.cs │ ├── OrderStatusEnum.cs │ ├── Events │ │ ├── OrderDomainEvent.cs │ │ ├── SendOrderEmailEvent.cs │ │ └── SendOrderSmsEvent.cs │ ├── IOrderRepository.cs │ ├── OrderLine.cs │ └── Order.cs ├── Users │ ├── Address.cs │ ├── Events │ │ ├── UserDomainEvent.cs │ │ └── SendRegisterEmailEvent.cs │ ├── IUserRepository.cs │ ├── Password.cs │ ├── Email.cs │ └── User.cs ├── Categories │ ├── ICategoryRepository.cs │ └── Category.cs ├── Products │ ├── IProductRepository.cs │ └── Product.cs ├── DomainDrivenDesignUdemy.Domain.csproj └── Shared │ ├── Name.cs │ ├── Money.cs │ └── Currency.cs ├── DomainDrivenDesignUdemy.Application ├── Features │ ├── Categories │ │ ├── CreateCategory │ │ │ ├── CreateCategoryCommand.cs │ │ │ └── CreateCategoryCommandHandler.cs │ │ └── GetAllCategory │ │ │ └── GetAllCategoryQuery.cs │ ├── Users │ │ ├── GetAllUser │ │ │ ├── GetAllUserQuery.cs │ │ │ └── GetAllUserQueryHandler.cs │ │ └── CreateUser │ │ │ ├── CreateUserCommand.cs │ │ │ └── CreateUserCommandHander.cs │ ├── Orders │ │ ├── GetAllOrder │ │ │ ├── GetAllOrderQuery.cs │ │ │ └── GetAllOrderQueryHandler.cs │ │ └── CreateOrder │ │ │ ├── CreateOrderCommand.cs │ │ │ └── CreateOrderCommandHandler.cs │ └── Products │ │ ├── GetAllProduct │ │ ├── GetAllProductQuery.cs │ │ └── GetAllProductQueryHandler.cs │ │ └── CreateProduct │ │ ├── CreateProductCommand.cs │ │ └── CreateProductCommandHandler.cs ├── DomainDrivenDesignUdemy.Application.csproj └── DependencyInjection.cs ├── DomainDrivenDesignUdemy.ConsoleApp ├── DomainDrivenDesignUdemy.ConsoleApp.csproj ├── BenchMarkService.cs └── Program.cs ├── DomainDrivenDesignUdemy.Infrastructure ├── DomainDrivenDesignUdemy.Infrastructure.csproj ├── Repositories │ ├── CategoryRepository.cs │ ├── ProductRepository.cs │ ├── UserRepository.cs │ └── OrderRepository.cs ├── DependencyInjection.cs ├── Context │ └── ApplicationDbContext.cs └── Migrations │ ├── 20231113032740_mg1.cs │ ├── ApplicationDbContextModelSnapshot.cs │ └── 20231113032740_mg1.Designer.cs ├── README.md ├── .gitattributes ├── DomainDrivenDesignUdemy.sln └── .gitignore /DomainDrivenDesignUdemy.WebApi/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.WebApi/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "AllowedHosts": "*" 9 | } 10 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Domain/Abstractions/IUnitOfWork.cs: -------------------------------------------------------------------------------- 1 | namespace DomainDrivenDesignUdemy.Domain.Abstractions; 2 | public interface IUnitOfWork 3 | { 4 | Task SaveChangesAsync(CancellationToken cancellationToken = default); 5 | } 6 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Domain/Orders/CreateOrderDto.cs: -------------------------------------------------------------------------------- 1 | namespace DomainDrivenDesignUdemy.Domain.Orders; 2 | 3 | public sealed record CreateOrderDto( 4 | Guid ProductId, 5 | int Quantity, 6 | decimal Amount, 7 | string Currency); 8 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Domain/Orders/OrderStatusEnum.cs: -------------------------------------------------------------------------------- 1 | namespace DomainDrivenDesignUdemy.Domain.Orders; 2 | 3 | public enum OrderStatusEnum 4 | { 5 | AwaitingApproval = 1, 6 | BeingPrepared = 2, 7 | InTransit = 3, 8 | Delivered = 4 9 | } -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Domain/Users/Address.cs: -------------------------------------------------------------------------------- 1 | namespace DomainDrivenDesignUdemy.Domain.Users; 2 | 3 | public sealed record Address( 4 | string Country, 5 | string City, 6 | string Street, 7 | string FullAddress, 8 | string PostalCode); 9 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Application/Features/Categories/CreateCategory/CreateCategoryCommand.cs: -------------------------------------------------------------------------------- 1 | using MediatR; 2 | 3 | namespace DomainDrivenDesignUdemy.Application.Features.Categories.CreateCategory; 4 | public sealed record CreateCategoryCommand( 5 | string Name): IRequest; 6 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Application/Features/Users/GetAllUser/GetAllUserQuery.cs: -------------------------------------------------------------------------------- 1 | using DomainDrivenDesignUdemy.Domain.Users; 2 | using MediatR; 3 | 4 | namespace DomainDrivenDesignUdemy.Application.Features.Users.GetAllUser; 5 | public sealed record GetAllUserQuery(): IRequest>; 6 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Application/Features/Orders/GetAllOrder/GetAllOrderQuery.cs: -------------------------------------------------------------------------------- 1 | using DomainDrivenDesignUdemy.Domain.Orders; 2 | using MediatR; 3 | 4 | namespace DomainDrivenDesignUdemy.Application.Features.Orders.GetAllOrder; 5 | public sealed record GetAllOrderQuery():IRequest>; 6 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Application/Features/Products/GetAllProduct/GetAllProductQuery.cs: -------------------------------------------------------------------------------- 1 | using DomainDrivenDesignUdemy.Domain.Products; 2 | using MediatR; 3 | 4 | namespace DomainDrivenDesignUdemy.Application.Features.Products.GetAllProduct; 5 | public sealed record GetAllProductQuery():IRequest>; 6 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Application/Features/Orders/CreateOrder/CreateOrderCommand.cs: -------------------------------------------------------------------------------- 1 | using DomainDrivenDesignUdemy.Domain.Orders; 2 | using MediatR; 3 | 4 | namespace DomainDrivenDesignUdemy.Application.Features.Orders.CreateOrder; 5 | public sealed record CreateOrderCommand( 6 | List CreateOrderDtos) :IRequest; 7 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Domain/Users/Events/UserDomainEvent.cs: -------------------------------------------------------------------------------- 1 | using MediatR; 2 | 3 | namespace DomainDrivenDesignUdemy.Domain.Users.Events; 4 | public sealed class UserDomainEvent : INotification 5 | { 6 | public User User { get; } 7 | public UserDomainEvent(User user) 8 | { 9 | User = user; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Domain/Categories/ICategoryRepository.cs: -------------------------------------------------------------------------------- 1 | namespace DomainDrivenDesignUdemy.Domain.Categories; 2 | public interface ICategoryRepository 3 | { 4 | Task CreateAsync(string name, CancellationToken cancellationToken = default); 5 | Task> GetAllAsync(CancellationToken cancellationToken = default); 6 | } 7 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Domain/Orders/Events/OrderDomainEvent.cs: -------------------------------------------------------------------------------- 1 | using MediatR; 2 | 3 | namespace DomainDrivenDesignUdemy.Domain.Orders.Events; 4 | public sealed class OrderDomainEvent : INotification 5 | { 6 | public Order Order { get; } 7 | public OrderDomainEvent(Order order) 8 | { 9 | Order = order; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Domain/Orders/IOrderRepository.cs: -------------------------------------------------------------------------------- 1 | namespace DomainDrivenDesignUdemy.Domain.Orders; 2 | public interface IOrderRepository 3 | { 4 | Task CreateAsync(List createOrderDtos, CancellationToken cancellationToken = default); 5 | Task> GetAllAsync(CancellationToken cancellationToken = default); 6 | } 7 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Application/Features/Products/CreateProduct/CreateProductCommand.cs: -------------------------------------------------------------------------------- 1 | using MediatR; 2 | 3 | namespace DomainDrivenDesignUdemy.Application.Features.Products.CreateProduct; 4 | public sealed record CreateProductCommand( 5 | string Name, 6 | int Quantity, 7 | decimal Amount, 8 | string Currency, 9 | Guid CategoryId) : IRequest; 10 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Domain/Products/IProductRepository.cs: -------------------------------------------------------------------------------- 1 | namespace DomainDrivenDesignUdemy.Domain.Products; 2 | public interface IProductRepository 3 | { 4 | Task CreateAsync(string name, int quantity, decimal amount, string currency, Guid categoryId, CancellationToken cancellationToken = default); 5 | Task> GetAllAsync(CancellationToken cancellationToken = default); 6 | } 7 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Domain/DomainDrivenDesignUdemy.Domain.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Application/Features/Users/CreateUser/CreateUserCommand.cs: -------------------------------------------------------------------------------- 1 | using MediatR; 2 | 3 | namespace DomainDrivenDesignUdemy.Application.Features.Users.CreateUser; 4 | public sealed record CreateUserCommand( 5 | string Name, 6 | string Email, 7 | string Password, 8 | string Country, 9 | string City, 10 | string Street, 11 | string PostalCode, 12 | string FullAddress) : IRequest; 13 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Domain/Users/IUserRepository.cs: -------------------------------------------------------------------------------- 1 | namespace DomainDrivenDesignUdemy.Domain.Users; 2 | public interface IUserRepository 3 | { 4 | Task CreateAsync(string name, string email, string password, string country, string city, string street, string postalCode, string fullAddress, CancellationToken cancellationToken = default); 5 | 6 | Task> GetAllAsync(CancellationToken cancellationToken = default); 7 | } 8 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Domain/Orders/Events/SendOrderEmailEvent.cs: -------------------------------------------------------------------------------- 1 | using MediatR; 2 | 3 | namespace DomainDrivenDesignUdemy.Domain.Orders.Events; 4 | public sealed class SendOrderEmailEvent : INotificationHandler 5 | { 6 | public Task Handle(OrderDomainEvent notification, CancellationToken cancellationToken) 7 | { 8 | //Mail gönderme işlemi 9 | return Task.CompletedTask; 10 | } 11 | } 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Domain/Orders/Events/SendOrderSmsEvent.cs: -------------------------------------------------------------------------------- 1 | using MediatR; 2 | 3 | namespace DomainDrivenDesignUdemy.Domain.Orders.Events; 4 | 5 | public sealed class SendOrderSmsEvent : INotificationHandler 6 | { 7 | public Task Handle(OrderDomainEvent notification, CancellationToken cancellationToken) 8 | { 9 | //Sms gönderme işlemi 10 | return Task.CompletedTask; 11 | } 12 | } 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Domain/Users/Events/SendRegisterEmailEvent.cs: -------------------------------------------------------------------------------- 1 | using MediatR; 2 | 3 | namespace DomainDrivenDesignUdemy.Domain.Users.Events; 4 | 5 | public sealed class SendRegisterEmailEvent : INotificationHandler 6 | { 7 | public Task Handle(UserDomainEvent notification, CancellationToken cancellationToken) 8 | { 9 | //Kullanıcı için register email gönderme işlemi 10 | return Task.CompletedTask; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.ConsoleApp/DomainDrivenDesignUdemy.ConsoleApp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net7.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Domain/Shared/Name.cs: -------------------------------------------------------------------------------- 1 | namespace DomainDrivenDesignUdemy.Domain.Shared; 2 | 3 | public sealed record Name 4 | { 5 | public string Value { get; init; } 6 | public Name(string value) 7 | { 8 | if (string.IsNullOrEmpty(value)) 9 | { 10 | throw new ArgumentException("İsim alanı boş olamaz!"); 11 | } 12 | 13 | if (value.Length < 3) 14 | { 15 | throw new ArgumentException("İsim alanı 3 karakterden küçük olamaz!"); 16 | } 17 | 18 | Value = value; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Application/DomainDrivenDesignUdemy.Application.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Domain/Users/Password.cs: -------------------------------------------------------------------------------- 1 | namespace DomainDrivenDesignUdemy.Domain.Users; 2 | 3 | public sealed record Password 4 | { 5 | public string Value { get; init; } 6 | public Password(string value) 7 | { 8 | if (string.IsNullOrEmpty(value)) 9 | { 10 | throw new ArgumentException("İsim alanı boş olamaz!"); 11 | } 12 | 13 | if (value.Length < 6) 14 | { 15 | throw new ArgumentException("İsim alanı 6 karakterden küçük olamaz!"); 16 | } 17 | 18 | Value = value; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Domain/Shared/Money.cs: -------------------------------------------------------------------------------- 1 | namespace DomainDrivenDesignUdemy.Domain.Shared; 2 | public sealed record Money(decimal Amount, Currency Currency) 3 | { 4 | public static Money operator +(Money a, Money b) 5 | { 6 | if(a.Currency != b.Currency) 7 | { 8 | throw new ArgumentException("Para birimleri birbirinden farklı değerler toplanamaz!"); 9 | } 10 | 11 | return new(a.Amount + b.Amount, a.Currency); 12 | } 13 | 14 | public static Money Zero() => new(0, Currency.None); 15 | public static Money Zero(Currency currency) => new(0, currency); 16 | 17 | public bool IsZero() => this == Zero(Currency); 18 | } 19 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.WebApi/Program.cs: -------------------------------------------------------------------------------- 1 | using DomainDrivenDesignUdemy.Application; 2 | using DomainDrivenDesignUdemy.Infrastructure; 3 | 4 | var builder = WebApplication.CreateBuilder(args); 5 | 6 | builder.Services.AddApplication(); 7 | builder.Services.AddInfrastructure(); 8 | 9 | builder.Services.AddControllers(); 10 | builder.Services.AddEndpointsApiExplorer(); 11 | builder.Services.AddSwaggerGen(); 12 | 13 | var app = builder.Build(); 14 | 15 | if (app.Environment.IsDevelopment()) 16 | { 17 | app.UseSwagger(); 18 | app.UseSwaggerUI(); 19 | } 20 | 21 | app.UseHttpsRedirection(); 22 | 23 | app.UseAuthorization(); 24 | 25 | app.MapControllers(); 26 | 27 | app.Run(); 28 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Domain/Categories/Category.cs: -------------------------------------------------------------------------------- 1 | using DomainDrivenDesignUdemy.Domain.Abstractions; 2 | using DomainDrivenDesignUdemy.Domain.Products; 3 | using DomainDrivenDesignUdemy.Domain.Shared; 4 | 5 | namespace DomainDrivenDesignUdemy.Domain.Categories; 6 | public sealed class Category : Entity 7 | { 8 | private Category(Guid id) : base(id) 9 | { 10 | 11 | } 12 | public Category(Guid id, Name name): base(id) 13 | { 14 | Name = name; 15 | } 16 | 17 | public Name Name { get; private set; } 18 | public ICollection Products { get; private set; } 19 | 20 | public void ChangeName(string name) 21 | { 22 | Name = new(name); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Application/DependencyInjection.cs: -------------------------------------------------------------------------------- 1 | using DomainDrivenDesignUdemy.Domain.Abstractions; 2 | using DomainDrivenDesignUdemy.Domain.Users; 3 | using Microsoft.Extensions.DependencyInjection; 4 | using System.Reflection; 5 | 6 | namespace DomainDrivenDesignUdemy.Application; 7 | public static class DependencyInjection 8 | { 9 | public static IServiceCollection AddApplication( 10 | this IServiceCollection services) 11 | { 12 | services.AddMediatR(cfr => 13 | { 14 | cfr.RegisterServicesFromAssemblies( 15 | Assembly.GetExecutingAssembly(), 16 | typeof(Entity).Assembly); 17 | }); 18 | 19 | return services; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Domain/Users/Email.cs: -------------------------------------------------------------------------------- 1 | namespace DomainDrivenDesignUdemy.Domain.Users; 2 | 3 | public sealed record Email 4 | { 5 | public string Value { get; init; } 6 | public Email(string value) 7 | { 8 | 9 | if (string.IsNullOrEmpty(value)) 10 | { 11 | throw new ArgumentException("İsim alanı boş olamaz!"); 12 | } 13 | 14 | if (value.Length < 3) 15 | { 16 | throw new ArgumentException("İsim alanı 3 karakterden küçük olamaz!"); 17 | } 18 | 19 | if (!value.Contains("@")) 20 | { 21 | throw new ArgumentException("Geçerli bir mail adresi girin!"); 22 | } 23 | 24 | Value = value; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Application/Features/Users/GetAllUser/GetAllUserQueryHandler.cs: -------------------------------------------------------------------------------- 1 | using DomainDrivenDesignUdemy.Domain.Users; 2 | using MediatR; 3 | 4 | namespace DomainDrivenDesignUdemy.Application.Features.Users.GetAllUser; 5 | 6 | internal sealed class GetAllUserQueryHandler : IRequestHandler> 7 | { 8 | private readonly IUserRepository _userRepository; 9 | 10 | public GetAllUserQueryHandler(IUserRepository userRepository) 11 | { 12 | _userRepository = userRepository; 13 | } 14 | 15 | public async Task> Handle(GetAllUserQuery request, CancellationToken cancellationToken) 16 | { 17 | return await _userRepository.GetAllAsync(cancellationToken); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Application/Features/Orders/GetAllOrder/GetAllOrderQueryHandler.cs: -------------------------------------------------------------------------------- 1 | using DomainDrivenDesignUdemy.Domain.Orders; 2 | using MediatR; 3 | 4 | namespace DomainDrivenDesignUdemy.Application.Features.Orders.GetAllOrder; 5 | 6 | internal sealed class GetAllOrderQueryHandler : IRequestHandler> 7 | { 8 | private readonly IOrderRepository _orderRepository; 9 | 10 | public GetAllOrderQueryHandler(IOrderRepository orderRepository) 11 | { 12 | _orderRepository = orderRepository; 13 | } 14 | 15 | public async Task> Handle(GetAllOrderQuery request, CancellationToken cancellationToken) 16 | { 17 | return await _orderRepository.GetAllAsync(cancellationToken); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Domain/Shared/Currency.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.Tracing; 2 | 3 | namespace DomainDrivenDesignUdemy.Domain.Shared; 4 | public sealed record Currency 5 | { 6 | internal static readonly Currency None = new(""); 7 | public static readonly Currency Usd = new("Usd"); 8 | public static readonly Currency TRY = new("TRY"); 9 | public string Code { get; init; } 10 | private Currency(string code) 11 | { 12 | Code = code; 13 | } 14 | 15 | public static Currency FromCode(string code) 16 | { 17 | return All.FirstOrDefault(p => p.Code == code) ?? 18 | throw new ArgumentException("Geçerli bir para birimi girin!"); 19 | } 20 | 21 | public static readonly IReadOnlyCollection All = new[] { Usd, TRY }; 22 | } 23 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Application/Features/Products/GetAllProduct/GetAllProductQueryHandler.cs: -------------------------------------------------------------------------------- 1 | using DomainDrivenDesignUdemy.Domain.Products; 2 | using MediatR; 3 | 4 | namespace DomainDrivenDesignUdemy.Application.Features.Products.GetAllProduct; 5 | 6 | internal sealed class GetAllProductQueryHandler : IRequestHandler> 7 | { 8 | private readonly IProductRepository _productRepository; 9 | 10 | public GetAllProductQueryHandler(IProductRepository productRepository) 11 | { 12 | _productRepository = productRepository; 13 | } 14 | 15 | public async Task> Handle(GetAllProductQuery request, CancellationToken cancellationToken) 16 | { 17 | return await _productRepository.GetAllAsync(cancellationToken); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Domain/Orders/OrderLine.cs: -------------------------------------------------------------------------------- 1 | using DomainDrivenDesignUdemy.Domain.Abstractions; 2 | using DomainDrivenDesignUdemy.Domain.Products; 3 | using DomainDrivenDesignUdemy.Domain.Shared; 4 | 5 | namespace DomainDrivenDesignUdemy.Domain.Orders; 6 | 7 | public sealed class OrderLine : Entity 8 | { 9 | private OrderLine(Guid id) : base(id) 10 | { 11 | 12 | } 13 | public OrderLine(Guid id, Guid orderId, Guid productId, int quantity, Money price) : base(id) 14 | { 15 | ProductId = productId; 16 | Quantity = quantity; 17 | Price = price; 18 | } 19 | 20 | public Guid OrderId { get; private set; } 21 | public Guid ProductId { get; private set; } 22 | public Product Product { get; private set; } 23 | public int Quantity { get; private set; } 24 | public Money Price { get; private set; } 25 | } -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Infrastructure/DomainDrivenDesignUdemy.Infrastructure.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | all 13 | runtime; build; native; contentfiles; analyzers; buildtransitive 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Application/Features/Categories/GetAllCategory/GetAllCategoryQuery.cs: -------------------------------------------------------------------------------- 1 | using DomainDrivenDesignUdemy.Domain.Categories; 2 | using MediatR; 3 | 4 | namespace DomainDrivenDesignUdemy.Application.Features.Categories.GetAllCategory; 5 | public sealed record GetAllCategoryQuery(): IRequest>; 6 | 7 | internal sealed class GetAllCategoryQueryHandler : IRequestHandler> 8 | { 9 | private readonly ICategoryRepository _categoryRepository; 10 | 11 | public GetAllCategoryQueryHandler(ICategoryRepository categoryRepository) 12 | { 13 | _categoryRepository = categoryRepository; 14 | } 15 | 16 | public async Task> Handle(GetAllCategoryQuery request, CancellationToken cancellationToken) 17 | { 18 | return await _categoryRepository.GetAllAsync(cancellationToken); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Infrastructure/Repositories/CategoryRepository.cs: -------------------------------------------------------------------------------- 1 | using DomainDrivenDesignUdemy.Domain.Categories; 2 | using DomainDrivenDesignUdemy.Infrastructure.Context; 3 | using Microsoft.EntityFrameworkCore; 4 | 5 | namespace DomainDrivenDesignUdemy.Infrastructure.Repositories; 6 | internal sealed class CategoryRepository : ICategoryRepository 7 | { 8 | private readonly ApplicationDbContext _context; 9 | 10 | public CategoryRepository(ApplicationDbContext context) 11 | { 12 | _context = context; 13 | } 14 | 15 | public async Task CreateAsync(string name, CancellationToken cancellationToken = default) 16 | { 17 | Category category = new(Guid.NewGuid(), new(name)); 18 | await _context.Categories.AddAsync(category, cancellationToken); 19 | } 20 | 21 | public async Task> GetAllAsync(CancellationToken cancellationToken = default) 22 | { 23 | return await _context.Categories.ToListAsync(cancellationToken); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Application/Features/Categories/CreateCategory/CreateCategoryCommandHandler.cs: -------------------------------------------------------------------------------- 1 | using DomainDrivenDesignUdemy.Domain.Abstractions; 2 | using DomainDrivenDesignUdemy.Domain.Categories; 3 | using MediatR; 4 | 5 | namespace DomainDrivenDesignUdemy.Application.Features.Categories.CreateCategory; 6 | 7 | internal sealed class CreateCategoryCommandHandler : IRequestHandler 8 | { 9 | private readonly ICategoryRepository _categoryRepository; 10 | private readonly IUnitOfWork _unitOfWork; 11 | 12 | public CreateCategoryCommandHandler(ICategoryRepository categoryRepository, IUnitOfWork unitOfWork) 13 | { 14 | _categoryRepository = categoryRepository; 15 | _unitOfWork = unitOfWork; 16 | } 17 | 18 | public async Task Handle(CreateCategoryCommand request, CancellationToken cancellationToken) 19 | { 20 | await _categoryRepository.CreateAsync(request.Name, cancellationToken); 21 | await _unitOfWork.SaveChangesAsync(cancellationToken); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.WebApi/Controllers/OrdersController.cs: -------------------------------------------------------------------------------- 1 | using DomainDrivenDesignUdemy.Application.Features.Orders.CreateOrder; 2 | using DomainDrivenDesignUdemy.Application.Features.Orders.GetAllOrder; 3 | using MediatR; 4 | using Microsoft.AspNetCore.Mvc; 5 | 6 | namespace DomainDrivenDesignUdemy.WebApi.Controllers; 7 | [Route("api/[controller]/[action]")] 8 | [ApiController] 9 | public class OrdersController : ControllerBase 10 | { 11 | private readonly IMediator _mediator; 12 | 13 | public OrdersController(IMediator mediator) 14 | { 15 | _mediator = mediator; 16 | } 17 | 18 | [HttpPost] 19 | public async Task Create(CreateOrderCommand request, CancellationToken cancellationToken) 20 | { 21 | await _mediator.Send(request, cancellationToken); 22 | return NoContent(); 23 | } 24 | 25 | [HttpPost] 26 | public async Task GetAll(GetAllOrderQuery request, CancellationToken cancellationToken) 27 | { 28 | var response = await _mediator.Send(request, cancellationToken); 29 | return Ok(response); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.WebApi/DomainDrivenDesignUdemy.WebApi.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | all 14 | runtime; build; native; contentfiles; analyzers; buildtransitive 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.WebApi/Controllers/ProductsController.cs: -------------------------------------------------------------------------------- 1 | using DomainDrivenDesignUdemy.Application.Features.Products.CreateProduct; 2 | using DomainDrivenDesignUdemy.Application.Features.Products.GetAllProduct; 3 | using MediatR; 4 | using Microsoft.AspNetCore.Mvc; 5 | 6 | namespace DomainDrivenDesignUdemy.WebApi.Controllers; 7 | [Route("api/[controller]/[action]")] 8 | [ApiController] 9 | public class ProductsController : ControllerBase 10 | { 11 | private readonly IMediator _mediator; 12 | 13 | public ProductsController(IMediator mediator) 14 | { 15 | _mediator = mediator; 16 | } 17 | 18 | [HttpPost] 19 | public async Task Create(CreateProductCommand request, CancellationToken cancellationToken) 20 | { 21 | await _mediator.Send(request, cancellationToken); 22 | return NoContent(); 23 | } 24 | 25 | [HttpPost] 26 | public async Task GetAll(GetAllProductQuery request, CancellationToken cancellationToken) 27 | { 28 | var response = await _mediator.Send(request, cancellationToken); 29 | return Ok(response); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.WebApi/Controllers/UsersController.cs: -------------------------------------------------------------------------------- 1 | using DomainDrivenDesignUdemy.Application.Features.Users.CreateUser; 2 | using DomainDrivenDesignUdemy.Application.Features.Users.GetAllUser; 3 | using MediatR; 4 | using Microsoft.AspNetCore.Http; 5 | using Microsoft.AspNetCore.Mvc; 6 | 7 | namespace DomainDrivenDesignUdemy.WebApi.Controllers; 8 | [Route("api/[controller]/[action]")] 9 | [ApiController] 10 | public class UsersController : ControllerBase 11 | { 12 | private readonly IMediator _mediator; 13 | 14 | public UsersController(IMediator mediator) 15 | { 16 | _mediator = mediator; 17 | } 18 | 19 | [HttpPost] 20 | public async Task Create(CreateUserCommand request, CancellationToken cancellationToken) 21 | { 22 | await _mediator.Send(request, cancellationToken); 23 | return NoContent(); 24 | } 25 | 26 | [HttpPost] 27 | public async Task GetAll(GetAllUserQuery request, CancellationToken cancellationToken) 28 | { 29 | var response = await _mediator.Send(request, cancellationToken); 30 | return Ok(response); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.WebApi/Controllers/CategoriesController.cs: -------------------------------------------------------------------------------- 1 | using DomainDrivenDesignUdemy.Application.Features.Categories.CreateCategory; 2 | using DomainDrivenDesignUdemy.Application.Features.Categories.GetAllCategory; 3 | using MediatR; 4 | using Microsoft.AspNetCore.Mvc; 5 | 6 | namespace DomainDrivenDesignUdemy.WebApi.Controllers; 7 | [Route("api/[controller]/[action]")] 8 | [ApiController] 9 | public class CategoriesController : ControllerBase 10 | { 11 | private readonly IMediator _mediator; 12 | 13 | public CategoriesController(IMediator mediator) 14 | { 15 | _mediator = mediator; 16 | } 17 | 18 | [HttpPost] 19 | public async Task Create(CreateCategoryCommand request, CancellationToken cancellationToken) 20 | { 21 | await _mediator.Send(request, cancellationToken); 22 | return NoContent(); 23 | } 24 | 25 | [HttpPost] 26 | public async Task GetAll(GetAllCategoryQuery request, CancellationToken cancellationToken) 27 | { 28 | var response = await _mediator.Send(request, cancellationToken); 29 | return Ok(response); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Domain/Products/Product.cs: -------------------------------------------------------------------------------- 1 | using DomainDrivenDesignUdemy.Domain.Abstractions; 2 | using DomainDrivenDesignUdemy.Domain.Categories; 3 | using DomainDrivenDesignUdemy.Domain.Shared; 4 | 5 | namespace DomainDrivenDesignUdemy.Domain.Products; 6 | public sealed class Product : Entity 7 | { 8 | private Product(Guid id) : base(id) 9 | { 10 | 11 | } 12 | public Product(Guid id, Name name, int quantity, Money price, Guid categoryId) : base(id) 13 | { 14 | Name = name; 15 | Quantity = quantity; 16 | Price = price; 17 | CategoryId = categoryId; 18 | } 19 | 20 | public Name Name { get; private set; } 21 | public int Quantity { get; private set; } 22 | public Money Price { get; private set; } 23 | public Guid CategoryId { get; private set; } 24 | public Category Category { get; private set; } 25 | 26 | public void Update(string name, int quantity, decimal amount, string currency, Guid categoryId) 27 | { 28 | Name = new(name); 29 | Quantity = quantity; 30 | Price = new(amount, Currency.FromCode(currency)); 31 | CategoryId = categoryId; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Application/Features/Products/CreateProduct/CreateProductCommandHandler.cs: -------------------------------------------------------------------------------- 1 | using DomainDrivenDesignUdemy.Domain.Abstractions; 2 | using DomainDrivenDesignUdemy.Domain.Products; 3 | using MediatR; 4 | 5 | namespace DomainDrivenDesignUdemy.Application.Features.Products.CreateProduct; 6 | 7 | internal sealed class CreateProductCommandHandler : IRequestHandler 8 | { 9 | private readonly IProductRepository _productRepository; 10 | private readonly IUnitOfWork _unitOfWork; 11 | public CreateProductCommandHandler(IProductRepository productRepository, IUnitOfWork unitOfWork) 12 | { 13 | _productRepository = productRepository; 14 | _unitOfWork = unitOfWork; 15 | } 16 | 17 | public async Task Handle(CreateProductCommand request, CancellationToken cancellationToken) 18 | { 19 | await _productRepository.CreateAsync( 20 | request.Name, 21 | request.Quantity, 22 | request.Amount, 23 | request.Currency, 24 | request.CategoryId, 25 | cancellationToken); 26 | 27 | await _unitOfWork.SaveChangesAsync(cancellationToken); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Infrastructure/DependencyInjection.cs: -------------------------------------------------------------------------------- 1 | using DomainDrivenDesignUdemy.Domain.Abstractions; 2 | using DomainDrivenDesignUdemy.Domain.Categories; 3 | using DomainDrivenDesignUdemy.Domain.Orders; 4 | using DomainDrivenDesignUdemy.Domain.Products; 5 | using DomainDrivenDesignUdemy.Domain.Users; 6 | using DomainDrivenDesignUdemy.Infrastructure.Context; 7 | using DomainDrivenDesignUdemy.Infrastructure.Repositories; 8 | using Microsoft.Extensions.DependencyInjection; 9 | 10 | namespace DomainDrivenDesignUdemy.Infrastructure; 11 | public static class DependencyInjection 12 | { 13 | public static IServiceCollection AddInfrastructure( 14 | this IServiceCollection services) 15 | { 16 | 17 | services.AddScoped(); 18 | services.AddScoped(opt=> opt.GetRequiredService()); 19 | 20 | services.AddScoped(); 21 | services.AddScoped(); 22 | services.AddScoped(); 23 | services.AddScoped(); 24 | return services; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Domain/Abstractions/Entity.cs: -------------------------------------------------------------------------------- 1 | namespace DomainDrivenDesignUdemy.Domain.Abstractions; 2 | public abstract class Entity : IEquatable 3 | { 4 | public Guid Id { get; init; } 5 | public Entity(Guid id) 6 | { 7 | Id = id; 8 | } 9 | 10 | public override bool Equals(object? obj) 11 | { 12 | if(obj is null) 13 | { 14 | return false; 15 | } 16 | 17 | if(obj is not Entity entity) 18 | { 19 | return false; 20 | } 21 | 22 | if(obj.GetType() != GetType()) 23 | { 24 | return false; 25 | } 26 | 27 | return entity.Id == Id; 28 | } 29 | 30 | public override int GetHashCode() 31 | { 32 | return Id.GetHashCode(); 33 | } 34 | 35 | public bool Equals(Entity? other) 36 | { 37 | if (other is null) 38 | { 39 | return false; 40 | } 41 | 42 | if (other is not Entity entity) 43 | { 44 | return false; 45 | } 46 | 47 | if (other.GetType() != GetType()) 48 | { 49 | return false; 50 | } 51 | 52 | return entity.Id == Id; 53 | } 54 | } -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Infrastructure/Repositories/ProductRepository.cs: -------------------------------------------------------------------------------- 1 | using DomainDrivenDesignUdemy.Domain.Products; 2 | using DomainDrivenDesignUdemy.Domain.Shared; 3 | using DomainDrivenDesignUdemy.Infrastructure.Context; 4 | using Microsoft.EntityFrameworkCore; 5 | 6 | namespace DomainDrivenDesignUdemy.Infrastructure.Repositories; 7 | internal sealed class ProductRepository : IProductRepository 8 | { 9 | private readonly ApplicationDbContext _context; 10 | 11 | public ProductRepository(ApplicationDbContext context) 12 | { 13 | _context = context; 14 | } 15 | 16 | public async Task CreateAsync(string name, int quantity, decimal amount, string currency, Guid categoryId, CancellationToken cancellationToken = default) 17 | { 18 | Product product = new( 19 | Guid.NewGuid(), 20 | new(name), 21 | quantity, 22 | new(amount, Currency.FromCode(currency)), 23 | categoryId); 24 | 25 | await _context.Products.AddAsync(product, cancellationToken); 26 | } 27 | 28 | public async Task> GetAllAsync(CancellationToken cancellationToken = default) 29 | { 30 | return await _context.Products.ToListAsync(cancellationToken); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Application/Features/Orders/CreateOrder/CreateOrderCommandHandler.cs: -------------------------------------------------------------------------------- 1 | using DomainDrivenDesignUdemy.Domain.Abstractions; 2 | using DomainDrivenDesignUdemy.Domain.Orders; 3 | using DomainDrivenDesignUdemy.Domain.Orders.Events; 4 | using MediatR; 5 | using System.Runtime.CompilerServices; 6 | 7 | namespace DomainDrivenDesignUdemy.Application.Features.Orders.CreateOrder; 8 | 9 | internal sealed class CreateOrderCommandHandler : IRequestHandler 10 | { 11 | private readonly IOrderRepository _orderRepository; 12 | private readonly IUnitOfWork _unitOfWork; 13 | private readonly IMediator _mediator; 14 | 15 | public CreateOrderCommandHandler(IOrderRepository orderRepository, IUnitOfWork unitOfWork, IMediator mediator) 16 | { 17 | _orderRepository = orderRepository; 18 | _unitOfWork = unitOfWork; 19 | _mediator = mediator; 20 | } 21 | 22 | public async Task Handle(CreateOrderCommand request, CancellationToken cancellationToken) 23 | { 24 | var order = await _orderRepository.CreateAsync(request.CreateOrderDtos, cancellationToken); 25 | await _unitOfWork.SaveChangesAsync(cancellationToken); 26 | 27 | await _mediator.Publish(new OrderDomainEvent(order)); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.WebApi/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:9872", 8 | "sslPort": 44376 9 | } 10 | }, 11 | "profiles": { 12 | "http": { 13 | "commandName": "Project", 14 | "dotnetRunMessages": true, 15 | "launchBrowser": true, 16 | "launchUrl": "swagger", 17 | "applicationUrl": "http://localhost:5257", 18 | "environmentVariables": { 19 | "ASPNETCORE_ENVIRONMENT": "Development" 20 | } 21 | }, 22 | "https": { 23 | "commandName": "Project", 24 | "dotnetRunMessages": true, 25 | "launchBrowser": true, 26 | "launchUrl": "swagger", 27 | "applicationUrl": "https://localhost:7092;http://localhost:5257", 28 | "environmentVariables": { 29 | "ASPNETCORE_ENVIRONMENT": "Development" 30 | } 31 | }, 32 | "IIS Express": { 33 | "commandName": "IISExpress", 34 | "launchBrowser": true, 35 | "launchUrl": "swagger", 36 | "environmentVariables": { 37 | "ASPNETCORE_ENVIRONMENT": "Development" 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Infrastructure/Repositories/UserRepository.cs: -------------------------------------------------------------------------------- 1 | using DomainDrivenDesignUdemy.Domain.Users; 2 | using DomainDrivenDesignUdemy.Infrastructure.Context; 3 | using Microsoft.EntityFrameworkCore; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Runtime.CompilerServices; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | 11 | namespace DomainDrivenDesignUdemy.Infrastructure.Repositories; 12 | internal sealed class UserRepository : IUserRepository 13 | { 14 | private readonly ApplicationDbContext _context; 15 | 16 | public UserRepository(ApplicationDbContext context) 17 | { 18 | _context = context; 19 | } 20 | 21 | public async Task CreateAsync(string name, string email, string password, string country, string city, string street, string postalCode, string fullAddress, CancellationToken cancellationToken = default) 22 | { 23 | User user = User.CreateUser(name, email, password, country, city, street, postalCode, fullAddress); 24 | await _context.Users.AddAsync(user, cancellationToken); 25 | 26 | return user; 27 | } 28 | 29 | public Task> GetAllAsync(CancellationToken cancellationToken = default) 30 | { 31 | return _context.Users.ToListAsync(cancellationToken); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Infrastructure/Repositories/OrderRepository.cs: -------------------------------------------------------------------------------- 1 | using DomainDrivenDesignUdemy.Domain.Orders; 2 | using DomainDrivenDesignUdemy.Infrastructure.Context; 3 | using Microsoft.EntityFrameworkCore; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace DomainDrivenDesignUdemy.Infrastructure.Repositories; 11 | internal sealed class OrderRepository : IOrderRepository 12 | { 13 | private readonly ApplicationDbContext _context; 14 | 15 | public OrderRepository(ApplicationDbContext context) 16 | { 17 | _context = context; 18 | } 19 | 20 | public async Task CreateAsync(List createOrderDtos, CancellationToken cancellationToken = default) 21 | { 22 | Order order = new( 23 | Guid.NewGuid(), 24 | "1", 25 | DateTime.Now, 26 | OrderStatusEnum.AwaitingApproval); 27 | 28 | order.CreateOrder(createOrderDtos); 29 | 30 | await _context.Orders.AddAsync(order, cancellationToken); 31 | return order; 32 | } 33 | 34 | public async Task> GetAllAsync(CancellationToken cancellationToken = default) 35 | { 36 | return 37 | await _context.Orders 38 | .Include(p=> p.OrderLines) 39 | .ThenInclude(p=> p.Product) 40 | .ToListAsync(cancellationToken); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Application/Features/Users/CreateUser/CreateUserCommandHander.cs: -------------------------------------------------------------------------------- 1 | using DomainDrivenDesignUdemy.Domain.Abstractions; 2 | using DomainDrivenDesignUdemy.Domain.Users; 3 | using DomainDrivenDesignUdemy.Domain.Users.Events; 4 | using MediatR; 5 | 6 | namespace DomainDrivenDesignUdemy.Application.Features.Users.CreateUser; 7 | 8 | internal sealed class CreateUserCommandHander : IRequestHandler 9 | { 10 | private readonly IUserRepository _userRepository; 11 | private readonly IUnitOfWork _unitOfWork; 12 | private readonly IMediator _mediator; 13 | 14 | public CreateUserCommandHander(IUserRepository userRepository, IUnitOfWork unitOfWork, IMediator mediator) 15 | { 16 | _userRepository = userRepository; 17 | _unitOfWork = unitOfWork; 18 | _mediator = mediator; 19 | } 20 | 21 | public async Task Handle(CreateUserCommand request, CancellationToken cancellationToken) 22 | { 23 | //iş kuralları 24 | var user = await _userRepository.CreateAsync( 25 | request.Name, 26 | request.Email, 27 | request.Password, 28 | request.Country, 29 | request.City, 30 | request.Street, 31 | request.PostalCode, 32 | request.FullAddress, 33 | cancellationToken); 34 | 35 | await _unitOfWork.SaveChangesAsync(cancellationToken); 36 | 37 | await _mediator.Publish(new UserDomainEvent(user)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Domain/Users/User.cs: -------------------------------------------------------------------------------- 1 | using DomainDrivenDesignUdemy.Domain.Abstractions; 2 | using DomainDrivenDesignUdemy.Domain.Shared; 3 | 4 | namespace DomainDrivenDesignUdemy.Domain.Users; 5 | public sealed class User : Entity 6 | { 7 | private User(Guid id) : base(id) 8 | { 9 | 10 | } 11 | private User(Guid id, Name name, Email email, Password password, Address address) : base(id) 12 | { 13 | Name = name; 14 | Email = email; 15 | Password = password; 16 | Address = address; 17 | } 18 | 19 | public Name Name { get; private set; } 20 | public Email Email { get; private set; } 21 | public Password Password { get; private set; } 22 | public Address Address { get; private set; } 23 | 24 | public static User CreateUser(string name, string email, string password, string country, string city, string street, string postalCode, string fullAddress) 25 | { 26 | //İş Kuralları 27 | User user = new( 28 | id: Guid.NewGuid(), 29 | name: new(name), 30 | email: new(email), 31 | password: new(password), 32 | address: new(country, city, street, fullAddress, postalCode)); 33 | 34 | return user; 35 | 36 | } 37 | 38 | public void ChangeName(string name) 39 | { 40 | Name = new(name); 41 | } 42 | 43 | public void ChangeAddress(string country, string city,string street, string postalCode, string fullAddress) 44 | { 45 | Address = new(country, city, street, fullAddress, postalCode); 46 | } 47 | 48 | public void ChangeEmail(string email) 49 | { 50 | Email = new(email); 51 | } 52 | 53 | public void ChangePassword(string password) 54 | { 55 | Password = new(password); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Domain-Driven Design Course - Udemy 2 | 3 | Welcome to the GitHub repository for our Udemy course on Domain-Driven Design (DDD) using Clean Architecture principles. This repository is designed as a comprehensive guide to help you understand and implement the core concepts of DDD in your projects. 4 | 5 | ## Course Overview 6 | 7 | This course provides a deep dive into Domain-Driven Design within the context of Clean Architecture, aiming to equip you with the knowledge and skills needed to design and implement maintainable and scalable software systems. Throughout the course, you will encounter practical examples and real-world scenarios that demonstrate how to apply DDD concepts effectively. 8 | 9 | ## Key Concepts Covered 10 | 11 | - **Domain Modeling**: Learn how to accurately represent your business domain through effective domain models. 12 | - **Aggregates and Entities**: Understand how to define clear boundaries and consistency rules within your domain. 13 | - **Value Objects**: Discover the importance of immutability and how value objects can enhance data integrity. 14 | - **Repositories**: Implement repository patterns to abstract data access logic and promote a cleaner architecture. 15 | - **Domain Events**: Utilize domain events to decouple components and ensure a reactive system architecture. 16 | - **Services (Application, Domain, and Infrastructure)**: Learn how to correctly segregate logic and responsibilities within your application. 17 | 18 | ## Getting Started 19 | 20 | To get started with this repository, please ensure you have the following installed: 21 | - .NET Core 3.1 or higher 22 | - An IDE such as Visual Studio or VSCode 23 | - A local or cloud-based SQL database instance 24 | 25 | Clone the repository using: 26 | ```bash 27 | git clone https://github.com/TanerSaydam/DomainDrivenDesignUdemy.git 28 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Domain/Orders/Order.cs: -------------------------------------------------------------------------------- 1 | using DomainDrivenDesignUdemy.Domain.Abstractions; 2 | using DomainDrivenDesignUdemy.Domain.Shared; 3 | 4 | namespace DomainDrivenDesignUdemy.Domain.Orders; 5 | public sealed class Order : Entity 6 | { 7 | private Order(Guid id) : base(id) 8 | { 9 | 10 | } 11 | public Order(Guid id,string orderNumber, DateTime createdDate, OrderStatusEnum status) : base(id) 12 | { 13 | OrderNumber = orderNumber; 14 | CreatedDate = createdDate; 15 | Status = status; 16 | } 17 | 18 | public string OrderNumber { get; private set; } 19 | public DateTime CreatedDate { get; private set; } 20 | public OrderStatusEnum Status { get; private set; } 21 | public ICollection OrderLines { get; private set; } = new List(); 22 | 23 | public void CreateOrder(List createOrderDtos) 24 | { 25 | foreach (var item in createOrderDtos) 26 | { 27 | if(item.Quantity < 1) 28 | { 29 | throw new ArgumentException("Sipariş adedi 1 den az olamaz!"); 30 | } 31 | 32 | //kalan iş kuralları 33 | 34 | OrderLine orderLine = new( 35 | Guid.NewGuid(), 36 | Id, 37 | item.ProductId, 38 | item.Quantity, 39 | new(item.Amount, Currency.FromCode(item.Currency))); 40 | 41 | OrderLines.Add(orderLine); 42 | } 43 | } 44 | 45 | public void RemoveOrderLine(Guid orderLineId) 46 | { 47 | var orderLine = OrderLines.FirstOrDefault(p => p.Id == orderLineId); 48 | if(orderLine is null) 49 | { 50 | throw new ArgumentException("Silmek istediğiniz sipariş kalemi bulunamadı!"); 51 | } 52 | 53 | OrderLines.Remove(orderLine); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.ConsoleApp/BenchMarkService.cs: -------------------------------------------------------------------------------- 1 | using BenchmarkDotNet.Attributes; 2 | 3 | namespace DomainDrivenDesignUdemy.ConsoleApp; 4 | public class BenchMarkService 5 | { 6 | [Benchmark(Baseline = true)] 7 | public void Equals() 8 | { 9 | int id = 1; 10 | Test1 test1 = new() { Id = id }; 11 | Test1 test2 = new() { Id = id }; 12 | Console.WriteLine(test1.Equals(test2)); 13 | } 14 | 15 | [Benchmark] 16 | public void IEquatable() 17 | { 18 | int id = 1; 19 | Test2 test1 = new() { Id = id }; 20 | Test2 test2 = new() { Id = id }; 21 | Console.WriteLine(test1.Equals(test2)); 22 | } 23 | } 24 | 25 | public class Test1 26 | { 27 | public int Id { get; set; } 28 | public override bool Equals(object? obj) 29 | { 30 | if (obj is null) 31 | { 32 | return false; 33 | } 34 | 35 | if (obj is not Test1 test1) 36 | { 37 | return false; 38 | } 39 | 40 | if (obj.GetType() != GetType()) 41 | { 42 | return false; 43 | } 44 | 45 | return test1.Id == Id; 46 | } 47 | } 48 | 49 | public class Test2 : IEquatable 50 | { 51 | public int Id { get; set; } 52 | public override bool Equals(object? obj) 53 | { 54 | if (obj is null) 55 | { 56 | return false; 57 | } 58 | 59 | if (obj is not Test2 test2) 60 | { 61 | return false; 62 | } 63 | 64 | if (obj.GetType() != GetType()) 65 | { 66 | return false; 67 | } 68 | 69 | return test2.Id == Id; 70 | } 71 | 72 | public bool Equals(Test2? other) 73 | { 74 | if (other is null) 75 | { 76 | return false; 77 | } 78 | 79 | if (other is not Test2 test2) 80 | { 81 | return false; 82 | } 83 | 84 | if (other.GetType() != GetType()) 85 | { 86 | return false; 87 | } 88 | 89 | return test2.Id == Id; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Infrastructure/Context/ApplicationDbContext.cs: -------------------------------------------------------------------------------- 1 | using DomainDrivenDesignUdemy.Domain.Abstractions; 2 | using DomainDrivenDesignUdemy.Domain.Categories; 3 | using DomainDrivenDesignUdemy.Domain.Orders; 4 | using DomainDrivenDesignUdemy.Domain.Products; 5 | using DomainDrivenDesignUdemy.Domain.Shared; 6 | using DomainDrivenDesignUdemy.Domain.Users; 7 | using Microsoft.EntityFrameworkCore; 8 | 9 | namespace DomainDrivenDesignUdemy.Infrastructure.Context; 10 | internal sealed class ApplicationDbContext : DbContext, IUnitOfWork 11 | { 12 | protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) 13 | { 14 | optionsBuilder.UseSqlServer("Data Source=DESKTOP-3BJ5GK9\\SQLEXPRESS;Initial Catalog=DDDUdemyDb;Integrated Security=True;Connect Timeout=30;Encrypt=False;Trust Server Certificate=False;Application Intent=ReadWrite;Multi Subnet Failover=False"); 15 | } 16 | 17 | public DbSet Users { get; set; } 18 | public DbSet Orders { get; set; } 19 | public DbSet Products { get; set; } 20 | public DbSet Categories { get; set; } 21 | 22 | protected override void OnModelCreating(ModelBuilder modelBuilder) 23 | { 24 | modelBuilder.Entity() 25 | .Property(p => p.Name) 26 | .HasConversion(name => name.Value, value => new(value)); 27 | 28 | modelBuilder.Entity() 29 | .Property(p => p.Email) 30 | .HasConversion(email => email.Value, value => new(value)); 31 | 32 | modelBuilder.Entity() 33 | .Property(p => p.Password) 34 | .HasConversion(password => password.Value, value => new(value)); 35 | 36 | modelBuilder.Entity() 37 | .OwnsOne(p => p.Address); 38 | 39 | modelBuilder.Entity() 40 | .Property(p => p.Name) 41 | .HasConversion(name => name.Value, value => new(value)); 42 | 43 | modelBuilder.Entity() 44 | .Property(p => p.Name) 45 | .HasConversion(name => name.Value, value => new(value)); 46 | 47 | modelBuilder.Entity() 48 | .OwnsOne(p => p.Price, priceBuilder => 49 | { 50 | priceBuilder 51 | .Property(p => p.Currency) 52 | .HasConversion(currency => currency.Code, code => Currency.FromCode(code)); 53 | 54 | priceBuilder 55 | .Property(p => p.Amount) 56 | .HasColumnType("money"); 57 | }); 58 | 59 | modelBuilder.Entity() 60 | .OwnsOne(p => p.Price, priceBuilder => 61 | { 62 | priceBuilder 63 | .Property(p => p.Currency) 64 | .HasConversion(currency => currency.Code, code => Currency.FromCode(code)); 65 | 66 | priceBuilder 67 | .Property(p => p.Amount) 68 | .HasColumnType("money"); 69 | }); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.7.34221.43 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DomainDrivenDesignUdemy.Domain", "DomainDrivenDesignUdemy.Domain\DomainDrivenDesignUdemy.Domain.csproj", "{847A8E44-B0BC-48A3-BD80-34A3DC277E46}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DomainDrivenDesignUdemy.ConsoleApp", "DomainDrivenDesignUdemy.ConsoleApp\DomainDrivenDesignUdemy.ConsoleApp.csproj", "{B2C99D92-CA23-435A-BCBA-5197BF3D8051}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DomainDrivenDesignUdemy.Application", "DomainDrivenDesignUdemy.Application\DomainDrivenDesignUdemy.Application.csproj", "{D4772EFA-7F91-4F51-BA0A-EEB96054B98C}" 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DomainDrivenDesignUdemy.Infrastructure", "DomainDrivenDesignUdemy.Infrastructure\DomainDrivenDesignUdemy.Infrastructure.csproj", "{2D43A90C-64B6-4DC4-9540-D9D584A25A99}" 13 | EndProject 14 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DomainDrivenDesignUdemy.WebApi", "DomainDrivenDesignUdemy.WebApi\DomainDrivenDesignUdemy.WebApi.csproj", "{602A42CF-99C0-40A4-9899-D75D91EAF358}" 15 | EndProject 16 | Global 17 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 18 | Debug|Any CPU = Debug|Any CPU 19 | Release|Any CPU = Release|Any CPU 20 | EndGlobalSection 21 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 22 | {847A8E44-B0BC-48A3-BD80-34A3DC277E46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {847A8E44-B0BC-48A3-BD80-34A3DC277E46}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {847A8E44-B0BC-48A3-BD80-34A3DC277E46}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {847A8E44-B0BC-48A3-BD80-34A3DC277E46}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {B2C99D92-CA23-435A-BCBA-5197BF3D8051}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {B2C99D92-CA23-435A-BCBA-5197BF3D8051}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {B2C99D92-CA23-435A-BCBA-5197BF3D8051}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {B2C99D92-CA23-435A-BCBA-5197BF3D8051}.Release|Any CPU.Build.0 = Release|Any CPU 30 | {D4772EFA-7F91-4F51-BA0A-EEB96054B98C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 31 | {D4772EFA-7F91-4F51-BA0A-EEB96054B98C}.Debug|Any CPU.Build.0 = Debug|Any CPU 32 | {D4772EFA-7F91-4F51-BA0A-EEB96054B98C}.Release|Any CPU.ActiveCfg = Release|Any CPU 33 | {D4772EFA-7F91-4F51-BA0A-EEB96054B98C}.Release|Any CPU.Build.0 = Release|Any CPU 34 | {2D43A90C-64B6-4DC4-9540-D9D584A25A99}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 35 | {2D43A90C-64B6-4DC4-9540-D9D584A25A99}.Debug|Any CPU.Build.0 = Debug|Any CPU 36 | {2D43A90C-64B6-4DC4-9540-D9D584A25A99}.Release|Any CPU.ActiveCfg = Release|Any CPU 37 | {2D43A90C-64B6-4DC4-9540-D9D584A25A99}.Release|Any CPU.Build.0 = Release|Any CPU 38 | {602A42CF-99C0-40A4-9899-D75D91EAF358}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 39 | {602A42CF-99C0-40A4-9899-D75D91EAF358}.Debug|Any CPU.Build.0 = Debug|Any CPU 40 | {602A42CF-99C0-40A4-9899-D75D91EAF358}.Release|Any CPU.ActiveCfg = Release|Any CPU 41 | {602A42CF-99C0-40A4-9899-D75D91EAF358}.Release|Any CPU.Build.0 = Release|Any CPU 42 | EndGlobalSection 43 | GlobalSection(SolutionProperties) = preSolution 44 | HideSolutionNode = FALSE 45 | EndGlobalSection 46 | GlobalSection(ExtensibilityGlobals) = postSolution 47 | SolutionGuid = {4DB24DFA-09FB-4723-B43F-D1D3E9414693} 48 | EndGlobalSection 49 | EndGlobal 50 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.ConsoleApp/Program.cs: -------------------------------------------------------------------------------- 1 | using BenchmarkDotNet.Running; 2 | using MediatR; 3 | 4 | namespace DomainDrivenDesignUdemy.ConsoleApp; 5 | 6 | internal class Program 7 | { 8 | static void Main(string[] args) 9 | { 10 | //Order order = new(); 11 | //order.CreateOrder(1, "Domates"); 12 | //order.CreateOrder(2, "Elma"); 13 | //order.CreateOrder(3, "Armut"); 14 | 15 | 16 | //DomainEventDispacther.Dispatch(order.DomainEvents); 17 | ////BenchmarkRunner.Run(); 18 | Console.ReadLine(); 19 | } 20 | } 21 | 22 | public class Order 23 | { 24 | private readonly IMediator _mediator; 25 | 26 | public Order(IMediator mediator) 27 | { 28 | _mediator = mediator; 29 | } 30 | 31 | public int Id { get; set; } 32 | public string ProductName { get; set; } 33 | public List DomainEvents { get; } = new(); 34 | public void CreateOrder(int id, string productName) 35 | { 36 | Id = id; 37 | ProductName = productName; 38 | //kayıt işlemi 39 | _mediator.Publish(new OrderCompletedEvent(id)); 40 | //DomainEvents.Add(new OrderCreatedEvent(id)); 41 | } 42 | } 43 | 44 | public class StockUpdateHandler : INotificationHandler 45 | { 46 | public Task Handle(OrderCompletedEvent notification, CancellationToken cancellationToken) 47 | { 48 | //İşlemlerimizi yapabiliriz 49 | return Task.CompletedTask; 50 | } 51 | } 52 | 53 | public class SendMailHandler : INotificationHandler 54 | { 55 | public Task Handle(OrderCompletedEvent notification, CancellationToken cancellationToken) 56 | { 57 | //Mail gönderme işlemi 58 | return Task.CompletedTask; 59 | } 60 | } 61 | 62 | public class SendSmsHandler : INotificationHandler 63 | { 64 | public Task Handle(OrderCompletedEvent notification, CancellationToken cancellationToken) 65 | { 66 | //Mail gönderme işlemi 67 | return Task.CompletedTask; 68 | } 69 | } 70 | 71 | public class OrderCompletedEvent : INotification 72 | { 73 | public int Id { get; } 74 | public OrderCompletedEvent(int id) 75 | { 76 | Id = id; 77 | } 78 | } 79 | 80 | public static class DomainEventDispacther 81 | { 82 | public static void Dispatch(List events) 83 | { 84 | foreach (var domainEvent in events) 85 | { 86 | if(domainEvent is OrderCreatedEvent orderEvent) 87 | { 88 | Console.WriteLine($"Order Event işleme başladı, Id: {orderEvent.OrderId}"); 89 | } 90 | } 91 | } 92 | } 93 | 94 | public interface IDomainEvent 95 | { 96 | 97 | } 98 | 99 | public class OrderCreatedEvent: IDomainEvent 100 | { 101 | public int OrderId { get; } 102 | public OrderCreatedEvent(int orderId) 103 | { 104 | OrderId = orderId; 105 | } 106 | } 107 | 108 | public abstract class Entity : IEquatable 109 | { 110 | public Guid Id { get; init; } 111 | public Entity(Guid id) 112 | { 113 | Id = id; 114 | } 115 | 116 | public override bool Equals(object? obj) 117 | { 118 | if (obj is null) 119 | { 120 | return false; 121 | } 122 | 123 | if (obj is not Entity entity) 124 | { 125 | return false; 126 | } 127 | 128 | if (obj.GetType() != GetType()) 129 | { 130 | return false; 131 | } 132 | 133 | return entity.Id == Id; 134 | } 135 | 136 | public override int GetHashCode() 137 | { 138 | return Id.GetHashCode(); 139 | } 140 | 141 | public bool Equals(Entity? other) 142 | { 143 | if (other is null) 144 | { 145 | return false; 146 | } 147 | 148 | if (other is not Entity entity) 149 | { 150 | return false; 151 | } 152 | 153 | if (other.GetType() != GetType()) 154 | { 155 | return false; 156 | } 157 | 158 | return entity.Id == Id; 159 | } 160 | } 161 | 162 | 163 | public class A : Entity 164 | { 165 | public A(Guid id) : base(id) 166 | { 167 | } 168 | } -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Infrastructure/Migrations/20231113032740_mg1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.EntityFrameworkCore.Migrations; 3 | 4 | #nullable disable 5 | 6 | namespace DomainDrivenDesignUdemy.Infrastructure.Migrations 7 | { 8 | /// 9 | public partial class mg1 : Migration 10 | { 11 | /// 12 | protected override void Up(MigrationBuilder migrationBuilder) 13 | { 14 | migrationBuilder.CreateTable( 15 | name: "Categories", 16 | columns: table => new 17 | { 18 | Id = table.Column(type: "uniqueidentifier", nullable: false), 19 | Name = table.Column(type: "nvarchar(max)", nullable: false) 20 | }, 21 | constraints: table => 22 | { 23 | table.PrimaryKey("PK_Categories", x => x.Id); 24 | }); 25 | 26 | migrationBuilder.CreateTable( 27 | name: "Orders", 28 | columns: table => new 29 | { 30 | Id = table.Column(type: "uniqueidentifier", nullable: false), 31 | OrderNumber = table.Column(type: "nvarchar(max)", nullable: false), 32 | CreatedDate = table.Column(type: "datetime2", nullable: false), 33 | Status = table.Column(type: "int", nullable: false) 34 | }, 35 | constraints: table => 36 | { 37 | table.PrimaryKey("PK_Orders", x => x.Id); 38 | }); 39 | 40 | migrationBuilder.CreateTable( 41 | name: "Users", 42 | columns: table => new 43 | { 44 | Id = table.Column(type: "uniqueidentifier", nullable: false), 45 | Name = table.Column(type: "nvarchar(max)", nullable: false), 46 | Email = table.Column(type: "nvarchar(max)", nullable: false), 47 | Password = table.Column(type: "nvarchar(max)", nullable: false), 48 | Address_Country = table.Column(type: "nvarchar(max)", nullable: false), 49 | Address_City = table.Column(type: "nvarchar(max)", nullable: false), 50 | Address_Street = table.Column(type: "nvarchar(max)", nullable: false), 51 | Address_FullAddress = table.Column(type: "nvarchar(max)", nullable: false), 52 | Address_PostalCode = table.Column(type: "nvarchar(max)", nullable: false) 53 | }, 54 | constraints: table => 55 | { 56 | table.PrimaryKey("PK_Users", x => x.Id); 57 | }); 58 | 59 | migrationBuilder.CreateTable( 60 | name: "Products", 61 | columns: table => new 62 | { 63 | Id = table.Column(type: "uniqueidentifier", nullable: false), 64 | Name = table.Column(type: "nvarchar(max)", nullable: false), 65 | Quantity = table.Column(type: "int", nullable: false), 66 | Price_Amount = table.Column(type: "money", nullable: false), 67 | Price_Currency = table.Column(type: "nvarchar(max)", nullable: false), 68 | CategoryId = table.Column(type: "uniqueidentifier", nullable: false) 69 | }, 70 | constraints: table => 71 | { 72 | table.PrimaryKey("PK_Products", x => x.Id); 73 | table.ForeignKey( 74 | name: "FK_Products_Categories_CategoryId", 75 | column: x => x.CategoryId, 76 | principalTable: "Categories", 77 | principalColumn: "Id", 78 | onDelete: ReferentialAction.Cascade); 79 | }); 80 | 81 | migrationBuilder.CreateTable( 82 | name: "OrderLine", 83 | columns: table => new 84 | { 85 | Id = table.Column(type: "uniqueidentifier", nullable: false), 86 | OrderId = table.Column(type: "uniqueidentifier", nullable: false), 87 | ProductId = table.Column(type: "uniqueidentifier", nullable: false), 88 | Quantity = table.Column(type: "int", nullable: false), 89 | Price_Amount = table.Column(type: "money", nullable: false), 90 | Price_Currency = table.Column(type: "nvarchar(max)", nullable: false) 91 | }, 92 | constraints: table => 93 | { 94 | table.PrimaryKey("PK_OrderLine", x => x.Id); 95 | table.ForeignKey( 96 | name: "FK_OrderLine_Orders_OrderId", 97 | column: x => x.OrderId, 98 | principalTable: "Orders", 99 | principalColumn: "Id", 100 | onDelete: ReferentialAction.Cascade); 101 | table.ForeignKey( 102 | name: "FK_OrderLine_Products_ProductId", 103 | column: x => x.ProductId, 104 | principalTable: "Products", 105 | principalColumn: "Id", 106 | onDelete: ReferentialAction.Cascade); 107 | }); 108 | 109 | migrationBuilder.CreateIndex( 110 | name: "IX_OrderLine_OrderId", 111 | table: "OrderLine", 112 | column: "OrderId"); 113 | 114 | migrationBuilder.CreateIndex( 115 | name: "IX_OrderLine_ProductId", 116 | table: "OrderLine", 117 | column: "ProductId"); 118 | 119 | migrationBuilder.CreateIndex( 120 | name: "IX_Products_CategoryId", 121 | table: "Products", 122 | column: "CategoryId"); 123 | } 124 | 125 | /// 126 | protected override void Down(MigrationBuilder migrationBuilder) 127 | { 128 | migrationBuilder.DropTable( 129 | name: "OrderLine"); 130 | 131 | migrationBuilder.DropTable( 132 | name: "Users"); 133 | 134 | migrationBuilder.DropTable( 135 | name: "Orders"); 136 | 137 | migrationBuilder.DropTable( 138 | name: "Products"); 139 | 140 | migrationBuilder.DropTable( 141 | name: "Categories"); 142 | } 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Oo]ut/ 33 | [Ll]og/ 34 | [Ll]ogs/ 35 | 36 | # Visual Studio 2015/2017 cache/options directory 37 | .vs/ 38 | # Uncomment if you have tasks that create the project's static files in wwwroot 39 | #wwwroot/ 40 | 41 | # Visual Studio 2017 auto generated files 42 | Generated\ Files/ 43 | 44 | # MSTest test Results 45 | [Tt]est[Rr]esult*/ 46 | [Bb]uild[Ll]og.* 47 | 48 | # NUnit 49 | *.VisualState.xml 50 | TestResult.xml 51 | nunit-*.xml 52 | 53 | # Build Results of an ATL Project 54 | [Dd]ebugPS/ 55 | [Rr]eleasePS/ 56 | dlldata.c 57 | 58 | # Benchmark Results 59 | BenchmarkDotNet.Artifacts/ 60 | 61 | # .NET Core 62 | project.lock.json 63 | project.fragment.lock.json 64 | artifacts/ 65 | 66 | # ASP.NET Scaffolding 67 | ScaffoldingReadMe.txt 68 | 69 | # StyleCop 70 | StyleCopReport.xml 71 | 72 | # Files built by Visual Studio 73 | *_i.c 74 | *_p.c 75 | *_h.h 76 | *.ilk 77 | *.meta 78 | *.obj 79 | *.iobj 80 | *.pch 81 | *.pdb 82 | *.ipdb 83 | *.pgc 84 | *.pgd 85 | *.rsp 86 | *.sbr 87 | *.tlb 88 | *.tli 89 | *.tlh 90 | *.tmp 91 | *.tmp_proj 92 | *_wpftmp.csproj 93 | *.log 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio LightSwitch build output 298 | **/*.HTMLClient/GeneratedArtifacts 299 | **/*.DesktopClient/GeneratedArtifacts 300 | **/*.DesktopClient/ModelManifest.xml 301 | **/*.Server/GeneratedArtifacts 302 | **/*.Server/ModelManifest.xml 303 | _Pvt_Extensions 304 | 305 | # Paket dependency manager 306 | .paket/paket.exe 307 | paket-files/ 308 | 309 | # FAKE - F# Make 310 | .fake/ 311 | 312 | # CodeRush personal settings 313 | .cr/personal 314 | 315 | # Python Tools for Visual Studio (PTVS) 316 | __pycache__/ 317 | *.pyc 318 | 319 | # Cake - Uncomment if you are using it 320 | # tools/** 321 | # !tools/packages.config 322 | 323 | # Tabs Studio 324 | *.tss 325 | 326 | # Telerik's JustMock configuration file 327 | *.jmconfig 328 | 329 | # BizTalk build output 330 | *.btp.cs 331 | *.btm.cs 332 | *.odx.cs 333 | *.xsd.cs 334 | 335 | # OpenCover UI analysis results 336 | OpenCover/ 337 | 338 | # Azure Stream Analytics local run output 339 | ASALocalRun/ 340 | 341 | # MSBuild Binary and Structured Log 342 | *.binlog 343 | 344 | # NVidia Nsight GPU debugger configuration file 345 | *.nvuser 346 | 347 | # MFractors (Xamarin productivity tool) working folder 348 | .mfractor/ 349 | 350 | # Local History for Visual Studio 351 | .localhistory/ 352 | 353 | # BeatPulse healthcheck temp database 354 | healthchecksdb 355 | 356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 357 | MigrationBackup/ 358 | 359 | # Ionide (cross platform F# VS Code tools) working folder 360 | .ionide/ 361 | 362 | # Fody - auto-generated XML schema 363 | FodyWeavers.xsd -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Infrastructure/Migrations/ApplicationDbContextModelSnapshot.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using DomainDrivenDesignUdemy.Infrastructure.Context; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.EntityFrameworkCore.Infrastructure; 6 | using Microsoft.EntityFrameworkCore.Metadata; 7 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 8 | 9 | #nullable disable 10 | 11 | namespace DomainDrivenDesignUdemy.Infrastructure.Migrations 12 | { 13 | [DbContext(typeof(ApplicationDbContext))] 14 | partial class ApplicationDbContextModelSnapshot : ModelSnapshot 15 | { 16 | protected override void BuildModel(ModelBuilder modelBuilder) 17 | { 18 | #pragma warning disable 612, 618 19 | modelBuilder 20 | .HasAnnotation("ProductVersion", "7.0.13") 21 | .HasAnnotation("Relational:MaxIdentifierLength", 128); 22 | 23 | SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); 24 | 25 | modelBuilder.Entity("DomainDrivenDesignUdemy.Domain.Categories.Category", b => 26 | { 27 | b.Property("Id") 28 | .ValueGeneratedOnAdd() 29 | .HasColumnType("uniqueidentifier"); 30 | 31 | b.Property("Name") 32 | .IsRequired() 33 | .HasColumnType("nvarchar(max)"); 34 | 35 | b.HasKey("Id"); 36 | 37 | b.ToTable("Categories"); 38 | }); 39 | 40 | modelBuilder.Entity("DomainDrivenDesignUdemy.Domain.Orders.Order", b => 41 | { 42 | b.Property("Id") 43 | .ValueGeneratedOnAdd() 44 | .HasColumnType("uniqueidentifier"); 45 | 46 | b.Property("CreatedDate") 47 | .HasColumnType("datetime2"); 48 | 49 | b.Property("OrderNumber") 50 | .IsRequired() 51 | .HasColumnType("nvarchar(max)"); 52 | 53 | b.Property("Status") 54 | .HasColumnType("int"); 55 | 56 | b.HasKey("Id"); 57 | 58 | b.ToTable("Orders"); 59 | }); 60 | 61 | modelBuilder.Entity("DomainDrivenDesignUdemy.Domain.Orders.OrderLine", b => 62 | { 63 | b.Property("Id") 64 | .ValueGeneratedOnAdd() 65 | .HasColumnType("uniqueidentifier"); 66 | 67 | b.Property("OrderId") 68 | .HasColumnType("uniqueidentifier"); 69 | 70 | b.Property("ProductId") 71 | .HasColumnType("uniqueidentifier"); 72 | 73 | b.Property("Quantity") 74 | .HasColumnType("int"); 75 | 76 | b.HasKey("Id"); 77 | 78 | b.HasIndex("OrderId"); 79 | 80 | b.HasIndex("ProductId"); 81 | 82 | b.ToTable("OrderLine"); 83 | }); 84 | 85 | modelBuilder.Entity("DomainDrivenDesignUdemy.Domain.Products.Product", b => 86 | { 87 | b.Property("Id") 88 | .ValueGeneratedOnAdd() 89 | .HasColumnType("uniqueidentifier"); 90 | 91 | b.Property("CategoryId") 92 | .HasColumnType("uniqueidentifier"); 93 | 94 | b.Property("Name") 95 | .IsRequired() 96 | .HasColumnType("nvarchar(max)"); 97 | 98 | b.Property("Quantity") 99 | .HasColumnType("int"); 100 | 101 | b.HasKey("Id"); 102 | 103 | b.HasIndex("CategoryId"); 104 | 105 | b.ToTable("Products"); 106 | }); 107 | 108 | modelBuilder.Entity("DomainDrivenDesignUdemy.Domain.Users.User", b => 109 | { 110 | b.Property("Id") 111 | .ValueGeneratedOnAdd() 112 | .HasColumnType("uniqueidentifier"); 113 | 114 | b.Property("Email") 115 | .IsRequired() 116 | .HasColumnType("nvarchar(max)"); 117 | 118 | b.Property("Name") 119 | .IsRequired() 120 | .HasColumnType("nvarchar(max)"); 121 | 122 | b.Property("Password") 123 | .IsRequired() 124 | .HasColumnType("nvarchar(max)"); 125 | 126 | b.HasKey("Id"); 127 | 128 | b.ToTable("Users"); 129 | }); 130 | 131 | modelBuilder.Entity("DomainDrivenDesignUdemy.Domain.Orders.OrderLine", b => 132 | { 133 | b.HasOne("DomainDrivenDesignUdemy.Domain.Orders.Order", null) 134 | .WithMany("OrderLines") 135 | .HasForeignKey("OrderId") 136 | .OnDelete(DeleteBehavior.Cascade) 137 | .IsRequired(); 138 | 139 | b.HasOne("DomainDrivenDesignUdemy.Domain.Products.Product", "Product") 140 | .WithMany() 141 | .HasForeignKey("ProductId") 142 | .OnDelete(DeleteBehavior.Cascade) 143 | .IsRequired(); 144 | 145 | b.OwnsOne("DomainDrivenDesignUdemy.Domain.Shared.Money", "Price", b1 => 146 | { 147 | b1.Property("OrderLineId") 148 | .HasColumnType("uniqueidentifier"); 149 | 150 | b1.Property("Amount") 151 | .HasColumnType("money"); 152 | 153 | b1.Property("Currency") 154 | .IsRequired() 155 | .HasColumnType("nvarchar(max)"); 156 | 157 | b1.HasKey("OrderLineId"); 158 | 159 | b1.ToTable("OrderLine"); 160 | 161 | b1.WithOwner() 162 | .HasForeignKey("OrderLineId"); 163 | }); 164 | 165 | b.Navigation("Price") 166 | .IsRequired(); 167 | 168 | b.Navigation("Product"); 169 | }); 170 | 171 | modelBuilder.Entity("DomainDrivenDesignUdemy.Domain.Products.Product", b => 172 | { 173 | b.HasOne("DomainDrivenDesignUdemy.Domain.Categories.Category", "Category") 174 | .WithMany("Products") 175 | .HasForeignKey("CategoryId") 176 | .OnDelete(DeleteBehavior.Cascade) 177 | .IsRequired(); 178 | 179 | b.OwnsOne("DomainDrivenDesignUdemy.Domain.Shared.Money", "Price", b1 => 180 | { 181 | b1.Property("ProductId") 182 | .HasColumnType("uniqueidentifier"); 183 | 184 | b1.Property("Amount") 185 | .HasColumnType("money"); 186 | 187 | b1.Property("Currency") 188 | .IsRequired() 189 | .HasColumnType("nvarchar(max)"); 190 | 191 | b1.HasKey("ProductId"); 192 | 193 | b1.ToTable("Products"); 194 | 195 | b1.WithOwner() 196 | .HasForeignKey("ProductId"); 197 | }); 198 | 199 | b.Navigation("Category"); 200 | 201 | b.Navigation("Price") 202 | .IsRequired(); 203 | }); 204 | 205 | modelBuilder.Entity("DomainDrivenDesignUdemy.Domain.Users.User", b => 206 | { 207 | b.OwnsOne("DomainDrivenDesignUdemy.Domain.Users.Address", "Address", b1 => 208 | { 209 | b1.Property("UserId") 210 | .HasColumnType("uniqueidentifier"); 211 | 212 | b1.Property("City") 213 | .IsRequired() 214 | .HasColumnType("nvarchar(max)"); 215 | 216 | b1.Property("Country") 217 | .IsRequired() 218 | .HasColumnType("nvarchar(max)"); 219 | 220 | b1.Property("FullAddress") 221 | .IsRequired() 222 | .HasColumnType("nvarchar(max)"); 223 | 224 | b1.Property("PostalCode") 225 | .IsRequired() 226 | .HasColumnType("nvarchar(max)"); 227 | 228 | b1.Property("Street") 229 | .IsRequired() 230 | .HasColumnType("nvarchar(max)"); 231 | 232 | b1.HasKey("UserId"); 233 | 234 | b1.ToTable("Users"); 235 | 236 | b1.WithOwner() 237 | .HasForeignKey("UserId"); 238 | }); 239 | 240 | b.Navigation("Address") 241 | .IsRequired(); 242 | }); 243 | 244 | modelBuilder.Entity("DomainDrivenDesignUdemy.Domain.Categories.Category", b => 245 | { 246 | b.Navigation("Products"); 247 | }); 248 | 249 | modelBuilder.Entity("DomainDrivenDesignUdemy.Domain.Orders.Order", b => 250 | { 251 | b.Navigation("OrderLines"); 252 | }); 253 | #pragma warning restore 612, 618 254 | } 255 | } 256 | } 257 | -------------------------------------------------------------------------------- /DomainDrivenDesignUdemy.Infrastructure/Migrations/20231113032740_mg1.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using DomainDrivenDesignUdemy.Infrastructure.Context; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.EntityFrameworkCore.Infrastructure; 6 | using Microsoft.EntityFrameworkCore.Metadata; 7 | using Microsoft.EntityFrameworkCore.Migrations; 8 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 9 | 10 | #nullable disable 11 | 12 | namespace DomainDrivenDesignUdemy.Infrastructure.Migrations 13 | { 14 | [DbContext(typeof(ApplicationDbContext))] 15 | [Migration("20231113032740_mg1")] 16 | partial class mg1 17 | { 18 | /// 19 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 20 | { 21 | #pragma warning disable 612, 618 22 | modelBuilder 23 | .HasAnnotation("ProductVersion", "7.0.13") 24 | .HasAnnotation("Relational:MaxIdentifierLength", 128); 25 | 26 | SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); 27 | 28 | modelBuilder.Entity("DomainDrivenDesignUdemy.Domain.Categories.Category", b => 29 | { 30 | b.Property("Id") 31 | .ValueGeneratedOnAdd() 32 | .HasColumnType("uniqueidentifier"); 33 | 34 | b.Property("Name") 35 | .IsRequired() 36 | .HasColumnType("nvarchar(max)"); 37 | 38 | b.HasKey("Id"); 39 | 40 | b.ToTable("Categories"); 41 | }); 42 | 43 | modelBuilder.Entity("DomainDrivenDesignUdemy.Domain.Orders.Order", b => 44 | { 45 | b.Property("Id") 46 | .ValueGeneratedOnAdd() 47 | .HasColumnType("uniqueidentifier"); 48 | 49 | b.Property("CreatedDate") 50 | .HasColumnType("datetime2"); 51 | 52 | b.Property("OrderNumber") 53 | .IsRequired() 54 | .HasColumnType("nvarchar(max)"); 55 | 56 | b.Property("Status") 57 | .HasColumnType("int"); 58 | 59 | b.HasKey("Id"); 60 | 61 | b.ToTable("Orders"); 62 | }); 63 | 64 | modelBuilder.Entity("DomainDrivenDesignUdemy.Domain.Orders.OrderLine", b => 65 | { 66 | b.Property("Id") 67 | .ValueGeneratedOnAdd() 68 | .HasColumnType("uniqueidentifier"); 69 | 70 | b.Property("OrderId") 71 | .HasColumnType("uniqueidentifier"); 72 | 73 | b.Property("ProductId") 74 | .HasColumnType("uniqueidentifier"); 75 | 76 | b.Property("Quantity") 77 | .HasColumnType("int"); 78 | 79 | b.HasKey("Id"); 80 | 81 | b.HasIndex("OrderId"); 82 | 83 | b.HasIndex("ProductId"); 84 | 85 | b.ToTable("OrderLine"); 86 | }); 87 | 88 | modelBuilder.Entity("DomainDrivenDesignUdemy.Domain.Products.Product", b => 89 | { 90 | b.Property("Id") 91 | .ValueGeneratedOnAdd() 92 | .HasColumnType("uniqueidentifier"); 93 | 94 | b.Property("CategoryId") 95 | .HasColumnType("uniqueidentifier"); 96 | 97 | b.Property("Name") 98 | .IsRequired() 99 | .HasColumnType("nvarchar(max)"); 100 | 101 | b.Property("Quantity") 102 | .HasColumnType("int"); 103 | 104 | b.HasKey("Id"); 105 | 106 | b.HasIndex("CategoryId"); 107 | 108 | b.ToTable("Products"); 109 | }); 110 | 111 | modelBuilder.Entity("DomainDrivenDesignUdemy.Domain.Users.User", b => 112 | { 113 | b.Property("Id") 114 | .ValueGeneratedOnAdd() 115 | .HasColumnType("uniqueidentifier"); 116 | 117 | b.Property("Email") 118 | .IsRequired() 119 | .HasColumnType("nvarchar(max)"); 120 | 121 | b.Property("Name") 122 | .IsRequired() 123 | .HasColumnType("nvarchar(max)"); 124 | 125 | b.Property("Password") 126 | .IsRequired() 127 | .HasColumnType("nvarchar(max)"); 128 | 129 | b.HasKey("Id"); 130 | 131 | b.ToTable("Users"); 132 | }); 133 | 134 | modelBuilder.Entity("DomainDrivenDesignUdemy.Domain.Orders.OrderLine", b => 135 | { 136 | b.HasOne("DomainDrivenDesignUdemy.Domain.Orders.Order", null) 137 | .WithMany("OrderLines") 138 | .HasForeignKey("OrderId") 139 | .OnDelete(DeleteBehavior.Cascade) 140 | .IsRequired(); 141 | 142 | b.HasOne("DomainDrivenDesignUdemy.Domain.Products.Product", "Product") 143 | .WithMany() 144 | .HasForeignKey("ProductId") 145 | .OnDelete(DeleteBehavior.Cascade) 146 | .IsRequired(); 147 | 148 | b.OwnsOne("DomainDrivenDesignUdemy.Domain.Shared.Money", "Price", b1 => 149 | { 150 | b1.Property("OrderLineId") 151 | .HasColumnType("uniqueidentifier"); 152 | 153 | b1.Property("Amount") 154 | .HasColumnType("money"); 155 | 156 | b1.Property("Currency") 157 | .IsRequired() 158 | .HasColumnType("nvarchar(max)"); 159 | 160 | b1.HasKey("OrderLineId"); 161 | 162 | b1.ToTable("OrderLine"); 163 | 164 | b1.WithOwner() 165 | .HasForeignKey("OrderLineId"); 166 | }); 167 | 168 | b.Navigation("Price") 169 | .IsRequired(); 170 | 171 | b.Navigation("Product"); 172 | }); 173 | 174 | modelBuilder.Entity("DomainDrivenDesignUdemy.Domain.Products.Product", b => 175 | { 176 | b.HasOne("DomainDrivenDesignUdemy.Domain.Categories.Category", "Category") 177 | .WithMany("Products") 178 | .HasForeignKey("CategoryId") 179 | .OnDelete(DeleteBehavior.Cascade) 180 | .IsRequired(); 181 | 182 | b.OwnsOne("DomainDrivenDesignUdemy.Domain.Shared.Money", "Price", b1 => 183 | { 184 | b1.Property("ProductId") 185 | .HasColumnType("uniqueidentifier"); 186 | 187 | b1.Property("Amount") 188 | .HasColumnType("money"); 189 | 190 | b1.Property("Currency") 191 | .IsRequired() 192 | .HasColumnType("nvarchar(max)"); 193 | 194 | b1.HasKey("ProductId"); 195 | 196 | b1.ToTable("Products"); 197 | 198 | b1.WithOwner() 199 | .HasForeignKey("ProductId"); 200 | }); 201 | 202 | b.Navigation("Category"); 203 | 204 | b.Navigation("Price") 205 | .IsRequired(); 206 | }); 207 | 208 | modelBuilder.Entity("DomainDrivenDesignUdemy.Domain.Users.User", b => 209 | { 210 | b.OwnsOne("DomainDrivenDesignUdemy.Domain.Users.Address", "Address", b1 => 211 | { 212 | b1.Property("UserId") 213 | .HasColumnType("uniqueidentifier"); 214 | 215 | b1.Property("City") 216 | .IsRequired() 217 | .HasColumnType("nvarchar(max)"); 218 | 219 | b1.Property("Country") 220 | .IsRequired() 221 | .HasColumnType("nvarchar(max)"); 222 | 223 | b1.Property("FullAddress") 224 | .IsRequired() 225 | .HasColumnType("nvarchar(max)"); 226 | 227 | b1.Property("PostalCode") 228 | .IsRequired() 229 | .HasColumnType("nvarchar(max)"); 230 | 231 | b1.Property("Street") 232 | .IsRequired() 233 | .HasColumnType("nvarchar(max)"); 234 | 235 | b1.HasKey("UserId"); 236 | 237 | b1.ToTable("Users"); 238 | 239 | b1.WithOwner() 240 | .HasForeignKey("UserId"); 241 | }); 242 | 243 | b.Navigation("Address") 244 | .IsRequired(); 245 | }); 246 | 247 | modelBuilder.Entity("DomainDrivenDesignUdemy.Domain.Categories.Category", b => 248 | { 249 | b.Navigation("Products"); 250 | }); 251 | 252 | modelBuilder.Entity("DomainDrivenDesignUdemy.Domain.Orders.Order", b => 253 | { 254 | b.Navigation("OrderLines"); 255 | }); 256 | #pragma warning restore 612, 618 257 | } 258 | } 259 | } 260 | --------------------------------------------------------------------------------