Repository navigation
Whats New In 4.0
The most significant change in 4.0. UseInMemoryCosmosContainers() now creates a hidden internal CosmosClient backed by FakeCosmosHandler, just like UseInMemoryCosmosDB(). This means:
-
.ToFeedIterator()works natively — noProductionExtensionspackage needed -
Containers resolved from DI are real SDK
Containerobjects (notInMemoryContainer) - Full SDK fidelity — serialization, LINQ-to-SQL translation, HTTP request construction, continuation tokens
-
Fault injection available via
OnHandlerCreatedcallback -
Handler wrapping via
WithHttpMessageHandlerWrapper()
The production CosmosClient registration is still not touched — only Container registrations are replaced.
// UseInMemoryCosmosContainers registered raw InMemoryContainer instances
services.UseInMemoryCosmosContainers(o => o.AddContainer("orders", "/pk"));
// ❌ Container resolved from DI was InMemoryContainer (no SDK pipeline)
// ❌ .ToFeedIterator() didn't work — needed the legacy ProductionExtensions workaround
// ❌ No fault injection, no request logging// Same API — but now backed by FakeCosmosHandler
services.UseInMemoryCosmosContainers(o => o.AddContainer("orders", "/pk"));
// ✅ Container from DI is a real SDK Container
// ✅ .ToFeedIterator() works natively
// ✅ Full SDK fidelity — serialization, LINQ-to-SQL, paginationInMemoryContainerOptions now supports:
services.UseInMemoryCosmosContainers(o =>
{
o.AddContainer("orders", "/pk");
o.DatabaseName = "TestDb";
// Capture handler for fault injection or request logging
o.OnHandlerCreated = (name, handler) =>
{
handler.FaultInjector = req => /* ... */;
};
// Wrap the HTTP handler (e.g. for logging)
o.WithHttpMessageHandlerWrapper(h => new MyLoggingHandler(h));
});UseInMemoryCosmosContainers() does not replace the production CosmosClient. This means:
- If your production code uses
CosmosClientto callGetContainer(), those container references will NOT go through the in-memory handler — they'll still reach the production endpoint - Only
Containerinstances resolved directly from DI are replaced - Use
UseInMemoryCosmosDB()instead if your code depends onCosmosClient
InMemoryCosmosClient is now marked [Obsolete]. It still works but is no longer recommended.
Why: It bypasses the SDK HTTP pipeline — no serialization testing, no LINQ-to-SQL translation, no fault injection, and .ToFeedIterator() doesn't work without ProductionExtensions.
Migration:
| Before | After |
|---|---|
new InMemoryCosmosClient() |
InMemoryCosmos.Create(...) or InMemoryCosmos.Builder()...
|
UseInMemoryCosmosDB<TClient>() with shadow types |
4.0.3+: Pass production typed client directly — shadow types removed, full SDK fidelity via Castle.Core proxy. See Pattern 2 |
The CosmosDB.InMemoryEmulator.ProductionExtensions NuGet package is no longer needed. All Dependency Injection methods and InMemoryCosmos now use FakeCosmosHandler, which handles .ToFeedIterator() natively.
The package still works for backward compatibility, but new code should not reference it.
InMemoryContainerOptions.RegisterFeedIteratorSetup is marked [Obsolete] and ignored. UseInMemoryCosmosContainers() no longer calls InMemoryFeedIteratorSetup.Register() since FakeCosmosHandler handles .ToFeedIterator() natively.
| Change | Impact |
|---|---|
UseInMemoryCosmosContainers() containers are real SDK Container (not InMemoryContainer) |
Code that cast Container to InMemoryContainer will fail. Use OnHandlerCreated to access handler.BackingContainer instead. |
UseInMemoryCosmosContainers() no longer calls InMemoryFeedIteratorSetup.Register()
|
Code that relied on the legacy feed iterator extension working after UseInMemoryCosmosContainers() may need to call InMemoryFeedIteratorSetup.Register() explicitly — or better, just use .ToFeedIterator() which now works natively. |
InMemoryCosmosClient is [Obsolete]
|
Compilation warnings (or errors with TreatWarningsAsErrors). Suppress with #pragma warning disable CS0618 or <NoWarn>CS0618</NoWarn> while migrating. |
- Choosing Your Approach — updated comparison
- Setup Guide — Pattern 4 — updated for 4.0
-
How Does ToFeedIterator() Work? — how
FakeCosmosHandlerhandles.ToFeedIterator()natively - Migration Guide — 3.x → 4.0 migration
Getting Started
Integration & Dependency Injection
Data Management
Reference
Help