Skip to main content

Database Providers

The same repository code runs against several database providers. Each provider ships as its own package and exposes a client factory plus a convenience repository factory. See Getting Started for the general initialization flow and dependency-injection setup.

Azure Cosmos DB

Package: Wemogy.Infrastructure.Database.Cosmos

var repository = CosmosDatabaseRepositoryFactory.CreateInstance<IUserRepository>(
"CONNECTION_STRING_HERE",
"DATABASE_NAME",
true); // enable insecure development mode for the local emulator

Or via dependency injection:

var databaseClientFactory = new CosmosDatabaseClientFactory("CONNECTION_STRING_HERE", "DATABASE_NAME");

services
.AddDatabase(databaseClientFactory)
.AddRepository<IUserRepository>();

Provider specifics:

  • Property names are serialized as camelCase, and null values are omitted.
  • The [ETag] attribute enables optimistic concurrency.
  • Multi-tenancy is supported.
  • The third constructor argument enables insecure development mode (gateway connection mode and relaxed certificate validation) for use with the local Cosmos DB emulator.

MongoDB

Package: Wemogy.Infrastructure.Database.Mongo

var repository = MongoDatabaseRepositoryFactory.CreateInstance<IUserRepository>(
"CONNECTION_STRING_HERE",
"DATABASE_NAME",
true);

Or via dependency injection:

var databaseClientFactory = new MongoDatabaseClientFactory("CONNECTION_STRING_HERE", "DATABASE_NAME");

services
.AddDatabase(databaseClientFactory)
.AddRepository<IUserRepository>();

In-Memory

Package: Wemogy.Infrastructure.Database.InMemory

The in-memory provider keeps data in process and requires no connection string. It is meant for unit tests, so the exact same repository code can be exercised without a real database.

var repository = InMemoryDatabaseRepositoryFactory.CreateInstance<IUserRepository>();

Provider specifics:

  • No external dependency or connection string.
  • State lives for the lifetime of the factory instance.
  • Multi-tenancy is supported.
Testing strategy

Reference the in-memory package in your test project and the real provider (Cosmos or Mongo) in your application. Because both implement the same IDatabaseClient, your repository logic and tests stay provider-independent.

Feature support matrix

FeatureCosmos DBMongoDBIn-Memory
CRUD, querying, sorting & pagination
Soft delete
Read & property filters
Multi-tenancy
Optimistic concurrency (ETag)