February 17 2026
using MyApp.Infrastructure;
dotnet add package NetArchTest.Rules
using NetArchTest.Rules; using Xunit; public class ArchitectureTests { [Fact] public void Domain_Should_Not_Depend_On_Infrastructure() { var result = Types .InAssembly(typeof(DomainMarker).Assembly) .ShouldNot() .HaveDependencyOn("MyApp.Infrastructure") .GetResult(); Assert.True(result.IsSuccessful); } }
Types.InAssembly(...) - Loads all types from the Domain assembly..ShouldNot().HaveDependencyOn(...) - Defines the architectural rule..GetResult() - Executes the rule validation.Assert.True(result.IsSuccessful) - Fails the test if any violation is found.
[Fact] public void Application_Should_Not_Depend_On_API() { var result = Types .InAssembly(typeof(ApplicationMarker).Assembly) .ShouldNot() .HaveDependencyOn("MyApp.API") .GetResult(); Assert.True(result.IsSuccessful); }
[Fact] public void Services_Should_End_With_Service() { var result = Types .InAssembly(typeof(ApplicationMarker).Assembly) .That() .AreClasses() .And() .HaveNameEndingWith("Service") .Should() .BePublic() .GetResult(); Assert.True(result.IsSuccessful); }
1. Design Patterns that Deliver
This isn’t just another design patterns book. Dive into real-world examples and practical solutions to real problems in real applications.Check out it here.
Go-to resource for understanding the core concepts of design patterns without the overwhelming complexity. In this concise and affordable ebook, I've distilled the essence of design patterns into an easy-to-digest format. It is a Beginner level. Check out it here.
Every Monday morning, I share 1 actionable tip on C#, .NET & Arcitecture topic, that you can use right away.
Join 18,000+ subscribers to improve your .NET Knowledge.
Subscribe to the TheCodeMan.net and be among the 18,000+ subscribers gaining practical tips and resources to enhance your .NET expertise.