Table of Contents

Class InMemoryRepositoryBase<T>

Namespace
Core.CliniCore.Repositories.InMemory
Assembly
Core.CliniCore.dll

Abstract base class for in-memory repository implementations. Provides thread-safe CRUD operations using a dictionary backing store.

Design Notes:

  • Uses lock-based synchronization for thread safety
  • Dictionary keyed by entity Id for O(1) lookups
  • Derived classes implement Search() method for entity-specific search logic
public abstract class InMemoryRepositoryBase<T> : IRepository<T> where T : class, IIdentifiable

Type Parameters

T

Entity type implementing IIdentifiable

Inheritance
InMemoryRepositoryBase<T>
Implements
Derived
Inherited Members

Fields

_entities

protected readonly Dictionary<Guid, T> _entities

Field Value

Dictionary<Guid, T>

_lock

protected readonly object _lock

Field Value

object

Properties

Count

Gets the count of entities in the repository

public int Count { get; }

Property Value

int

Methods

Add(T)

Adds a new entity to the repository

public virtual void Add(T entity)

Parameters

entity T

The entity to add

Exceptions

ArgumentNullException

If entity is null

InvalidOperationException

If entity with same Id already exists

Delete(Guid)

Deletes an entity from the repository by Id

public virtual void Delete(Guid id)

Parameters

id Guid

The Id of the entity to delete

Exceptions

KeyNotFoundException

If entity doesn't exist

Exists(Guid)

Checks if an entity with the given Id exists

public bool Exists(Guid id)

Parameters

id Guid

Returns

bool

GetAll()

Gets all entities in the repository

public virtual IEnumerable<T> GetAll()

Returns

IEnumerable<T>

An enumerable of all entities (snapshot at time of call)

GetById(Guid)

Gets an entity by its unique identifier

public virtual T? GetById(Guid id)

Parameters

id Guid

The entity's GUID

Returns

T

The entity if found, null otherwise

Search(string)

Searches for entities matching the query string. Must be implemented by derived classes for entity-specific search logic.

public abstract IEnumerable<T> Search(string query)

Parameters

query string

The search query string

Returns

IEnumerable<T>

Entities matching the query

Update(T)

Updates an existing entity in the repository

public virtual void Update(T entity)

Parameters

entity T

The entity with updated values

Exceptions

ArgumentNullException

If entity is null

KeyNotFoundException

If entity doesn't exist