ICommandor 1.0.0
dotnet add package ICommandor --version 1.0.0
NuGet\Install-Package ICommandor -Version 1.0.0
<PackageReference Include="ICommandor" Version="1.0.0" />
<PackageVersion Include="ICommandor" Version="1.0.0" />
<PackageReference Include="ICommandor" />
paket add ICommandor --version 1.0.0
#r "nuget: ICommandor, 1.0.0"
#:package ICommandor@1.0.0
#addin nuget:?package=ICommandor&version=1.0.0
#tool nuget:?package=ICommandor&version=1.0.0
Commandor
Commandor - MediatR uchun zamonaviy, yuqori samaradorlikka ega alternative. ActualLab.Fusion va MediatR'dan ilhomlangan, Source Generator va Automatic Caching bilan.
โจ Asosiy Xususiyatlar
- ๐ Zero Boilerplate - Handler'larni yozish shart emas (Source Generator)
- โก Auto Caching - Query'lar avtomatik cache'lanadi (3-5x tezroq)
- ๐ฅ Fusion Pattern - Dependency tracking va transitive invalidation
- ๐พ GC-free Cache - LiteAPI.Cache (Rust-backed, ultra-fast)
- ๐ฏ Type-Safe - To'liq compile-time xavfsizlik
- ๐ Command/Query Separation -
[CommandHandler]va[QueryHandler] - ๐งช Production Ready - 29/29 test o'tgan, ishonchli
๐ Quick Start
1. O'rnatish
dotnet add package Commandor
dotnet add package Commandor.Generators
2. Command va Query yaratish
using Commandor;
// Commands (Write operations - cache invalidation)
public record CreateProductCommand(string Name, decimal Price) : IRequest<Product>;
public record UpdatePriceCommand(int Id, decimal Price) : IRequest;
// Queries (Read operations - auto caching)
public record GetProductByIdQuery(int Id) : IRequest<Product?>;
3. Service interface - Attribute bilan
public interface IProductService : ICommandorService
{
[CommandHandler] // โจ Handler avtomatik yaratiladi!
Task<Product> CreateProduct(CreateProductCommand cmd, CancellationToken ct = default);
[CommandHandler] // โจ Cache'ni invalidate qiladi
Task UpdatePrice(UpdatePriceCommand cmd, CancellationToken ct = default);
[QueryHandler] // ๐ฅ Natija avtomatik cache'lanadi!
Task<Product?> GetProductById(GetProductByIdQuery query, CancellationToken ct = default);
}
4. Service implementation - Faqat business logic
public class ProductService : IProductService
{
private readonly List<Product> _products = new();
public Task<Product> CreateProduct(CreateProductCommand cmd, CancellationToken ct)
{
var product = new Product
{
Id = Random.Shared.Next(1000, 9999),
Name = cmd.Name,
Price = cmd.Price
};
_products.Add(product);
return Task.FromResult(product);
}
public Task UpdatePrice(UpdatePriceCommand cmd, CancellationToken ct)
{
var product = _products.First(p => p.Id == cmd.Id);
product.Price = cmd.Price;
// Cache'ni invalidate qilish
using (Invalidation.Begin())
{
_ = GetProductById(new GetProductByIdQuery(cmd.Id));
}
return Task.CompletedTask;
}
public Task<Product?> GetProductById(GetProductByIdQuery query, CancellationToken ct)
{
// Bu metod avtomatik cache'lanadi! โก
var product = _products.FirstOrDefault(p => p.Id == query.Id);
return Task.FromResult(product);
}
}
5. DI Setup
var services = new ServiceCollection();
// Commandor qo'shish
services.AddSingleton<ICommandor, Commandor.Commandor>();
// Service va auto-generated handler'larni ro'yxatga olish
services.AddCommandorService<IProductService, ProductService>();
var serviceProvider = services.BuildServiceProvider();
6. Ishlatish
var commandor = serviceProvider.GetRequiredService<ICommandor>();
// 1. Mahsulot yaratish
var product = await commandor.SendAsync(
new CreateProductCommand("iPhone 15 Pro", 15000000));
// 2. Birinchi query - DB'dan (~1.5ms)
var p1 = await commandor.SendAsync(new GetProductByIdQuery(product.Id));
// 3. Ikkinchi query - CACHE'dan (~0.3ms) โกโกโก 5x TEZROQ!
var p2 = await commandor.SendAsync(new GetProductByIdQuery(product.Id));
// 4. Narxni yangilash - cache invalidate
await commandor.SendAsync(new UpdatePriceCommand(product.Id, 14500000));
// 5. Keyingi query - yangi ma'lumot DB'dan
var p3 = await commandor.SendAsync(new GetProductByIdQuery(product.Id));
๐ Performance
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Birinchi Query (DB): ~1.5-2.0ms โ
โ Cached Query: ~0.3-0.6ms โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ Tezlashish: 3-5x โ
โ GC Pressure: ZERO โ
โ Memory: Ultra-efficient โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ฏ Command vs Query
Commands - Write Operations
[CommandHandler] // โ Cache'lanmaydi
Task<Product> CreateProduct(CreateProductCommand cmd);
[CommandHandler] // โก Cache'ni invalidate qiladi
Task UpdatePrice(UpdatePriceCommand cmd);
Xususiyatlari:
- Ma'lumotlarni o'zgartiradi (Create, Update, Delete)
- Cache'lanmaydi
- Tegishli Query'larni invalidate qiladi
Queries - Read Operations
[QueryHandler] // โ
Avtomatik cache'lanadi
Task<Product?> GetProductById(GetProductByIdQuery query);
[QueryHandler] // โ
Avtomatik cache'lanadi
Task<List<Product>> GetAllProducts(GetAllProductsQuery query);
Xususiyatlari:
- Faqat ma'lumot o'qiydi (Read-only)
- Avtomatik cache'lanadi
- Dependency tracking bilan
- Transitive invalidation
๐ฅ Fusion Pattern - Dependency Tracking
Commandor ActualLab.Fusion'dan ilhomlangan dependency tracking mexanizmini ishlatadi:
// A โ B bog'liqligi
var productList = await commandor.SendAsync(new GetProductListQuery());
// Ichida GetProductById chaqirilgan
// GetProductById invalidate bo'lsa
await commandor.SendAsync(new UpdatePriceCommand(1, 15000));
// GetProductList ham invalidate bo'ladi! (Transitive)
var updatedList = await commandor.SendAsync(new GetProductListQuery());
Computed Values
Har bir cached natija Computed<T> sifatida saqlanadi:
public interface IComputed<T>
{
T Value { get; } // Cache'langan qiymat
long Version { get; } // Versiya (invalidation tracking)
ConsistencyState State { get; } // Consistent, Computing, Invalidated
bool IsConsistent(); // Cache hali fresh?
void Invalidate(); // Cache'ni bekor qilish
Task WhenInvalidated(); // Invalidation kutish
}
๐พ LiteAPI.Cache - GC-free Caching
Commandor LiteAPI.Cache 1.1.0 dan foydalanadi:
Afzalliklar
- โก Ultra-fast - Rust-backed native implementation
- ๐ง GC-free - .NET garbage collector'ga ta'sir qilmaydi
- ๐ Thread-safe - Concurrent access safe
- ๐พ Cross-platform - Windows, Linux, macOS
- ๐ Production-ready - Battle-tested
Cache Key Format
ServiceType.MethodName(arg1, arg2, ...)
Misollar:
- ProductService.GetProductById(1)
- ProductService.GetAllProducts()
- UserService.GetUserByEmail("john@example.com")
๐ Boshqa Kutubxonalar bilan Taqqoslash
| Xususiyat | Commandor | MediatR | Fusion |
|---|---|---|---|
| Handler Generation | โ Avtomatik | โ Qo'lda | โ Avtomatik |
| Source Generator | โ | โ | โ |
| Auto Caching | โ | โ | โ |
| GC-free Cache | โ | โ | โ |
| Dependency Tracking | โ | โ | โ |
| Transitive Invalidation | โ | โ | โ |
| Type Safety | โ | โ | โ |
| Learning Curve | โญโญ | โญโญโญ | โญโญโญโญ |
| Naming | "o" ๐ | "e" | "e" |
๐๏ธ Arxitektura
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Application Layer โ
โ โโ await commandor.SendAsync(command) โ
โ โโ await commandor.SendAsync(query) โ
โโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Commandor Core (ICommandor) โ
โ โโ Request routing โ
โ โโ Handler resolution (DI) โ
โ โโ Caching logic (Query'lar uchun) โ
โโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโดโโโโโโโโโโโโโ
โ โ
โโโโโผโโโโโโโโโโโโโโโ โโโโโโโโผโโโโโโโโโโโโโโโโโโโ
โ CommandHandler โ โ QueryHandler (Cached) โ
โ - Write ops โ โ - Read ops โ
โ - No cache โ โ - Auto cache โ
โ - Invalidation โ โ - Dependency tracking โ
โโโโโฌโโโโโโโโโโโโโโโ โโโโโโโโฌโโโโโโโโโโโโโโโโโโโ
โ โ
โโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโ
โ Source Generator (Commandor.Generators) โ
โ โโ Compile-time handler generation โ
โ โโ [CommandHandler] โ Handler class โ
โ โโ [QueryHandler] โ Cached handler class โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Cache Layer โ
โ โโ LiteApiComputedCache (default, GC-free) โ
โ โโ CommandorMemoryCache (fallback) โ
โ โโ ComputedRegistry (global tracking) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐งช Testlar
dotnet test
Test Coverage
โ
29/29 Tests Passing
๐ Test Suites:
โโ CommandorTests (7 tests) - v1 manual handlers
โโ GeneratorCommandorTests (5) - v2 source generator
โโ CachingTests (14) - Cache infrastructure
โ โโ CacheKeyBuilder (3)
โ โโ CommandorMemoryCache (4)
โ โโ Computed<T> (4)
โ โโ ComputedRegistry (2)
โ โโ LiteApiComputedCache (1)
โโ IntegrationTests (3) - End-to-end workflows
โฑ๏ธ Total Time: 1.17s
๐ Dokumentatsiya
- README.md - Ushbu fayl (umumiy ko'rinish)
- README_V2.md - Source Generator to'liq qo'llanma
- CACHING.md - Caching va Fusion pattern tafsilotlari
- EXAMPLES.md - Ko'proq misollar
๐๏ธ Proyekt Tuzilmasi
Commandor/
โโโ Commandor/ # Core library
โ โโโ IRequest.cs # Request interfaces
โ โโโ IRequestHandler.cs # Handler interfaces
โ โโโ ICommandor.cs # Mediator interface
โ โโโ Commandor.cs # Core implementation
โ โโโ CommandHandlerAttribute.cs # Command attribute
โ โโโ QueryHandlerAttribute.cs # Query attribute (caching)
โ โโโ ICommandorService.cs # Service marker
โ โโโ IComputed.cs # Computed value interface
โ โโโ Computed.cs # Computed<T> implementation
โ โโโ IComputedCache.cs # Cache abstractions
โ โโโ CacheKeyBuilder.cs # Cache key generator
โโโ Commandor.Generators/ # Source Generator
โ โโโ CommandHandlerGenerator.cs # Roslyn generator
โโโ Commandor.Example/ # Demo application
โ โโโ Program.cs # Example usage
โ โโโ Services/
โ โโโ ProductService.cs # Example service
โโโ Commandor.Tests/ # Unit tests (29 tests)
โ โโโ CommandorTests.cs # v1 tests
โ โโโ GeneratorCommandorTests.cs # v2 tests
โ โโโ CachingTests.cs # Cache tests
โ โโโ IntegrationTests.cs # E2E tests
โโโ README.md # Documentation
๐ Migration: MediatR โ Commandor
MediatR (Before)
// Command
public class CreateOrderCommand : IRequest<Order>
{
public string ProductName { get; set; }
public int Quantity { get; set; }
}
// Handler (manual)
public class CreateOrderCommandHandler
: IRequestHandler<CreateOrderCommand, Order>
{
public async Task<Order> Handle(
CreateOrderCommand request,
CancellationToken ct)
{
// Business logic
}
}
// DI
services.AddMediatR(cfg =>
cfg.RegisterServicesFromAssembly(typeof(Program).Assembly));
// Usage
await mediator.Send(new CreateOrderCommand { ... });
Commandor (After)
// Command (record)
public record CreateOrderCommand(string ProductName, int Quantity)
: IRequest<Order>;
// Service interface
public interface IOrderService : ICommandorService
{
[CommandHandler] // โจ Handler avtomatik!
Task<Order> CreateOrder(CreateOrderCommand cmd, CancellationToken ct = default);
}
// DI
services.AddSingleton<ICommandor, Commandor.Commandor>();
services.AddCommandorService<IOrderService, OrderService>();
// Usage
await commandor.SendAsync(new CreateOrderCommand("iPhone", 1));
Afzalliklar
- โ 70% kam kod - handler sinflarini yozish shart emas
- โ Record types - immutable, concise
- โ Auto caching - query'lar uchun bepul
- โ Type-safe - compile-time xavfsizlik
๐ Production Deployment
Best Practices
- Command/Query Separation - Doim ajrating
- Service per Aggregate - Har bir aggregate uchun alohida service
- Validation - Command'larni validate qiling
- Error Handling - Exception handling strategiyasi
- Logging - Muhim operatsiyalarni log qiling
- Monitoring - Cache hit/miss ratio kuzatish
ASP.NET Core Integration
// Program.cs
var builder = WebApplication.CreateBuilder(args);
// Commandor
builder.Services.AddSingleton<ICommandor, Commandor.Commandor>();
builder.Services.AddCommandorService<IProductService, ProductService>();
builder.Services.AddCommandorService<IOrderService, OrderService>();
// Controllers
builder.Services.AddControllers();
var app = builder.Build();
app.MapControllers();
app.Run();
// ProductsController.cs
[ApiController]
[Route("api/[controller]")]
public class ProductsController : ControllerBase
{
private readonly ICommandor _commandor;
public ProductsController(ICommandor commandor) => _commandor = commandor;
[HttpPost]
public async Task<IActionResult> Create([FromBody] CreateProductCommand cmd)
{
var product = await _commandor.SendAsync(cmd);
return CreatedAtAction(nameof(Get), new { id = product.Id }, product);
}
[HttpGet("{id}")]
public async Task<IActionResult> Get(int id)
{
var product = await _commandor.SendAsync(new GetProductByIdQuery(id));
return product != null ? Ok(product) : NotFound();
}
}
๐ Kelajak Rejalari
- Distributed caching (Redis support)
- Cache TTL (Time To Live)
- Cache statistics va monitoring
- GraphQL integration
- OpenTelemetry tracing
- Benchmarks (vs MediatR, vs Fusion)
๐ค Hissa Qo'shish
Pull request'lar va issue'lar qabul qilinadi!
- Fork qiling
- Feature branch yarating (
git checkout -b feature/AmazingFeature) - Commit qiling (
git commit -m 'Add some AmazingFeature') - Push qiling (
git push origin feature/AmazingFeature) - Pull Request oching
๐ Litsenziya
MIT License - LICENSE faylini ko'ring
๐จโ๐ป Muallif
Bu loyiha quyidagi texnologiyalardan ilhomlangan:
- MediatR - Command/Query pattern
- ActualLab.Fusion - Automatic caching va dependency tracking
- LiteAPI.Cache - GC-free cache implementation
๐ Minnatdorchilik
- Jimmy Bogard - MediatR yaratgani uchun
- ActualLab team - Fusion pattern uchun
- LiteAPI.Cache team - GC-free cache uchun
<div align="center">
โญ Agar loyiha foydali bo'lsa, GitHub'da star qo'yishni unutmang! โญ
Commandor - Command va Query'laringizni boshqarish uchun eng oson va tez yo'l! ๐
</div>
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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 is compatible. 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. |
-
net7.0
- LiteAPI.Cache (>= 1.1.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
-
net8.0
- LiteAPI.Cache (>= 1.1.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
-
net9.0
- LiteAPI.Cache (>= 1.1.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 1,382 | 11/18/2025 |