Cocoar.Capabilities 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Cocoar.Capabilities --version 1.0.0
                    
NuGet\Install-Package Cocoar.Capabilities -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Cocoar.Capabilities" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Cocoar.Capabilities" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Cocoar.Capabilities" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Cocoar.Capabilities --version 1.0.0
                    
#r "nuget: Cocoar.Capabilities, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Cocoar.Capabilities@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Cocoar.Capabilities&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Cocoar.Capabilities&version=1.0.0
                    
Install as a Cake Tool

High-performance capability composition for .NET

Cocoar.Capabilities

A high-performance, low-allocation capability composition library for .NET that implements the Capability Composition pattern for building extensible, type-safe systems.

NuGet License .NET Downloads

🚀 Features

  • 🎯 Type-Safe Composition - Attach multiple capabilities to any object with full type safety
  • ⚡ High Performance - Zero-allocation lookups and minimal overhead
  • 🔒 Immutable Compositions - Thread-safe by design with immutable capability collections
  • 🎨 Flexible Registration - Support for multiple contract types per capability
  • 📦 Primary Capabilities - Enforce single "primary" capability per subject
  • 🔄 Recomposition - Modify existing compositions safely
  • 🎭 Custom Ordering - Control capability resolution order with flexible ordering strategies
  • 🗂️ Registry Support - Optional registries for managing compositions across your application

📦 Installation

dotnet add package Cocoar.Capabilities

🎓 Quick Start

using Cocoar.Capabilities;

// Create a scope to manage capabilities
using var scope = new CapabilityScope();

// Define your subject
var document = new Document("README.md");

// Compose capabilities
var composition = scope.For(document)
    .Add(new EditCapability())
    .Add(new PrintCapability())
    .Add(new ShareCapability())
    .Build();

// Retrieve and use capabilities
var capabilities = composition.GetAll<EditCapability>();
foreach (var cap in capabilities)
{
    cap.Edit(document);
}

Primary Capabilities

Enforce a single "primary" capability per subject:

public record UserPrimaryCapability(string UserId, string Name) : IPrimaryCapability;

var composition = scope.For(user)
    .Add(new UserPrimaryCapability("user123", "John Doe"))
    .Add(new AdminCapability("Level2"))
    .Build();

// Retrieve the primary capability
var primary = composition.GetPrimary();
Console.WriteLine($"User: {primary.Name}");

Multiple Contracts

Register a single capability under multiple contract types:

var composition = scope.For(myObject)
    .AddAs<(IValidator, IFormatter)>(new DataProcessor())
    .Build();

// Access via either contract
var validator = composition.GetFirstOrDefault<IValidator>();
var formatter = composition.GetFirstOrDefault<IFormatter>();

📚 Documentation

🎯 Key Concepts

  • CapabilityScope - Entry point for all capability operations
  • Composer - Fluent builder for creating compositions
  • Composition - Immutable collection of capabilities attached to a subject
  • Primary Capability - Single "main" capability per subject (via IPrimaryCapability)
  • Registry - Optional centralized management of compositions

Contributing & Versioning

  • SemVer (additive MINOR, breaking MAJOR)
  • PRs & issues welcome
  • Licensed under Apache License 2.0 (explicit patent grant & attribution via NOTICE)

License & Trademark

This project is licensed under the Apache License, Version 2.0. See NOTICE for attribution.

"Cocoar" and related marks are trademarks of COCOAR e.U. Use of the name in forks or derivatives should preserve attribution and avoid implying official endorsement. See TRADEMARKS for permitted and restricted uses.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Cocoar.Capabilities:

Package Downloads
Cocoar.Configuration

Reactive, strongly-typed configuration layering for .NET with health monitoring, file resilience, and zero-downtime updates. Core library providing ConfigManager, providers (file, environment, command-line, observable), and differential updates.

Cocoar.Configuration.DI

Dependency injection integration for Cocoar.Configuration with Microsoft.Extensions.DependencyInjection. Fluent API for registering configuration types with customizable lifetimes (singleton, scoped, transient) and keyed services.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.0 500 11/3/2025
1.1.0 124 10/26/2025
1.0.0 123 10/10/2025