Skip to content

demolite-nuget/DemoliteDb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Demolite.Db

Demolite.Db is a simple database wrapper package utilizing EF Core. It is meant to reduce the amount of boilerplate code needed for creating new projects and for handling db operations.

Using this package works as follows:

  1. Create an abstract repository for your DbContext
    public abstract class AbstractMyContextRepository<T>(IDbContextFactory<MyDbContext> contextFactory)
        : AbstractBaseRepository<T, MyContext> 
        where T: class, IHasOperation
    {
        
    }
  1. In the context, override the methods for GetContextAsync() and GetContext(). In this example, a context factory is injected, but you can use any method to instantiate your DbContext.

  2. Create a db model which inherits AbstractDbItem, or create your own AbstractDbItem which implements the IDbItem and IHasOperation interface

    public class ModelType : AbstractDbItem
  1. Create an empty interface class for your repository which implements IDbRepository for your model class.
    public interface IModelTypeRepository : IDbRepository<ModelType>;
  1. Implement the interface and inherit from your abstract repository in your model type repository:
    public class ModelTypeRepository(IDbContextFactory<MyDbContext> contextFactory) 
        : AbstractMyContextRepository<ModelType>(contextFactory), IModelTypeRepository
  1. Now just register the repository in your DI and it is ready to use.

Updates:

v0.1.0:

  • Removed dependency on Serilog
  • Updated EF Core to address vulnerability CVE-2024-43483

About

A .NET8 based easy to use Abstract EF Core Repository

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages