Skip to main content

Dependency Injection

All core services are registered with a single extension method call:

services.AddAriadneNETServices();
services.AddAriadneNETWorkspaces(); // only when you check solutions on disk

AddAriadneNETWorkspaces() comes from the Ariadne.NET.Workspaces package. It registers ISolutionLoader and ISolutionValidator as singletons with AddSingleton, not through ZeroAlloc.Inject. ISolutionValidator needs IArchitectureValidator, so call both methods.

The method is hand-written and public. It calls the internal AddAriadneNETGeneratedServices(), which ZeroAlloc.Inject generates at compile time (every service class carries a [Singleton] attribute), and then AddGitClientResilience<GitCliClient>(), generated by ZeroAlloc.Resilience, which wraps the internal git client with a 60 second timeout and 3 retries. The MCP host project gets its own generated AddAriadneNETMcpServices(), which registers RuleResolutionHelper behind IRuleResolutionHelper. Adding a service means adding the attribute; there is no registration list to maintain.

Registration Table​

All services use Singleton lifetime. AddAriadneNETServices() registers:

InterfaceImplementationPurpose
IRulePackLoaderYamlRulePackLoaderYAML → RulePack deserialization
IBuiltinPackRegistryBuiltinPackRegistryEmbedded template discovery and loading
IRulePackMergerRulePackMergerMulti-pack composition
IRulePackResolverRulePackResolverReference resolution (builtin://, import://)
ILayerInferenceEngineLayerInferenceEngineRole → layer mapping
ICodeGeneratorServiceCodeGeneratorServiceRoslyn-based C# generation
IGenerateOrchestratorGenerateOrchestratorMulti-component generation workflow
IWorkspaceOrchestratorWorkspaceOrchestratorProject structure scaffolding
IArchitectureValidatorArchitectureValidatorType graph checks against layer and role rules
IImportsLoaderImportsYamlLoaderImports manifest parsing
IGitSyncProviderGitCliSyncProviderGit clone, tag resolution, caching
ISyncOrchestratorSyncOrchestratorMulti-import sync coordination

Registered by AddAriadneNETWorkspaces() in Ariadne.NET.Workspaces, also as singletons:

InterfaceImplementationPurpose
ISolutionLoaderSolutionLoaderLoads a solution, filter or project into compilations with MSBuildWorkspace
ISolutionValidatorSolutionValidatorLoads a path, checks its projects and returns an ArchitectureReport

Why Singleton?​

All services are stateless — they don't hold per-request state. The BuiltinPackRegistry caches loaded packs in a thread-safe dictionary, which benefits from Singleton lifetime. CodeGeneratorService creates a fresh AdhocWorkspace per call, avoiding shared mutable state.