Restructured query repositries to move ef logic from handlers
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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>();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user