Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ namespace EasyWay.Samples.Databases
{
public class SampleAggragateRootRepository : ISampleAggragateRootRepository, IAsyncDisposable
{
private readonly IWriteGenericRepository<SampleAggregateRoot> _repository;
private readonly IGenericRepository<SampleAggregateRoot> _repository;

public SampleAggragateRootRepository(IWriteGenericRepository<SampleAggregateRoot> repository)
public SampleAggragateRootRepository(IGenericRepository<SampleAggregateRoot> repository)
{
_repository = repository;
}
Expand Down
2 changes: 1 addition & 1 deletion source/EasyWay.EntityFrameworkCore/Extnsions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static void AddEntityFrameworkCore<TContext>(
services.AddScoped<IAggregateRootsContext, EntityFrameworkAggregateRootsContext>();
services.AddTransient<IDomainEventsContext, DomainEventsAccessor>();

services.AddScoped(typeof(IWriteGenericRepository<>), typeof(WriteGenericRepository<>));
services.AddScoped(typeof(IGenericRepository<>), typeof(GenericRepository<>));

services.AddTransactions();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace EasyWay
{
public interface IWriteGenericRepository<TAggregateRoot>
public interface IGenericRepository<TAggregateRoot>
where TAggregateRoot : AggregateRoot
{
Task Add(TAggregateRoot aggregateRoot);
Expand All @@ -11,6 +11,8 @@ public interface IWriteGenericRepository<TAggregateRoot>

Task<TAggregateRoot?> Get(Guid id);

Task<IEnumerable<TAggregateRoot>> Get(Expression<Func<TAggregateRoot, bool>> predicate);

Task Remove(TAggregateRoot aggregateRoot);

Task Remove(IEnumerable<TAggregateRoot> aggregateRoots);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

namespace EasyWay.Internals.Repositories
{
internal sealed class WriteGenericRepository<TAggregateRoot> : IWriteGenericRepository<TAggregateRoot>
internal sealed class GenericRepository<TAggregateRoot> : IGenericRepository<TAggregateRoot>
where TAggregateRoot : AggregateRoot
{
private readonly DbSet<TAggregateRoot> _aggregateRoots;

public WriteGenericRepository(DbContext dbContext)
public GenericRepository(DbContext dbContext)
{
_aggregateRoots = dbContext.Set<TAggregateRoot>();
}
Expand Down Expand Up @@ -48,6 +48,11 @@ public Task<int> Count(Expression<Func<TAggregateRoot, bool>> predicate)
return _aggregateRoots.FindAsync(id).AsTask();
}

public async Task<IEnumerable<TAggregateRoot>> Get(Expression<Func<TAggregateRoot, bool>> predicate)
{
return await _aggregateRoots.Where(predicate).ToListAsync();
}

public Task Remove(TAggregateRoot aggregateRoot)
{
_aggregateRoots.Remove(aggregateRoot);
Expand Down
Loading