Skip to content

Allow disabling architecture and rule evaluation cache#459

Merged
alexanderlinne merged 15 commits intomainfrom
allow-disabling-architecture-and-rule-evaluation-cache
Mar 27, 2026
Merged

Allow disabling architecture and rule evaluation cache#459
alexanderlinne merged 15 commits intomainfrom
allow-disabling-architecture-and-rule-evaluation-cache

Conversation

@alexanderlinne
Copy link
Copy Markdown
Collaborator

No description provided.

- Convert DotNetCoreAssemblyResolver.AssemblyPath from public field to
  auto-property for better encapsulation
- Make FilterResult static fields readonly to prevent mutation
- Optimize MethodReference.BuildFullName with early return and
  StringBuilder instead of string concatenation via Aggregate

Signed-off-by: Alexander Linne <alexander.linne@tngtech.com>
Replace List<AssemblyNameReference> with HashSet<string> keyed by
FullName for tracking processed assemblies. The previous approach
used List.Contains with reference equality on AssemblyNameReference
objects, which could fail to detect duplicates when different
reference instances point to the same assembly.

Signed-off-by: Alexander Linne <alexander.linne@tngtech.com>
The RegexUtils.MatchNamespaces helper simply delegates to
string.StartsWith. Inline the check directly in ArchBuilder to
remove an unnecessary indirection. The remaining RegexUtils methods
(MatchGetPropertyName, MatchSetPropertyName) are still in use.

Signed-off-by: Alexander Linne <alexander.linne@tngtech.com>
Function pointer types are synthetic types created during dependency
resolution, not types directly loaded from assemblies. Setting
isStub=true ensures they are correctly classified as referenced
types rather than primary architecture types.

Signed-off-by: Alexander Linne <alexander.linne@tngtech.com>
The class creates and caches IType, MethodMember, FieldMember,
Assembly, and Namespace instances — far more than a type factory.
DomainResolver better reflects its primary role: resolving
Mono.Cecil references into cached domain objects.

This is a pure mechanical rename with no structural or behavioral
changes.

Signed-off-by: Alexander Linne <alexander.linne@tngtech.com>
…ls into DomainResolver

Signed-off-by: Alexander Linne <alexander.linne@tngtech.com>
Signed-off-by: Alexander Linne <alexander.linne@tngtech.com>
…ass ScanMethodBody

Signed-off-by: Alexander Linne <alexander.linne@tngtech.com>
…istry

Replace ILoadTask interface and LoadTaskRegistry with static Execute methods
on each load task class. Move type processing orchestration from DomainResolver
into ArchBuilder.ProcessTypes() with explicit phased execution. Remove
RegexUtils (property matching now uses dictionary lookup in AddMethodDependencies).
Remove LoadBaseTask/LoadNonBaseTasks from DomainResolver since type processing
is now driven externally by ArchBuilder. Remove RegexUtils tests (only
BackingFieldExamples test fixture class retained).

Signed-off-by: Alexander Linne <alexander.linne@tngtech.com>
Replace immediate module loading with a deferred instruction pattern.
Introduce LoadInstruction hierarchy (FileLoadInstruction,
DirectoryLoadInstruction) to accumulate load specifications. Create
resolver and builder locally in Build() with try/finally for proper
disposal. Make LoadModule and AddReferencedAssembliesRecursively static,
removing instance field dependencies on _archBuilder and _assemblyResolver.

Signed-off-by: Alexander Linne <alexander.linne@tngtech.com>
Replace separate ObjectProviderCache class with a ConcurrentDictionary
field directly in Architecture. Inline the cache lookup logic into
GetOrCreateObjects<T>. Delete ObjectProviderCache.cs.

Signed-off-by: Alexander Linne <alexander.linne@tngtech.com>
Signed-off-by: Alexander Linne <alexander.linne@tngtech.com>
…ching

Signed-off-by: Alexander Linne <alexander.linne@tngtech.com>
Signed-off-by: Alexander Linne <alexander.linne@tngtech.com>
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 27, 2026

Codecov Report

❌ Patch coverage is 97.76000% with 28 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.26%. Comparing base (b25c4f9) to head (d54bc8e).

Files with missing lines Patch % Lines
ArchUnitNET/Loader/TypeProcessor.cs 97.68% 11 Missing and 6 partials ⚠️
ArchUnitNET/Loader/MonoCecilMemberExtensions.cs 95.53% 2 Missing and 3 partials ⚠️
ArchUnitNET/Loader/ArchLoader.cs 97.12% 4 Missing ⚠️
ArchUnitNET/Loader/DomainResolver.cs 97.87% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #459      +/-   ##
==========================================
+ Coverage   77.16%   77.26%   +0.09%     
==========================================
  Files         275      259      -16     
  Lines       14381    14311      -70     
  Branches     1336     1353      +17     
==========================================
- Hits        11097    11057      -40     
+ Misses       2866     2845      -21     
+ Partials      418      409       -9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces explicit switches to disable both the global Architecture cache and the per-architecture rule evaluation cache, and refactors the loader pipeline to support those options cleanly.

Changes:

  • Add ArchLoader.WithoutRuleEvaluationCache() and ArchLoader.WithoutArchitectureCache() and thread those options through ArchBuilder/ArchitectureCacheKey/Architecture.
  • Replace the old loader “load task” infrastructure with a phased TypeProcessor + DomainResolver approach.
  • Update docs and tests to cover the new cache behavior and ensure deterministic test architectures.

Reviewed changes

Copilot reviewed 35 out of 35 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
documentation/docs/guide.md Document the two cache layers and how to disable them via ArchLoader.
ArchUnitNETTests/StaticTestArchitectures.cs Build most test architectures with caching disabled/bypassed for isolation.
ArchUnitNETTests/Loader/RegexUtilsTests.cs Remove obsolete RegexUtils tests; keep BackingFieldExamples fixture type.
ArchUnitNETTests/Loader/ArchLoaderTests.cs Add tests asserting default caching vs disabled caching behavior.
ArchUnitNETTests/Domain/Extensions/TypeExtensionTests.cs Update fixture type reference after removing RegexUtilsTest.
ArchUnitNETTests/Domain/ArchitectureCacheKeyTests.cs Add equality/hash tests for rule-evaluation-cache flag in the cache key.
ArchUnitNET/Loader/TypeProcessor.cs New phased type-processing pipeline (members/deps/attrs/backrefs/namespaces).
ArchUnitNET/Loader/RegistryUtils.cs Deleted (no longer needed after resolver refactor).
ArchUnitNET/Loader/RegexUtils.cs Deleted (old property accessor matching approach removed).
ArchUnitNET/Loader/NamespaceRegistry.cs Deleted (namespace caching moved into DomainResolver).
ArchUnitNET/Loader/MonoCecilMemberExtensions.cs Optimize full-name building and consolidate method body scanning.
ArchUnitNET/Loader/MonoCecilAttributeExtensions.cs Switch from TypeFactory to DomainResolver for type resolution.
ArchUnitNET/Loader/LoadTasks/ILoadTask.cs Deleted (load-task system removed).
ArchUnitNET/Loader/LoadTasks/* Deleted (replaced by TypeProcessor phases).
ArchUnitNET/Loader/LoadTaskRegistry.cs Deleted (load-task system removed).
ArchUnitNET/Loader/FilterResult.cs Make static instances readonly.
ArchUnitNET/Loader/DotNetCoreAssemblyResolver.cs Change AssemblyPath to a property.
ArchUnitNET/Loader/DomainResolver.cs Rename/refactor from TypeFactory; centralize caches for assemblies/namespaces/types/members.
ArchUnitNET/Loader/AssemblyRegistry.cs Deleted (assembly caching moved into DomainResolver).
ArchUnitNET/Loader/ArchLoader.cs Add cache toggles + defer instruction processing until Build().
ArchUnitNET/Loader/ArchBuilder.cs Support skipping caches; drive the new phased processing and new cache-key behavior.
ArchUnitNET/Domain/ObjectProviderCache.cs Deleted (logic moved into Architecture with opt-out flag).
ArchUnitNET/Domain/ArchitectureCacheKey.cs Include “rule evaluation cache disabled” flag in equality/hash.
ArchUnitNET/Domain/ArchitectureCache.cs Add documentation/comments; no functional change beyond API usage.
ArchUnitNET/Domain/Architecture.cs Implement rule evaluation cache internally and allow disabling it.
Comments suppressed due to low confidence (1)

ArchUnitNET/Loader/DomainResolver.cs:327

  • GetOrCreateTypeInstanceFromTypeDefinition calls GetOrCreateAssembly(assemblyFullName, assemblyFullName, ...), which can create Assembly objects whose Name is the full display name (with version/culture/etc.) instead of the simple assembly name. Use typeDefinition.Module.Assembly.Name.Name (or equivalent) for the assemblyName parameter so Assembly.Name stays consistent.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: Alexander Linne <alexander.linne@tngtech.com>
@alexanderlinne alexanderlinne merged commit f630718 into main Mar 27, 2026
9 checks passed
@alexanderlinne alexanderlinne deleted the allow-disabling-architecture-and-rule-evaluation-cache branch March 27, 2026 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants