Registry Mirror
Skip to content

Architecture validation issues due to permanent ArchitectureCache #269

Closed

Description

@thojaw

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:

  • MyAppVariant1\
    • MyRootAssembly.dll
    • references: ReferencedAssembly.dll
  • MyAppVariant2\
    • MyRootAssembly.dll
    • references: OtherReferencedAssembly.dll

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

  • Allow to optional disable the ArchitectureCache using a flag
  • Add the ability to manually clear the ArchitectureCache (e. g. ArchitectureCache.Instance.Clear()) as a minimum
  • Open the structure of ArchLoader and ArchBuilder to be public and overridable, with virtual methods, so that one could easily build a CustomCachingArchBuilder.cs class within the own project and, for example provide a custom caching manager

Activity

  1. added 2 commits that reference this issue on Jun 10, 2024
  2. thojaw commented on Jun 10, 2024

    @thojaw
    Author

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

  3. added a commit that references this issue on Jun 15, 2024
  4. mak638 commented on Jun 15, 2024

    @mak638
    Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions