iTernity.archlint 0.1.0

The package provides static code analysis functions to verify architectural requirements like component structures, layers or dependency rules. At the moment the package is limited to a specific architecture of two concentric layers inspired by the "Clean Architecture" described by Bob Martin. But you can add your own architectural style by implementing the IArchStyle interface.

Install-Package iTernity.archlint -Version 0.1.0
dotnet add package iTernity.archlint --version 0.1.0
<PackageReference Include="iTernity.archlint" Version="0.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add iTernity.archlint --version 0.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

The archlint project provides static code analysis (SCA) to verify certain architectural conditions
in your Visual Studio .NET solution.
Especially component structures, layers and dependency rules between them.

When used continuously (e.g. as architectural tests inside your CI) archlint can help to prevent
so called "architectural erosion" in your project, which is the gap between the planned and
the actual architecture of your software system.

How can I use it?

See how simple it is to automatically verify your architecture with a single Assertion as part of a unit test.

// 1. Choose your architectural style
var archStyle = new CleanArchLight("Petshop");

// 2. Identify and parse all components and dependencies in your solution (according to the given [definition](#Defintion: Components and Dependencies)).
var petshopSolution = Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.Create().OpenSolutionAsync("path/To/Petshop/Solution.sln").Result;
var dependencies = new DependencyCollector(archStyle).Collect(petshopSolution);

// 3. Check for invalid component dependencies (according to your [architectural style](#Architectural styles)).
var checkedDependencies = DependencyCheck
        .WithDependencies(dependencies)
        .WithRule(archStyle)
        .Result();

// 4. Assert that all dependencies are allowed
Assert.IsTrue(checkedDependencies.AllDependenciesAllowed, "There are invalid dependencies in your code!");

Here's another example with some more usefull features using pretty printing and the iTernity.plantuml package.

// 1. Choose your architectural style
var archStyle = new CleanArchLight("Petshop");

// 2. Identify and parse all components and dependencies in your solution (according to the given [definition](#Defintion: Components and Dependencies)).
var petshopSolution = Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.Create().OpenSolutionAsync("path/To/Petshop/Solution.sln").Result;
var dependencies = new DependencyCollector(archStyle).Collect(petshopSolution);

// 3. Check for invalid component dependencies (according to your [architectural style](#Architectural styles)).
var checkedDependencies = DependencyCheck
        .WithDependencies(dependencies)
        .WithRule(archStyle)
        .Result();

// 4. Use a StringWriter to create a message for the upcoming Assert statement, where only the invalid dependencies are printed.
var msg = new System.IO.StringWriter();
DependencyCheckResultWriter
    .WithResult(checkedDependencies)
    .WithWriter(msg)
    .OnlyInvalidDependencies()
    .Write();

// 5. Use iTernity.plantuml nuget package to attach a PlantUML link to your error message to visualize all components and dependencies.
var plantUmlCode = new System.IO.StringWriter();
PlantUMLWriter
    .WithRule(archStyle)
    .WithWriter(plantUmlCode)
    //.OnlyInvalidDependencies() // Use this, if you only want to display the invalid depedencies.
    .ExcludeLayerDependencies()
    .Write(dependencies);
msgWriter.WriteLine(Iternity.PlantUML.PlantUMLUrl.UML(plantUmlCode.ToString()));

// 6. Assert that all dependencies are allowed
Assert.IsTrue(checkedDependencies.AllDependenciesAllowed, msgWriter.ToString());

The archlint project provides static code analysis (SCA) to verify certain architectural conditions
in your Visual Studio .NET solution.
Especially component structures, layers and dependency rules between them.

When used continuously (e.g. as architectural tests inside your CI) archlint can help to prevent
so called "architectural erosion" in your project, which is the gap between the planned and
the actual architecture of your software system.

How can I use it?

See how simple it is to automatically verify your architecture with a single Assertion as part of a unit test.

// 1. Choose your architectural style
var archStyle = new CleanArchLight("Petshop");

// 2. Identify and parse all components and dependencies in your solution (according to the given [definition](#Defintion: Components and Dependencies)).
var petshopSolution = Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.Create().OpenSolutionAsync("path/To/Petshop/Solution.sln").Result;
var dependencies = new DependencyCollector(archStyle).Collect(petshopSolution);

// 3. Check for invalid component dependencies (according to your [architectural style](#Architectural styles)).
var checkedDependencies = DependencyCheck
        .WithDependencies(dependencies)
        .WithRule(archStyle)
        .Result();

// 4. Assert that all dependencies are allowed
Assert.IsTrue(checkedDependencies.AllDependenciesAllowed, "There are invalid dependencies in your code!");

Here's another example with some more usefull features using pretty printing and the iTernity.plantuml package.

// 1. Choose your architectural style
var archStyle = new CleanArchLight("Petshop");

// 2. Identify and parse all components and dependencies in your solution (according to the given [definition](#Defintion: Components and Dependencies)).
var petshopSolution = Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.Create().OpenSolutionAsync("path/To/Petshop/Solution.sln").Result;
var dependencies = new DependencyCollector(archStyle).Collect(petshopSolution);

// 3. Check for invalid component dependencies (according to your [architectural style](#Architectural styles)).
var checkedDependencies = DependencyCheck
        .WithDependencies(dependencies)
        .WithRule(archStyle)
        .Result();

// 4. Use a StringWriter to create a message for the upcoming Assert statement, where only the invalid dependencies are printed.
var msg = new System.IO.StringWriter();
DependencyCheckResultWriter
    .WithResult(checkedDependencies)
    .WithWriter(msg)
    .OnlyInvalidDependencies()
    .Write();

// 5. Use iTernity.plantuml nuget package to attach a PlantUML link to your error message to visualize all components and dependencies.
var plantUmlCode = new System.IO.StringWriter();
PlantUMLWriter
    .WithRule(archStyle)
    .WithWriter(plantUmlCode)
    //.OnlyInvalidDependencies() // Use this, if you only want to display the invalid depedencies.
    .ExcludeLayerDependencies()
    .Write(dependencies);
msgWriter.WriteLine(Iternity.PlantUML.PlantUMLUrl.UML(plantUmlCode.ToString()));

// 6. Assert that all dependencies are allowed
Assert.IsTrue(checkedDependencies.AllDependenciesAllowed, msgWriter.ToString());

Version History

Version Downloads Last updated
0.1.0 110 11/28/2018