Skip to content

Commit 7f3d917

Browse files
Merge pull request #156 from AntonioFalcao/feature/code-smells
Backing field collections
2 parents c9ca840 + d02330d commit 7f3d917

16 files changed

Lines changed: 1757 additions & 1764 deletions

File tree

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
32
<ItemGroup>
4-
<PackageReference Include="FluentValidation" Version="$(FluentValidation_Version)" />
5-
<PackageReference Include="GraphQL" Version="$(GraphQL_Version)" />
6-
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="$(Microsoft_DependencyInjection_Version)" />
7-
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="3.1.6" />
3+
<PackageReference Include="FluentValidation" Version="$(FluentValidation_Version)"/>
4+
<PackageReference Include="GraphQL" Version="$(GraphQL_Version)"/>
5+
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="$(Microsoft_DependencyInjection_Version)"/>
6+
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="3.1.6"/>
87
</ItemGroup>
9-
108
</Project>
Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
32
<ItemGroup>
4-
<PackageReference Include="FluentValidation" Version="$(FluentValidation_Version)" />
5-
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="$(Microsoft_DependencyInjection_Version)" />
6-
<PackageReference Include="Scrutor" Version="$(Scrutor_Version)" />
3+
<PackageReference Include="FluentValidation" Version="$(FluentValidation_Version)"/>
4+
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="$(Microsoft_DependencyInjection_Version)"/>
5+
<PackageReference Include="Scrutor" Version="$(Scrutor_Version)"/>
76
</ItemGroup>
8-
97
<ItemGroup>
10-
<ProjectReference Include="..\Dotnet5.GraphQL3.CrossCutting\Dotnet5.GraphQL3.CrossCutting.csproj" />
8+
<ProjectReference Include="..\Dotnet5.GraphQL3.CrossCutting\Dotnet5.GraphQL3.CrossCutting.csproj"/>
119
</ItemGroup>
12-
1310
</Project>
Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
32
<ItemGroup>
4-
<PackageReference Include="AutoMapper" Version="$(AutoMapper_Version)" />
5-
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="$(Microsoft_EntityFrameworkCore_Version)" />
6-
<PackageReference Include="Scrutor" Version="$(Scrutor_Version)" />
3+
<PackageReference Include="AutoMapper" Version="$(AutoMapper_Version)"/>
4+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="$(Microsoft_EntityFrameworkCore_Version)"/>
5+
<PackageReference Include="Scrutor" Version="$(Scrutor_Version)"/>
76
</ItemGroup>
8-
97
<ItemGroup>
10-
<ProjectReference Include="..\Dotnet5.GraphQL3.Store.Domain\Dotnet5.GraphQL3.Store.Domain.csproj" />
8+
<ProjectReference Include="..\Dotnet5.GraphQL3.Store.Domain\Dotnet5.GraphQL3.Store.Domain.csproj"/>
119
</ItemGroup>
12-
1310
</Project>

src/Dotnet5.GraphQL3.Services.Abstractions/Dotnet5.GraphQL3.Services.Abstractions.csproj

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
32
<ItemGroup>
4-
<PackageReference Include="AutoMapper" Version="$(AutoMapper_Version)" />
5-
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="$(AutoMapper_DependencyInjection_Version)" />
6-
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="$(Microsoft_EntityFrameworkCore_Version)" />
7-
<PackageReference Include="Scrutor" Version="$(Scrutor_Version)" />
3+
<PackageReference Include="AutoMapper" Version="$(AutoMapper_Version)"/>
4+
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="$(AutoMapper_DependencyInjection_Version)"/>
5+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="$(Microsoft_EntityFrameworkCore_Version)"/>
6+
<PackageReference Include="Scrutor" Version="$(Scrutor_Version)"/>
87
</ItemGroup>
9-
108
<ItemGroup>
11-
<ProjectReference Include="..\Dotnet5.GraphQL3.CrossCutting\Dotnet5.GraphQL3.CrossCutting.csproj" />
12-
<ProjectReference Include="..\Dotnet5.GraphQL3.Repositories.Abstractions\Dotnet5.GraphQL3.Repositories.Abstractions.csproj" />
13-
<ProjectReference Include="..\Dotnet5.GraphQL3.Store.Domain\Dotnet5.GraphQL3.Store.Domain.csproj" />
9+
<ProjectReference Include="..\Dotnet5.GraphQL3.CrossCutting\Dotnet5.GraphQL3.CrossCutting.csproj"/>
10+
<ProjectReference Include="..\Dotnet5.GraphQL3.Repositories.Abstractions\Dotnet5.GraphQL3.Repositories.Abstractions.csproj"/>
11+
<ProjectReference Include="..\Dotnet5.GraphQL3.Store.Domain\Dotnet5.GraphQL3.Store.Domain.csproj"/>
1412
</ItemGroup>
1513

1614
<ItemGroup>
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
32
<ItemGroup>
4-
<PackageReference Include="FluentValidation" Version="$(FluentValidation_Version)" />
3+
<PackageReference Include="FluentValidation" Version="$(FluentValidation_Version)"/>
4+
</ItemGroup>
5+
<ItemGroup>
6+
<ProjectReference Include="..\Dotnet5.GraphQL3.Domain.Abstractions\Dotnet5.GraphQL3.Domain.Abstractions.csproj"/>
57
</ItemGroup>
6-
78
<ItemGroup>
89
<EmbeddedResource Update="Resource.resx">
910
<Generator>ResXFileCodeGenerator</Generator>
1011
<LastGenOutput>Resource.Designer.cs</LastGenOutput>
1112
</EmbeddedResource>
1213
</ItemGroup>
13-
1414
<ItemGroup>
1515
<Compile Update="Resource.Designer.cs">
1616
<DesignTime>True</DesignTime>
1717
<AutoGen>True</AutoGen>
1818
<DependentUpon>DomainResource.resx</DependentUpon>
1919
</Compile>
2020
</ItemGroup>
21-
22-
<ItemGroup>
23-
<ProjectReference Include="..\Dotnet5.GraphQL3.Domain.Abstractions\Dotnet5.GraphQL3.Domain.Abstractions.csproj" />
24-
</ItemGroup>
25-
2621
</Project>

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
}

src/Dotnet5.GraphQL3.Store.Repositories/Contexts/StoreDbContext.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ namespace Dotnet5.GraphQL3.Store.Repositories.Contexts
77
{
88
public class StoreDbContext : DbContext
99
{
10+
private const string SqlLatin1GeneralCp1CsAs = "SQL_Latin1_General_CP1_CS_AS";
11+
1012
public StoreDbContext(DbContextOptions options)
1113
: base(options) { }
1214

@@ -16,7 +18,7 @@ public StoreDbContext(DbContextOptions options)
1618

1719
protected override void OnModelCreating(ModelBuilder modelBuilder)
1820
{
19-
modelBuilder.UseCollation("SQL_Latin1_General_CP1_CS_AS");
21+
modelBuilder.UseCollation(SqlLatin1GeneralCp1CsAs);
2022
modelBuilder.ApplyConfigurationsFromAssembly(typeof(StoreDbContext).Assembly);
2123
modelBuilder.Seed();
2224
base.OnModelCreating(modelBuilder);
Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
32
<ItemGroup>
4-
<PackageReference Include="Bogus" Version="33.0.2" />
5-
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="$(Microsoft_EntityFrameworkCore_Version)" />
6-
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="$(Microsoft_EntityFrameworkCore_Version)" />
7-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="$(Microsoft_EntityFrameworkCore_Version)" />
3+
<PackageReference Include="Bogus" Version="33.0.2"/>
4+
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="$(Microsoft_EntityFrameworkCore_Version)"/>
5+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="$(Microsoft_EntityFrameworkCore_Version)"/>
6+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="$(Microsoft_EntityFrameworkCore_Version)"/>
87
</ItemGroup>
9-
108
<ItemGroup>
11-
<ProjectReference Include="..\Dotnet5.GraphQL3.Repositories.Abstractions\Dotnet5.GraphQL3.Repositories.Abstractions.csproj" />
9+
<ProjectReference Include="..\Dotnet5.GraphQL3.Repositories.Abstractions\Dotnet5.GraphQL3.Repositories.Abstractions.csproj"/>
1210
</ItemGroup>
13-
1411
</Project>

0 commit comments

Comments
 (0)