Skip to content

Why Choose Foundatio?

Foundatio was born from real-world experience building large-scale cloud applications. Here's why it stands out from other approaches.

The Problem

When building distributed applications, you typically face these challenges:

  1. Vendor Lock-in: Direct use of Redis, Azure, or AWS SDKs couples your code to specific providers
  2. Testing Complexity: External dependencies make testing slow and unreliable
  3. Development Setup: Developers need to run Redis, Azure Storage Emulator, etc. locally
  4. Inconsistent Patterns: Different team members use different approaches for the same problems
  5. Reinventing the Wheel: Every project implements caching, queuing, locking from scratch

The Foundatio Solution

🔌 Pluggable Abstractions

Write your code against interfaces, not implementations:

csharp
// Your service doesn't care about the implementation
public class OrderProcessor
{
    private readonly ICacheClient _cache;
    private readonly IQueue<Order> _queue;

    public OrderProcessor(ICacheClient cache, IQueue<Order> queue)
    {
        _cache = cache;
        _queue = queue;
    }
}

Change from in-memory to Redis with one line in your DI configuration:

csharp
// Development
services.AddSingleton<ICacheClient, InMemoryCacheClient>();

// Production
services.AddSingleton<ICacheClient>(sp =>
    new RedisCacheClient(o => o.ConnectionMultiplexer = redis));

🧪 Superior Testing Experience

No mocking frameworks needed - use real implementations:

csharp
[Fact]
public async Task Should_Process_Order_With_Caching()
{
    // Arrange - use in-memory implementations
    var cache = new InMemoryCacheClient();
    var queue = new InMemoryQueue<Order>();
    var processor = new OrderProcessor(cache, queue);

    // Act
    await processor.ProcessAsync(new Order { Id = 1 });

    // Assert
    var cached = await cache.GetAsync<Order>("order:1");
    Assert.NotNull(cached);
}

Benefits:

  • Fast: No network calls
  • Isolated: No shared state between tests
  • Reliable: No external service failures
  • Complete: Test the exact code path used in production

🚀 Zero-Config Development

Start coding immediately without external dependencies:

csharp
// Works out of the box - no Redis, no Azure, no AWS
var cache = new InMemoryCacheClient();
var queue = new InMemoryQueue<WorkItem>();
var messageBus = new InMemoryMessageBus();
var storage = new InMemoryFileStorage();

Compare to other approaches:

  • Direct Redis: Requires running Redis server
  • Direct Azure: Requires Azure subscription or emulator
  • Direct AWS: Requires AWS account or LocalStack

📊 Comparison with Alternatives

vs. Direct SDK Usage

AspectDirect SDKFoundatio
TestingMock everythingUse in-memory implementations
Switching providersRewrite codeChange DI registration
Local developmentRun servicesZero dependencies
Learning curveLearn each SDKLearn one API

vs. Building Your Own

AspectDIYFoundatio
Time to implementWeeks/monthsMinutes
Battle testedNoYes (years of production use)
Edge cases handledMaybeComprehensive
Maintenance burdenOn youOn community

vs. Other Libraries

Foundatio is unique in providing:

  1. Complete abstraction set: Caching, Queues, Locks, Messaging, Storage, Jobs, Resilience
  2. Consistent API design: Same patterns across all abstractions
  3. In-memory implementations: For all abstractions, not just some
  4. Active maintenance: Regular updates and community support

Real-World Usage

Exceptionless

Exceptionless, a large-scale error tracking application, uses Foundatio extensively:

  • Caching: User sessions, resolved geo-locations with MaxItems limit
  • Queues: Event processing pipeline
  • Jobs: Background processing for reports, cleanup, notifications
  • Storage: Error stack traces, attachments
  • Messaging: Real-time notifications

Enterprise Applications

Teams choose Foundatio for:

  • Consistency: Same patterns across all services
  • Onboarding: New developers learn one API
  • Migration: Easy to switch providers without code changes
  • Testing: Comprehensive test coverage without infrastructure

Feature Highlights

Hybrid Caching

Combine local and distributed caching for maximum performance:

csharp
var hybridCache = new HybridCacheClient(
    distributedCache: new RedisCacheClient(...),
    messageBus: new RedisMessageBus(...)
);
  • Local cache for fastest access
  • Distributed cache for consistency
  • Message bus for cache invalidation

Scoped Caching

Easily namespace your cache keys:

csharp
var scopedCache = new ScopedCacheClient(cache, "tenant:123");
await scopedCache.SetAsync("user", user); // Key: "tenant:123:user"
await scopedCache.RemoveByPrefixAsync(""); // Clears all tenant:123 keys

Throttling Locks

Rate limit operations across all instances:

csharp
var throttledLocker = new ThrottlingLockProvider(
    cache,
    maxHits: 10,
    period: TimeSpan.FromMinutes(1)
);

// Only allows 10 operations per minute across all instances
if (await throttledLocker.AcquireAsync("api-call"))
{
    await CallExternalApiAsync();
}

Queue Behaviors

Extend queue functionality with behaviors:

csharp
queue.AttachBehavior(new MetricsQueueBehavior<T>(metrics));
queue.AttachBehavior(new RetryQueueBehavior<T>(maxRetries: 3));

Resilience Policies

Built-in retry and circuit breaker:

csharp
var policy = new ResiliencePolicyBuilder()
    .WithMaxAttempts(5)
    .WithExponentialDelay(TimeSpan.FromSeconds(1))
    .WithMaxDelay(TimeSpan.FromMinutes(1))
    .WithJitter()
    .WithCircuitBreaker(cb => cb
        .WithFailureRatio(0.5)
        .WithBreakDuration(TimeSpan.FromMinutes(1)))
    .Build();

Getting Started

Ready to try Foundatio?

  1. Installation & Setup - Get running in minutes
  2. Caching Guide - Deep dive into caching
  3. Sample Application - See complete examples

The combination of consistent abstractions, excellent testability, and production-ready implementations makes Foundatio an excellent choice for modern .NET applications.

Released under the Apache 2.0 License.