Skip to content

Finaps/DotNetDatabase

Repository files navigation

Database Abstraction

The purpose of this package is to provide a basis of a repository pattern on top of a given database. Currently this package targets Mongo and Entity Framework.

Setup

Mongo

Create a mongo model:

  public class TestMongoObject : IMongoModel
  {
    public string CoolString { get; set; }
    public Guid Id { get; set; }
  }

The IMongoModel requires that you have an Id configured for you object.

Create a interface for your repository (optional):

  public interface ITestMongoRepository : IMongoRepository<TestMongoObject>
  {

  }

Create your repository:

  public class TestMongoRepository : MongoRepository<TestMongoObject>, ITestMongoRepository
  {
    public TestMongoRepository(IMongoCollection<TestMongoObject> collection) : base(collection)
    {
    }
  }

Entity Framework

Create a model:

  public class TestEfObject
  {
    public Guid Id { get; set; }
    public string CoolString { get; set; }
  }

Create a interface for your repository (optional):

  public interface ITestEfRepository : IEntityFrameworkRepository<TestEfObject>
  {

  }

Create your repository:

  public class TestEfRepository : EntityFrameworkRepository<TestEfObject>, ITestEfRepository
  {
    public TestEfRepository(TestDbContext context) : base(context)
    {
    }
  }

Startup

Configure Mongo / DB Context as you would usually to ensure the dependency injection works correctly.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages