TNG / ArchUnitNET

A C# architecture test library to specify and assert architecture rules in C# for automated testing.
Apache License 2.0
826 stars 55 forks source link

Architecture validation issues due to permanent ArchitectureCache #269

Closed thojaw closed 2 weeks ago

thojaw commented 3 weeks ago

Problem overview

The internal class ArchBuilder utilizes the ArchitectureCache.Instance which is a singleton. So even if you create a new ArchLoader instance, it will always reuse the ArchitectureCache.Instance. This can be a benefit for performance, but it's an issue when we want to analyze several folders which can contain the same assemblies (by name) but they have different references.

Assume the following Folder Structure:

Once you analyze "MyAppVariant1", the cache will remember that MyRootAssembly only references ReferencedAssembly. When you then build the architecture for "MyAppVariant2", the reference change is not being detected.

Please understand that instances of ArchLoader are not necessarily used within short living applications. They could be created from a long running service application for example, which can re-run the same checks in a iterative way. The assembiles being imported might have the same name, but they're not the same.

Potential solutions I can think of

thojaw commented 3 weeks ago

Implementation in #270 only aims to "Add the ability to manually clear the ArchitectureCache"

mak638 commented 2 weeks ago

Hi @thojaw. Thank you for your contribution. It will be added in the next version of ArchUnitNET.