Skip to content

API Reference

This appendix is a reference organized so you can quickly look up the entire Functorium ArchitectureRules API at a glance. Use it to quickly check method usage or parameters during tutorial learning.

Inherits TypeValidator<Class, ClassValidator> and verifies class-level architecture rules.

MethodDescription
RequirePublic()Must be a public class
RequireInternal()Must be an internal class
MethodDescription
RequireSealed()Must be a sealed class
RequireNotSealed()Must not be sealed
RequireStatic()Must be a static class
RequireNotStatic()Must not be static
RequireAbstract()Must be an abstract class
RequireNotAbstract()Must not be abstract
MethodDescription
RequireRecord()Must be a record type
RequireNotRecord()Must not be a record
MethodDescription
RequireAttribute(string attributeName)Must have the specified attribute
MethodDescription
RequireInherits(Type baseType)Must inherit a specific base class
RequireImplements(Type interfaceType)Must implement a specific interface
RequireImplementsGenericInterface(string name)Must implement a generic interface
MethodDescription
RequirePrivateAnyParameterlessConstructor()Must have a private parameterless constructor
RequireAllPrivateConstructors()All constructors must be private
MethodDescription
RequireProperty(string propertyName)A specific property must exist
RequireNoPublicSetters()Must have no public setters
RequireNoInstanceFields()Must have no instance fields
RequireOnlyPrimitiveProperties(params string[])Only primitive type properties allowed
MethodDescription
RequireNestedClass(string name, Action<ClassValidator>?)Nested class must exist (optional validation)
RequireNestedClassIfExists(string name, Action<ClassValidator>?)Validates only if present
MethodDescription
RequireImmutable()Applies ImmutabilityRule (6-dimension immutability verification)

Inherits TypeValidator<Interface, InterfaceValidator> and verifies interface-level rules.

Uses methods inherited from TypeValidator (naming, method verification, dependencies, etc.).

Performs method-level signature verification.

MethodDescription
RequireVisibility(Visibility)Must have specified visibility
RequireStatic()Must be a static method
RequireNotStatic()Must not be static
RequireVirtual()Must be a virtual method
RequireNotVirtual()Must not be virtual
RequireExtensionMethod()Must be an extension method
MethodDescription
RequireReturnType(Type)Must have a specific return type (open generic supported)
RequireReturnTypeOfDeclaringClass()Must return the declaring class type
RequireReturnTypeOfDeclaringTopLevelClass()Must return the top-level class type
RequireReturnTypeContaining(string)Return type name must contain the string
MethodDescription
RequireParameterCount(int)Exact parameter count
RequireParameterCountAtLeast(int)Minimum parameter count
RequireFirstParameterTypeContaining(string)First parameter type contains the string
RequireAnyParameterTypeContaining(string)Any parameter type contains the string

The common base class inherited by ClassValidator and InterfaceValidator.

MethodDescription
RequireNameStartsWith(string prefix)Name must start with the prefix
RequireNameEndsWith(string suffix)Name must end with the suffix
RequireNameMatching(string regex)Name must match the regular expression
MethodDescription
RequireNoDependencyOn(string typeNameContains)Must not depend on the specified type
MethodDescription
RequireMethod(string name, Action<MethodValidator>)Verify a specific method
RequireMethodIfExists(string name, Action<MethodValidator>)Verify only if present
RequireAllMethods(Action<MethodValidator>)Verify all methods
RequireAllMethods(Func<MethodMember, bool>, Action<MethodValidator>)Verify filtered methods
MethodDescription
Apply(IArchRule<TType> rule)Apply a custom rule

Entry Points (ArchitectureValidationEntryPoint)

Section titled “Entry Points (ArchitectureValidationEntryPoint)”
Extension MethodDescription
ValidateAllClasses(Architecture, Action<ClassValidator>, bool verbose)Extension on IObjectProvider<Class>
ValidateAllInterfaces(Architecture, Action<InterfaceValidator>, bool verbose)Extension on IObjectProvider<Interface>

Return type: ValidationResultSummary

MethodDescription
ThrowIfAnyFailures(string ruleName)Throws ArchitectureViolationException on violations
public interface IArchRule<in TType> where TType : IType
{
string Description { get; }
IReadOnlyList<RuleViolation> Validate(TType target, Architecture architecture);
}
// Lambda-based custom rule
var rule = new DelegateArchRule<Class>(
"Rule description",
(target, architecture) => {
// Verification logic
return violations; // IReadOnlyList<RuleViolation>
});
// Compose multiple rules with AND
var composite = new CompositeArchRule<Class>(rule1, rule2, rule3);
// Description: "rule1 AND rule2 AND rule3"
public sealed record RuleViolation(
string TargetName, // Full name of the violating type
string RuleName, // Rule name
string Description); // Violation description
DimensionVerification Content
WritabilityNon-static members must be immutable
ConstructorsMust have no public constructors
PropertiesMust have no public setters
FieldsMust have no public non-static fields
CollectionsMutable collection types prohibited (List, Dictionary, etc.)
MethodsPublic non-static methods only from the allowed list

Allowed methods: Equals, GetHashCode, ToString, Create, Validate, operators, Getter methods

Pre-built test suites that instantly apply verified architecture rules through inheritance alone.

Provides 21 tests that verify DDD tactical patterns in the domain layer.

PropertyTypeDescription
ArchitectureArchitectureAssembly architecture loaded with ArchLoader
DomainNamespacestringRoot namespace where domain types reside
PropertyDefaultDescription
ValueObjectExcludeFromFactoryMethods[]ValueObject types to exclude from Create/Validate factory method verification
DomainServiceAllowedFieldTypes[]Field types to allow in DomainService’s RequireNoInstanceFields
CategoryTestVerification Content
EntityAggregateRoot_ShouldBe_PublicSealedClasspublic sealed, not static
EntityAggregateRoot_ShouldHave_CreateAndCreateFromValidatedCreate/CreateFromValidated static factory methods
EntityAggregateRoot_ShouldHave_GenerateEntityIdAttribute[GenerateEntityId] attribute
EntityAggregateRoot_ShouldHave_AllPrivateConstructorsAll constructors private
EntityEntity_ShouldBe_PublicSealedClasspublic sealed, not static (excluding AggregateRoot)
EntityEntity_ShouldHave_CreateAndCreateFromValidatedCreate/CreateFromValidated static factory methods
EntityEntity_ShouldHave_AllPrivateConstructorsAll constructors private
ValueObjectValueObject_ShouldBe_PublicSealedWithPrivateConstructorspublic sealed + private constructors
ValueObjectValueObject_ShouldBe_ImmutableImmutabilityRule 6-dimension immutability
ValueObjectValueObject_ShouldHave_CreateFactoryMethodCreate -> Fin<T> return
ValueObjectValueObject_ShouldHave_ValidateMethodValidate -> Validation<Error, T> return
DomainEventDomainEvent_ShouldBe_SealedRecordsealed record
DomainEventDomainEvent_ShouldHave_EventSuffix”Event” suffix
SpecificationSpecification_ShouldBe_PublicSealedpublic sealed
SpecificationSpecification_ShouldInherit_SpecificationBaseSpecification<T> inheritance
SpecificationSpecification_ShouldResideIn_DomainLayerLocated within domain namespace
DomainServiceDomainService_ShouldBe_PublicSealedpublic sealed
DomainServiceDomainService_ShouldBe_StatelessNo instance fields (excluding allowed types)
DomainServiceDomainService_ShouldNotDependOn_IObservablePortIObservablePort dependency prohibited
DomainServiceDomainService_PublicMethods_ShouldReturn_FinPublic instance methods return Fin<T>
DomainServiceDomainService_ShouldNotBe_RecordNot a record type

Provides 4 tests that verify Command/Query structure in the application layer.

PropertyTypeDescription
ArchitectureArchitectureAssembly architecture loaded with ArchLoader
ApplicationNamespacestringRoot namespace where application types reside
TestVerification Content
Command_ShouldHave_ValidatorNestedClassIf a Command has a Validator, it must be sealed + implement AbstractValidator
Command_ShouldHave_UsecaseNestedClassCommand must have a Usecase, sealed + implement ICommandUsecase
Query_ShouldHave_ValidatorNestedClassIf a Query has a Validator, it must be sealed + implement AbstractValidator
Query_ShouldHave_UsecaseNestedClassQuery must have a Usecase, sealed + implement IQueryUsecase

The next appendix provides a cheat sheet for quick reference of ArchUnitNET core APIs.

-> Appendix B: ArchUnitNET Cheat Sheet