Skip to content

Commit

Permalink
Merge branch 'refs/heads/main' into 242--explore-the-result-pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmackay committed Jul 2, 2024
2 parents fa35e17 + 263599e commit be8c4db
Show file tree
Hide file tree
Showing 19 changed files with 52 additions and 104 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish-log4brains.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
log4brains build --basePath /${GITHUB_REPOSITORY#*/}
- name: Deploy
uses: JamesIves/github-pages-deploy-action@v4.5.0
uses: JamesIves/github-pages-deploy-action@v4.6.1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: gh-pages
Expand Down
6 changes: 3 additions & 3 deletions CleanArchitecture.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<metadata>

<id>SSW.CleanArchitecture.Template</id>
<version>2024.2.22</version>
<version>2024.6.24</version>
<title>SSW Clean Architecture Template</title>
<authors>SSW</authors>
<description>SSW Clean Architecture Solution Template for .NET.</description>
Expand All @@ -13,8 +13,8 @@
<releaseNotes>
</releaseNotes>

<projectUrl>https://github.com/SSWConsulting/CleanArchitecture</projectUrl>
<repository type="git" url="https://github.com/SSWConsulting/CleanArchitecture.git" branch="main" />
<projectUrl>https://github.com/SSWConsulting/SSW.CleanArchitecture</projectUrl>
<repository type="git" url="https://github.com/SSWConsulting/SSW.CleanArchitecture.git" branch="main" />

<license type="expression">MIT</license>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
Expand Down
40 changes: 27 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

[![SSW TV | YouTube](https://img.shields.io/youtube/channel/views/UCBFgwtV9lIIhvoNh0xoQ7Pg?label=SSW%20TV%20%7C%20Views&style=social)](https://youtube.com/@SSWTV)

[![.NET](https://github.com/SSWConsulting/SSW.CleanArchitecture/actions/workflows/dotnet.yml/badge.svg)](https://github.com/SSWConsulting/SSW.CleanArchitecture/actions/workflows/dotnet.yml)
[![Build and Test](https://github.com/SSWConsulting/SSW.CleanArchitecture/actions/workflows/build-and-test.yml/badge.svg?branch=main)](https://github.com/SSWConsulting/SSW.CleanArchitecture/actions/workflows/build-and-test.yml)
[![Code Scanning](https://github.com/SSWConsulting/SSW.CleanArchitecture/actions/workflows/codeql.yml/badge.svg)](https://github.com/SSWConsulting/SSW.CleanArchitecture/actions/workflows/codeql.yml)
[![Package](https://github.com/SSWConsulting/SSW.CleanArchitecture/actions/workflows/package.yml/badge.svg)](https://github.com/SSWConsulting/SSW.CleanArchitecture/actions/workflows/package.yml)
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/dwyl/esta/issues)
Expand Down Expand Up @@ -156,24 +156,38 @@ dotnet new ssw-ca-command --name {{CommandName}} --entityName {{Entity}} --slnNa

1. Start dockerized SQL Server, create and seed the database.

Windows:
```ps
.\up.ps1
```
Windows:
```ps
.\up.ps1
```

Mac/Linux:
```bash
pwsh ./up.ps1
```
Mac/Linux:
```bash
pwsh ./up.ps1
```

2. Run the solution
2. Change directory

```bash
dotnet run
```
Windows:
```ps
cd src\WebApi\
```

Mac/Linux:
```bash
cd src/WebApi/
```

3. Run the solution

```bash
dotnet run
```

> **NOTE:** The first time you run the solution, it may take a while to download the docker images, create the DB, and seed the data.

4. Open http://localhost:5024/swagger/index.html in your browser to see it running ️🏃‍♂️

## 🚀 Publishing Template

Template will be published to NuGet.org when changes are made to `CleanArchitecture.nuspec` on the `main` branch.
Expand Down
7 changes: 4 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ services:
# If you really want to use MS SQL Server, uncomment the following line
#image: mcr.microsoft.com/mssql/server
ports:
- 1433:1433
restart: always
- 1500:1433
# restart the container unless it's been manually stopped
restart: unless-stopped
healthcheck:
test: ["CMD-SHELL", "/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P yourStrong(!)Password -Q 'SELECT 1' || exit 1"]
interval: 10s
retries: 10
start_period: 10s
timeout: 3s
timeout: 3s
15 changes: 0 additions & 15 deletions src/Domain/Common/Base/AggregateRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,5 @@ public abstract class AggregateRoot<TId> : Entity<TId>, IAggregateRoot

public void RemoveDomainEvent(DomainEvent domainEvent) => _domainEvents.Remove(domainEvent);

public void ClearDomainEvents() => _domainEvents.Clear();
}

// TODO: Delete this once TodoItems are removed
public abstract class BaseEntity<TId> : Entity<TId>
{
private readonly List<DomainEvent> _domainEvents = [];

[NotMapped]
public IReadOnlyList<DomainEvent> DomainEvents => _domainEvents.AsReadOnly();

public void AddDomainEvent(DomainEvent domainEvent) => _domainEvents.Add(domainEvent);

public void RemoveDomainEvent(DomainEvent domainEvent) => _domainEvents.Remove(domainEvent);

public void ClearDomainEvents() => _domainEvents.Clear();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace SSW.CleanArchitecture.Domain.Common.Base;

/// <summary>
/// Tracks creation and modification of an entity.
/// Tracks creation and modification of objects.
/// </summary>
public abstract class AuditableEntity : IAuditableEntity
public abstract class Auditable : IAuditable
{
public DateTimeOffset CreatedAt { get; private set; }
public string? CreatedBy { get; private set; }
Expand Down
2 changes: 1 addition & 1 deletion src/Domain/Common/Base/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/// They can be created within the domain, but not externally.
/// Enforce business rules (i.e. invariants)
/// </summary>
public abstract class Entity<TId> : AuditableEntity
public abstract class Entity<TId> : Auditable
{
public TId Id { get; set; } = default!;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace SSW.CleanArchitecture.Domain.Common.Interfaces;

public interface IAuditableEntity
public interface IAuditable
{
public DateTimeOffset CreatedAt { get; }
public string? CreatedBy { get; } // TODO: String as userId? (https://github.com/SSWConsulting/SSW.CleanArchitecture/issues/76)
Expand Down
2 changes: 1 addition & 1 deletion src/Infrastructure/Infrastructure.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
<ProjectReference Include="..\Domain\Domain.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.5" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void UpdateEntities(DbContext? context)
if (context is null)
return;

foreach (var entry in context.ChangeTracker.Entries<IAuditableEntity>())
foreach (var entry in context.ChangeTracker.Entries<IAuditable>())
if (entry.State is EntityState.Added)
{
entry.Entity.SetCreated(timeProvider.GetUtcNow(), currentUserService.UserId);
Expand Down
2 changes: 1 addition & 1 deletion src/Infrastructure/Persistence/Migrations/.editorconfig
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Treat all cs files in this folder as generated code
[*.cs]
generated_code = true
generated_code = true

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#nullable disable

namespace SSW.CleanArchitecture.Infrastructure.Migrations
namespace Infrastructure.Persistence.Migrations
{
/// <inheritdoc />
public partial class Remove_Todos : Migration
Expand Down Expand Up @@ -39,4 +39,4 @@ protected override void Down(MigrationBuilder migrationBuilder)
});
}
}
}
}
6 changes: 3 additions & 3 deletions src/WebApi/WebApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="7.0.0" />
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="8.0.2" />
<PackageReference Include="AspNetCore.HealthChecks.UI" Version="8.0.1" />
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="7.1.0" />
<PackageReference Include="AspNetCore.HealthChecks.UI.InMemory.Storage" Version="7.0.0" />
<PackageReference Include="AspNetCore.HealthChecks.UI.InMemory.Storage" Version="8.0.1" />
<PackageReference Include="NSwag.AspNetCore" Version="14.0.3" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.5" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="8.0.4" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="8.0.4" />
</ItemGroup>
Expand Down
6 changes: 1 addition & 5 deletions src/WebApi/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
"Microsoft.AspNetCore": "Warning"
}
},
// NOTE: If any of your connection strings real passwords, you should delete them and put them in the user secrets file instead.
"ConnectionStrings": {
// Local DB
//"DefaultConnection": "Server=(localdb)\\MSSQLLocalDB;Database=CleanArchitecture;Trusted_Connection=True;MultipleActiveResultSets=true;TrustServerCertificate=True"
// Docker DB
"DefaultConnection": "Server=localhost,1433;Initial Catalog=CleanArchitecture;Persist Security Info=False;User ID=sa;Password=yourStrong(!)Password;MultipleActiveResultSets=True;TrustServerCertificate=True;Connection Timeout=30;"
"DefaultConnection": "Server=localhost,1500;Initial Catalog=CleanArchitecture;Persist Security Info=False;User ID=sa;Password=yourStrong(!)Password;MultipleActiveResultSets=True;TrustServerCertificate=True;Connection Timeout=30;"
}
}
47 changes: 0 additions & 47 deletions tests/Architecture.Tests/DatabaseEntitiesTest.cs

This file was deleted.

1 change: 0 additions & 1 deletion tests/Architecture.Tests/DomainModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public void DomainModel_ShouldInheritsBaseClasses()
.Should()
.Inherit(typeof(AggregateRoot<>))
.Or().Inherit(typeof(Entity<>))
.Or().Inherit(typeof(BaseEntity<>))
.Or().Inherit(typeof(DomainEvent))
.Or().ImplementInterface(typeof(IValueObject));

Expand Down
2 changes: 1 addition & 1 deletion tests/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<PackageVersion Include="Respawn" Version="6.2.1" />
<PackageVersion Include="Testcontainers" Version="3.8.0" />
<PackageVersion Include="Testcontainers.SqlEdge" Version="3.8.0" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.3" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.6" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
<PackageVersion Include="Meziantou.Extensions.Logging.Xunit" Version="1.0.7" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion tools/Database/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
}
},
"ConnectionStrings": {
"DefaultConnection": "Server=localhost,1433;Initial Catalog=CleanArchitecture;Persist Security Info=False;User ID=sa;Password=yourStrong(!)Password;MultipleActiveResultSets=True;TrustServerCertificate=True;Connection Timeout=30;"
"DefaultConnection": "Server=localhost,1500;Initial Catalog=CleanArchitecture;Persist Security Info=False;User ID=sa;Password=yourStrong(!)Password;MultipleActiveResultSets=True;TrustServerCertificate=True;Connection Timeout=30;"
}
}

0 comments on commit be8c4db

Please sign in to comment.