first commit
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
param(
|
||||
[string]$ProjectRoot = (Split-Path -Parent $PSScriptRoot)
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$violations = [System.Collections.Generic.List[string]]::new()
|
||||
|
||||
function Add-Matches {
|
||||
param(
|
||||
[string]$Label,
|
||||
[string]$Pattern,
|
||||
[string]$Path
|
||||
)
|
||||
|
||||
$matches = & rg --line-number --glob '*.cs' $Pattern $Path 2>$null
|
||||
if ($LASTEXITCODE -eq 0) {
|
||||
foreach ($match in $matches) {
|
||||
$violations.Add("${Label}: ${match}")
|
||||
}
|
||||
}
|
||||
elseif ($LASTEXITCODE -ne 1) {
|
||||
throw "Architecture scan failed while checking ${Label}."
|
||||
}
|
||||
}
|
||||
|
||||
Add-Matches `
|
||||
-Label 'Service database dependency' `
|
||||
-Pattern 'AppDBContext|Microsoft\.EntityFrameworkCore|GetRequiredService<AppDBContext>' `
|
||||
-Path (Join-Path $ProjectRoot 'Services')
|
||||
|
||||
Add-Matches `
|
||||
-Label 'Controller repository dependency' `
|
||||
-Pattern 'I[A-Za-z0-9]+Repo(sitory)?\b' `
|
||||
-Path (Join-Path $ProjectRoot 'Controllers')
|
||||
|
||||
Add-Matches `
|
||||
-Label 'Repository upward dependency or commit' `
|
||||
-Pattern 'Interfaces\.Services|I[A-Za-z0-9]+Service\b|IUnitOfWork|HttpContext|SaveChangesAsync\(' `
|
||||
-Path (Join-Path $ProjectRoot 'Repos')
|
||||
|
||||
if ($violations.Count -gt 0) {
|
||||
Write-Error ("Layering violations found:`n" + ($violations -join "`n"))
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Output 'Layering check passed: Controller -> Service -> Repository -> AppDBContext.'
|
||||
Reference in New Issue
Block a user