Restructured query repositries to move ef logic from handlers

This commit is contained in:
2019-04-27 00:02:55 -04:00
parent 7be4075222
commit 1a95acac01
18 changed files with 169 additions and 59 deletions

View File

@@ -1,6 +1,7 @@
using System.Threading.Tasks;
using System;
using System.Threading.Tasks;
using BrightGlimmer.Service.Commands;
using BrightGlimmer.Services.Queries;
using BrightGlimmer.Service.Queries;
using MediatR;
using Microsoft.AspNetCore.Mvc;
@@ -18,12 +19,20 @@ namespace BrightGlimmer.Api.Controllers
}
[HttpGet]
public async Task<ActionResult> GetAll()
public async Task<ActionResult> Get()
{
var students = await mediator.Send(new GetAllStudentsQuery());
var students = await mediator.Send(new GetStudentsQuery());
return new JsonResult(students);
}
[HttpGet]
[Route("{id}")]
public async Task<ActionResult> Get(Guid id)
{
var student = await mediator.Send(new GetStudentQuery(id));
return new JsonResult(student);
}
[HttpPost]
public async Task<ActionResult> Create([FromBody]CreateStudentCommand command)
{

View File

@@ -1,6 +1,7 @@
using BrightGlimmer.Data;
using BrightGlimmer.Data.Interfaces;
using BrightGlimmer.Data.Repositories;
using BrightGlimmer.Domain;
using MediatR;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
@@ -31,6 +32,8 @@ namespace BrightGlimmer.Api
services.AddTransient(typeof(IQueryRepository<>), typeof(QueryRepository<>));
services.AddTransient(typeof(ICommandRepository<>), typeof(CommandRepository<>));
services.AddTransient(typeof(IQueryRepository<Student>), typeof(StudentQueryRepository));
services.AddDbContext<BgContext>(options => options.UseSqlite(Configuration.GetConnectionString("DefaultConnection")));
services.AddTransient<BgContext, BgContext>();
}