Skip to content

Choosing Your Approach

Aryeh Citron edited this page Apr 26, 2026 · 1 revision

Choosing Your Approach

At a Glance

Approach Best For DI Required? Prod Changes?
InMemoryMongo.Create<T>() Unit tests, simple scenarios No No
InMemoryMongo.Builder() Multi-collection unit tests No No
UseInMemoryMongoDB() Integration tests with DI Yes No
UseInMemoryMongoCollections() Collection-only DI replacement Yes No
Custom factory Advanced DI scenarios Yes No

Decision Flowchart

Are you using Dependency Injection?
├── No
│   ├── Single collection? → InMemoryMongo.Create<T>()
│   └── Multiple collections? → InMemoryMongo.Builder()
│
└── Yes
    ├── Need to replace IMongoClient + IMongoDatabase + IMongoCollection<T>?
    │   └── Yes → UseInMemoryMongoDB()
    │
    ├── Only need IMongoCollection<T> replacements?
    │   └── Yes → UseInMemoryMongoCollections()
    │
    └── Custom factory interface?
        └── Yes → Manual implementation (see Setup Guide Pattern 5)

Recommendation

For most projects, use:

  • InMemoryMongo.Create<T>() for unit tests
  • UseInMemoryMongoDB() for integration tests

These cover 90%+ of use cases with zero configuration.

See Also

Clone this wiki locally