A basic implementation of an In Memory Repository written in C#. This IS NOT a thread safe collection.
The library is witten in .Net Standard so should be usable in either the .Net Core or .Net Full Frameworks
Your model entity must inherit either inherit from the abstract Storeable class or implement IStorable:
public class Model : Storeable
{
public string Message { get; set; }
}
public class AlternativeModel : IStoreable<Model>
{
public IComparable Id { get; set; }
public string Message { get; set; }
}
Add a reference to the namespace:
using RepositoryPattern;
Initialize the in memory repository
IRepository repository = new InMemoryRepository<Model>();
Add an item to the repository:
repository.Save(new Model { Id = 1, "Message" });
Find an item to the repository:
repository.FindById(1);
Get IEnumerable collection of all items in the repository:
repository.All();
Delete an item to the repository:
repository.Delete(1);
A range of tests can be found in the RepositoryPattern.Tests project.