ArchUnitNET
ArchUnitNET copied to clipboard
Question: Load assemblies example
I have a question about you example for loading the assemblies.
Create a Test
private static readonly Architecture Architecture = new ArchLoader().LoadAssemblies(typeof(ExampleClass).Assembly, typeof(ForbiddenClass).Assembly) .Build();
You using a class instance to find the correct assembly to load it. This will assume that the class instance is in the correct assembly. From my point of view it could be that someone move this class and then the test isn't testing what it should.
From my point of view it would make more sense to use the System.Reflection.Assembly.Load("AssemblyName")
.
Advantages:
- If assembly is renamed but test not adapt, test will failed.
- System.IO.FileNotFoundException : Could not load file or assembly 'AssemblyName, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
- Assembly loading is not depending on the class in case this is moving to other assembly
So now my question is there any reason which I didn't saw yet to use the class instances instead of loading the assembly by using the assembly name?
I think you're right here, your approach is cleaner and should be used in the example. I believe it was there due to the fact that we had a different loading mechanism in the past, which needed the class reference. Do you care to create a PR to fix it?
@fgather I will create a PR to adapt this in the example