This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IEntity<TKey> | |
{ | |
TKey Id { get; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Order : AggregateRoot | |
{ | |
public ICollection<OrderItem> Items { get; set; } | |
public Address Address { get; set; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class AggregateRoot{ | |
private readonly List<INotification> _domainEvents = new List<INotification>(); | |
public IReadOnlyCollection<INotification> DomainEvents => _domainEvents.AsReadOnly(); | |
public void AddDomainEvent(INotification eventItem) | |
{ | |
_domainEvents.Add(eventItem); | |
} | |
public void RemoveDomainEvent(INotification eventItem) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public record class Address(string Street, string ZipCode, string City); | |
/* | |
EQUALS: | |
public class Adress{ | |
public string Street { get; init; } | |
public string ZipCode { get; init; } | |
public string City { get; init; } | |
public Address(string street, string zipcode, string city){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AppDbContext : DbContext | |
{ | |
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) | |
{ | |
} | |
protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder) | |
{ | |
configurationBuilder.Properties<Address>().HaveConversion<AddressConverter>(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AddressConverter : ValueConverter<Address, string> | |
{ | |
public AddressConverter() | |
: base( | |
v => JsonSerializer.Serialize(v, (JsonSerializerOptions)null), | |
v => JsonSerializer.Deserialize<Address>(v, (JsonSerializerOptions)null)) | |
{ | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
modelBuilder.Entity<Person>() | |
.Property(e => e.Address) | |
.HasConversion( | |
v => JsonSerializer.Serialize(v, (JsonSerializerOptions)null), | |
v => JsonSerializer.Deserialize<Address>(v, (JsonSerializerOptions)null)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
b.OwnsMany(x => x.Addresses, sb => | |
{ | |
sb.Property(x => x.City) | |
.HasMaxLength(255) | |
.HasDefaultValue(string.Empty); | |
sb.Property(x => x.Street) | |
.HasMaxLength(255) | |
.HasDefaultValue(string.Empty); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AppDbContext : DbContext | |
{ | |
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) | |
{ | |
} | |
protected override void OnModelCreating(ModelBuilder modelBuilder) | |
{ | |
modelBuilder.Entity<Person>(b => | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Person | |
{ | |
public Guid Id { get; set; } | |
public string Name { get; set; } | |
public string LastName { get; set; } | |
public Address Address { get; set; } | |
} | |
public record class Address(string City, string Street, string ZipCode); |
NewerOlder