Skip to content

Commit d0d61fa

Browse files
Adding backing field collection
1 parent 178452b commit d0d61fa

6 files changed

Lines changed: 1711 additions & 1693 deletions

File tree

src/Dotnet5.GraphQL3.Store.Domain/Entities/Products/Product.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ namespace Dotnet5.GraphQL3.Store.Domain.Entities.Products
99
{
1010
public abstract class Product : Entity<Guid>, IProduct
1111
{
12-
protected Product(Guid id, string description, DateTimeOffset introduceAt, string name, string photoUrl, decimal price,
13-
ProductType productType, int rating, int stock, Option option)
12+
private readonly HashSet<Review> _reviews = new();
13+
14+
protected Product(Guid id, string description, DateTimeOffset introduceAt, string name, string photoUrl, decimal price, ProductType productType, int rating, int stock, Option option)
1415
{
1516
Id = id;
1617
Description = description;
@@ -22,11 +23,13 @@ protected Product(Guid id, string description, DateTimeOffset introduceAt, strin
2223
Rating = rating;
2324
Stock = stock;
2425
Option = option;
25-
Reviews = new List<Review>();
2626
}
2727

2828
protected Product() { }
2929

30+
public IReadOnlyCollection<Review> Reviews
31+
=> _reviews;
32+
3033
public string Description { get; }
3134
public DateTimeOffset IntroduceAt { get; }
3235
public string Name { get; }
@@ -36,7 +39,6 @@ protected Product() { }
3639
public ProductType ProductType { get; }
3740
public int Rating { get; }
3841
public int Stock { get; }
39-
public ICollection<Review> Reviews { get; }
4042

4143
public void AddReview(Review review)
4244
{
@@ -46,8 +48,8 @@ public void AddReview(Review review)
4648
return;
4749
}
4850

49-
if (Reviews.Contains(review)) return;
50-
Reviews.Add(review);
51+
if (_reviews.Contains(review)) return;
52+
_reviews.Add(review);
5153
}
5254
}
5355
}

0 commit comments

Comments
 (0)