Skip to content

Commit

Permalink
Merge pull request #30 from e13tech/repo
Browse files Browse the repository at this point in the history
IRepository Enhancements
  • Loading branch information
JJBussert authored Feb 24, 2021
2 parents 22b02bb + 7d7576b commit 91405dc
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
CI | CD | OWASP | License
------ | ------ | ------ | ------
[![Build Status](https://dev.azure.com/e13tech/common/_apis/build/status/ci?branchName=master)](https://dev.azure.com/e13tech/common/_build/latest?definitionId=29&branchName=master) | [![Build Status](https://dev.azure.com/e13tech/common/_apis/build/status/cd?branchName=master)](https://dev.azure.com/e13tech/common/_build/latest?definitionId=30&branchName=master) | [![Build Status](https://dev.azure.com/e13tech/common/_apis/build/status/owasp?branchName=mac)](https://dev.azure.com/e13tech/common/_build/latest?definitionId=31&branchName=mac) | ![MIT](https://badgen.net/badge/license/MIT/blue)
[![Build history](https://buildstats.info/azurepipelines/chart/e13tech/common/29)](https://dev.azure.com/e13tech/common/_build?definitionId=29) | [![Build history](https://buildstats.info/azurepipelines/chart/e13tech/common/30)](https://dev.azure.com/e13tech/common/_build?definitionId=30) | [![Build history](https://buildstats.info/azurepipelines/chart/e13tech/common/31)](https://dev.azure.com/e13tech/common/_build?definitionId=31) |


CI | CD | OWASP
------ | ------ | ------
[![Build Status](https://dev.azure.com/e13tech/common/_apis/build/status/ci?branchName=master)](https://dev.azure.com/e13tech/common/_build/latest?definitionId=29&branchName=master) | [![Build Status](https://dev.azure.com/e13tech/common/_apis/build/status/cd?branchName=master)](https://dev.azure.com/e13tech/common/_build/latest?definitionId=30&branchName=master) | [![Build Status](https://dev.azure.com/e13tech/common/_apis/build/status/owasp?branchName=mac)](https://dev.azure.com/e13tech/common/_build/latest?definitionId=31&branchName=mac)
[![Build history](https://buildstats.info/azurepipelines/chart/e13tech/common/29)](https://dev.azure.com/e13tech/common/_build?definitionId=29) | [![Build history](https://buildstats.info/azurepipelines/chart/e13tech/common/30)](https://dev.azure.com/e13tech/common/_build?definitionId=30) | [![Build history](https://buildstats.info/azurepipelines/chart/e13tech/common/31)](https://dev.azure.com/e13tech/common/_build?definitionId=31)

License | ![MIT](https://badgen.net/badge/license/MIT/blue)
------ | ------
Codecy | [![Codacy Badge](https://app.codacy.com/project/badge/Grade/f68816611a5543f0bb5c55df77032ff0)](https://www.codacy.com/gh/e13tech/common/dashboard?utm_source=github.com&utm_medium=referral&utm_content=e13tech/common&utm_campaign=Badge_Grade)


# E13.common
Expand Down
5 changes: 4 additions & 1 deletion src/E13.Common.Data.Db/IRepository.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using E13.Common.Core;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.EntityFrameworkCore.Query;
using System;
Expand All @@ -14,7 +15,9 @@ namespace E13.Common.Data.Db
/// Defines the interfaces for generic repository.
/// </summary>
/// <typeparam name="TEntity">The type of the entity.</typeparam>
public interface IRepository<TEntity> where TEntity : class
public interface IRepository<TContext, TEntity>
where TContext : DbContext
where TEntity : class
{
/// <summary>

Expand Down
29 changes: 25 additions & 4 deletions src/E13.Common.Data.Db/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,39 @@
namespace E13.Common.Data.Db
{
/// <summary>
/// Represents a default generic repository implements the <see cref="IRepository{TEntity}"/> interface.
/// ShortHand for the <see cref="Repository{TContext, TEntity}"/> that accepts a base DbContext type for Repositories that do not need access to other domains
/// </summary>
/// <typeparam name="TEntity">The type of the entity.</typeparam>
public class Repository<TEntity> : IRepository<TEntity> where TEntity : class
/// <seealso cref="Repository{TContext, TEntity}"/>
public class Repository<TEntity> : Repository<DbContext, TEntity>
where TEntity : class
{
protected DbContext Context { get; }
protected DbSet<TEntity> DbSet {get;}
/// <summary>
/// Initializes a new instance of the <see cref="Repository{TEntity}"/> class.
/// </summary>
/// <param name="dbContext">The database context.</param>
public Repository(DbContext dbContext)
: base(dbContext)
{}
}

/// <summary>
/// Represents a default generic repository implements the <see cref="IRepository{TContext, TEntity}"/> interface.
/// </summary>
/// <typeparam name="TContext">The type of the EFCore DbContext.</typeparam>
/// <typeparam name="TEntity">The type of the entity.</typeparam>
public class Repository<TContext, TEntity> : IRepository<TContext, TEntity>
where TContext : DbContext
where TEntity : class
{
protected TContext Context { get; }
protected DbSet<TEntity> DbSet {get;}

/// <summary>
/// Initializes a new instance of the <see cref="Repository{TEntity}"/> class.
/// </summary>
/// <param name="dbContext">The database context.</param>
public Repository(TContext dbContext)
{
Context = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
DbSet = Context.Set<TEntity>();
Expand Down

0 comments on commit 91405dc

Please sign in to comment.