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
Problem overview
The internal class
ArchBuilder
utilizes theArchitectureCache.Instance
which is a singleton. So even if you create a newArchLoader
instance, it will always reuse theArchitectureCache.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 referencesReferencedAssembly
. 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
ArchitectureCache
using a flagArchitectureCache
(e. g.ArchitectureCache.Instance.Clear()
) as a minimumArchLoader
andArchBuilder
to be public and overridable, with virtual methods, so that one could easily build aCustomCachingArchBuilder.cs
class within the own project and, for example provide a custom caching manager