Refactored repositories and fixed service injections
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using BrightGlimmer.Data.Domain;
|
||||
using BrightGlimmer.Data.Interfaces;
|
||||
using BrightGlimmer.Data.Interfaces;
|
||||
using BrightGlimmer.Domain;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
|
||||
@@ -5,7 +5,7 @@ using System.Text;
|
||||
|
||||
namespace BrightGlimmer.Data.Interfaces
|
||||
{
|
||||
public interface IRepository<T>
|
||||
public interface ICommandRepository<T>
|
||||
{
|
||||
IUnitOfWork UnitOfWork { get; }
|
||||
|
||||
16
BrightGlimmer.Data/Interfaces/IQueryRepository.cs
Normal file
16
BrightGlimmer.Data/Interfaces/IQueryRepository.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace BrightGlimmer.Data.Interfaces
|
||||
{
|
||||
public interface IQueryRepository<T>
|
||||
{
|
||||
IUnitOfWork UnitOfWork { get; }
|
||||
|
||||
IQueryable<T> Get();
|
||||
|
||||
T Get(Guid id);
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
namespace BrightGlimmer.Data.Migrations
|
||||
{
|
||||
[DbContext(typeof(SqliteContext))]
|
||||
[DbContext(typeof(BgContext))]
|
||||
[Migration("20190420001348_CreateDatabase")]
|
||||
partial class CreateDatabase
|
||||
{
|
||||
|
||||
@@ -8,13 +8,13 @@ using System.Text;
|
||||
|
||||
namespace BrightGlimmer.Data.Repositories
|
||||
{
|
||||
public abstract class Repository<T> : IRepository<T> where T : Entity
|
||||
public class CommandRepository<T> : ICommandRepository<T> where T : Entity
|
||||
{
|
||||
public IUnitOfWork UnitOfWork => context;
|
||||
|
||||
protected BgContext context;
|
||||
protected readonly BgContext context;
|
||||
|
||||
public Repository(BgContext context)
|
||||
public CommandRepository(BgContext context) /* TODO: Change way we inject context later */
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
31
BrightGlimmer.Data/Repositories/QueryRepository.cs
Normal file
31
BrightGlimmer.Data/Repositories/QueryRepository.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using BrightGlimmer.Data.Interfaces;
|
||||
using BrightGlimmer.Domain;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace BrightGlimmer.Data.Repositories
|
||||
{
|
||||
public class QueryRepository<T> : IQueryRepository<T> where T : Entity
|
||||
{
|
||||
public IUnitOfWork UnitOfWork => context;
|
||||
|
||||
protected readonly BgContext context;
|
||||
|
||||
public QueryRepository(BgContext context) /* TODO: Change way we inject context later */
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public virtual IQueryable<T> Get()
|
||||
{
|
||||
return context.Set<T>();
|
||||
}
|
||||
|
||||
public virtual T Get(Guid id)
|
||||
{
|
||||
return context.Set<T>().Find(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,8 +8,8 @@ using System.Text;
|
||||
|
||||
namespace BrightGlimmer.Data.Repositories
|
||||
{
|
||||
public class StudentRepository : Repository<Student>
|
||||
public class StudentQueryRepository : QueryRepository<Student>
|
||||
{
|
||||
public StudentRepository(BgContext context) : base(context) { }
|
||||
public StudentQueryRepository(BgContext context) : base(context) { }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user