A modular framework for chaining processing links with hook support, designed for robust .NET applications.
This package supports the llm.txt standard for easy AI/LLM integration. See llm-full.txt for comprehensive documentation.
CodeUChain C# provides a clean, async-first architecture for building processing pipelines with:
- Immutable State: Thread-safe data passing between processing steps
- Link Interface: Pluggable processing units
- Chain Orchestration: Sequential execution with error handling
- Hook Support: Cross-cutting concerns like logging, authentication, etc.
dotnet add package CodeUChain --version 1.0.0# Clone the repository
git clone https://github.com/codeuchain/codeuchain.git
cd codeuchain/packages/csharp
# Build the library
dotnet build CodeUChain.csproj
# Run the example
dotnet run --project examples/MathProcessingExample.csprojusing CodeUChain;
// Create a processing chain
var chain = new Chain();
// Add processing links
chain = chain.AddLink("validate", new ValidationLink());
chain = chain.AddLink("process", new ProcessingLink());
chain = chain.AddLink("save", new SaveLink());
// Add hook
chain = chain.UseHook(new LoggingHook());
chain = chain.UseHook(new ErrorHandlingHook());
// Execute the chain
var input = State.Create(new Dictionary<string, object>
{
["data"] = "some input"
});
var result = await chain.RunAsync(input);Immutable data container that flows through the processing chain:
// Create state
var state = State.Create();
var stateWithData = State.Create(new Dictionary<string, object>
{
["key"] = "value"
});
// Manipulate data
var newState = state.Insert("newKey", "newValue");
var removedState = state.Remove("oldKey");
// Access data
var value = state.Get<string>("key");
var hasKey = state.ContainsKey("key");Processing units that transform the state:
public class MyLink : ILink
{
public async Task<State> CallAsync(State state)
{
// Process the state
var data = state.Get<string>("input");
var result = ProcessData(data);
return state.Insert("output", result);
}
}Cross-cutting concerns that intercept execution:
public class LoggingHook : IHook
{
public Task<State> BeforeAsync(ILink? link, State state)
{
var linkName = link?.GetType().Name ?? "Chain";
Console.WriteLine($"Executing: {linkName}");
return Task.FromResult(state);
}
public Task<State> AfterAsync(ILink? link, State state)
{
var linkName = link?.GetType().Name ?? "Chain";
Console.WriteLine($"Completed: {linkName}");
return Task.FromResult(state);
}
public Task<State> OnErrorAsync(ILink? link, Exception exception, State state)
{
var linkName = link?.GetType().Name ?? "Chain";
Console.WriteLine($"Error in {linkName}: {exception.Message}");
return Task.FromResult(state);
}
}Orchestrator that manages link execution and hook:
var chain = new Chain()
.AddLink("step1", new Step1Link())
.AddLink("step2", new Step2Link())
.UseHook(new LoggingHook());
var result = await chain.RunAsync(inputState);CodeUChain C# emphasizes:
- Harmony: Clean interfaces and predictable behavior
- Immutability: Thread-safe data flow
- Composability: Easy combination of components
- Error Resilience: Comprehensive error handling
- Observability: Hook-based monitoring
See the examples/ directory for complete working examples:
- MathProcessingExample: Demonstrates basic chain execution with logging hook
- More examples coming soon...
# Run tests (when test project is properly configured)
dotnet test- Follow the established patterns from other language implementations
- Maintain immutability and async-first design
- Add comprehensive tests for new features
- Update documentation
See the main repository for licensing information.