DanielCunha.Toolkit.RepositoryPattern.EntityFrameworkCore 1.0.4

Install-Package DanielCunha.Toolkit.RepositoryPattern.EntityFrameworkCore -Version 1.0.4
dotnet add package DanielCunha.Toolkit.RepositoryPattern.EntityFrameworkCore --version 1.0.4
<PackageReference Include="DanielCunha.Toolkit.RepositoryPattern.EntityFrameworkCore" Version="1.0.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DanielCunha.Toolkit.RepositoryPattern.EntityFrameworkCore --version 1.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: DanielCunha.Toolkit.RepositoryPattern.EntityFrameworkCore, 1.0.4"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install DanielCunha.Toolkit.RepositoryPattern.EntityFrameworkCore as a Cake Addin
#addin nuget:?package=DanielCunha.Toolkit.RepositoryPattern.EntityFrameworkCore&version=1.0.4

// Install DanielCunha.Toolkit.RepositoryPattern.EntityFrameworkCore as a Cake Tool
#tool nuget:?package=DanielCunha.Toolkit.RepositoryPattern.EntityFrameworkCore&version=1.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Repository Pattern

This package contains classes and interfaces I frequently use in my projects for working with repository pattern. Read me more about repository pattern in this article.


Create a reusable project which contains all the basics I need to implement repository pattern without relying on copying the classes and interfaces every time.


Install NuGet package DanielCunha.Toolkit.RepositoryPattern or download repo and compile it manually so you can reference it from your target project.

Also, install or clone DanielCunha.Toolkit.RepositoryPattern.EntityFrameworkCore in case you're going to work with Entity Framework Core because it already contains a class which implements IRepository interface.


These packages are very ease of use. They just contain one interface and one class. You'll find an interface called IRepository in the DanielCunha.Toolkit.RepositoryPattern NuGet package.

The IRepository interface basically contains a couple of commonly used LINQ methods which your repository will inherit. You may implement your own base repository just inheriting from this interface.

public abstract class RepositoryBase<TEntity> : IRepository<TEntity> where TEntity : class
    protected readonly DbContext Context;

    protected RepositoryBase(DbContext context) 
        Context = context;


In this case I'm using Entity Framework Core, but fell free to use whatever ORM you want to.

Last but not least, in the package DanielCunha.Toolkit.RepositoryPattern.EntityFrameworkCore you'll find the RepositoryBase class. It's basically a class which already implements all the methods from IRepository using Entity Framework Core.

When implementing your repositories, just create an interface inheriting from IRepository, add some methods and then create a class which inherits from RepositoryBase and your interface. This is a sample:

// IRepository receives the type of your entity because it's generic
public interface IAuthorRepository : IRepository<Author>
    Task<IEnumerable<Author>> FindActiveAuthorsAsync();

// RepositoryBase receives the entity and the type of your DbContext, because it will be accessible
// from a protected readonly property in case you want to use it in your implementations
internal class AuthorRepository : RepositoryBase<Author, DataContext>, IAuthorRepository
    public AuthorRepository(DataContext context) : base(context)

    public async Task<IEnumerable<Author>> FindActiveAuthorsAsync()
        return await Context.Authors
            .Where(x => x.Active)

After that, all you have to do is to add this repository to your container, or to your Unit of Work in case your using one. Otherwise, you can still just instantiates the repository passing your DbContext. It really depends on your call.

In case there were any doubts, there is a sample project in this repository which use this packages.


Fell free to clone this repository and modify the projects as you wish. I'll glad to add your changes to the next version of the package!


MIT License.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.4 314 11/9/2019
1.0.3 202 11/9/2019
1.0.2 199 11/9/2019
1.0.1 196 11/9/2019
1.0.0 193 11/9/2019