Skip to content

wemogy/libs-infrastructure-database

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

233 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wemogy logo Infrastructure Database Layer

Abstraction Layer for multiple Database Technologies.

Currently Supported:

  • Local In Memory Database
  • Azure Cosmos DB
  • MongoDB

Getting started

Local In Memory Database

Install the NuGet package into your project.

dotnet add package Wemogy.Infrastructure.Database.InMemory

Initialize the Database Client Factory centrally.

var databaseClientFactory = new InMemoryDatabaseClientFactory();

Azure Cosmos DB

Install the NuGet package into your project.

dotnet add package Wemogy.Infrastructure.Database.Cosmos

Initialize the Database Client Factory centrally.

var databaseClientFactory = new CosmosDatabaseClientFactory("<CONNECTION_STRING>", "<DATABASE_NAME>");

MongoDB

Install the NuGet package into your project.

dotnet add package Wemogy.Infrastructure.Database.Mongo

Initialize the Database Client Factory centrally.

var databaseClientFactory = new MongoDatabaseClientFactory("<CONNECTION_STRING>", "<DATABASE_NAME>");

Define and register Repositories

If your Models are stored in a differen class library, install the Core NuGet package into your project.

dotnet add package Wemogy.Infrastructure.Database.Core

Define a class that you want to store in a database vie the Repository, and let it inherit from EntityBase.

public class Foo : EntityBase
{
}

Each repository needs to implement the IDatabaseRepository<T> interface.

public interface IFooRepository : IDatabaseRepository<Foo>
{
}

Register the Database Client Factory and the Repositories centrally at the Dependency Injection Container (for example in Startup.cs).

var databaseClientFactory = new // ...

services
    .AddDatabase(databaseClientFactory)
    .AddRepository<IFooRepository>()
    .AddRepository<IBarRepository>();

Checkout the full Documentation to get information about the available classes and extensions.

Testing

Cosmos

Initialize & start the cosmos DB emulator

docker compose -f env/cosmos/docker-compose.yaml up

MongoDB

Initialize & start the MongoDB emulator

docker compose -f env/mongo/docker-compose.yaml up

About

Abstraction Layer for multiple Database Technologies.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 5

Languages