WIP setting up new data project structure and event handlers

This commit is contained in:
2019-04-23 17:42:16 +00:00
parent 49f6ee5542
commit a437573af0
18 changed files with 196 additions and 85 deletions

View File

@@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BrightGlimmer.Data.Repositories; /* REMOVE LATER */
using MediatR;
using Microsoft.AspNetCore.Mvc;
@@ -12,18 +11,17 @@ namespace BrightGlimmer.Api.Controllers
[ApiController]
public class StudentController : ControllerBase
{
// private readonly IMediator mediator;
private readonly StudentRepository studentRepository;
private readonly IMediator mediator;
public StudentController(StudentRepository studentRepository)
public StudentController(IMediator mediator)
{
this.studentRepository = studentRepository;
this.mediator = mediator;
}
[HttpGet]
public IActionResult GetAll()
{
var customers = studentRepository.GetAll();
var customers = mediator.GetAll();
if (customers == null)
{
return NotFound();
@@ -32,28 +30,28 @@ namespace BrightGlimmer.Api.Controllers
return new ObjectResult(customers);
}
[HttpGet("createstudent")]
public IActionResult CreateStudent()
{
var created = studentRepository.Create(new Data.Domain.Student
{
Id = Guid.NewGuid(),
FirstName = "Giovani",
LastName = "Rodriguez",
Email = "giovaniluisrodriguez@gmail.com",
Phones = new List<Data.Domain.Phone>
{
new Data.Domain.Phone
{
Id = Guid.NewGuid(),
AreaCode = 305,
Number = 8888888,
Type = Data.Domain.PhoneType.HOMEPHONE
}
}
});
//[HttpGet("createstudent")]
//public IActionResult CreateStudent()
//{
// var created = studentRepository.Create(new Data.Domain.Student
// {
// Id = Guid.NewGuid(),
// FirstName = "Giovani",
// LastName = "Rodriguez",
// Email = "giovaniluisrodriguez@gmail.com",
// Phones = new List<Data.Domain.Phone>
// {
// new Data.Domain.Phone
// {
// Id = Guid.NewGuid(),
// AreaCode = 305,
// Number = 8888888,
// Type = Data.Domain.PhoneType.HOMEPHONE
// }
// }
// });
return new ObjectResult(created);
}
// return new ObjectResult(created);
//}
}
}

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BrightGlimmer.Data;
using BrightGlimmer.Data.Interfaces;
using BrightGlimmer.Data.Repositories; /* REMOVE LATER */
using MediatR;
using Microsoft.AspNetCore.Builder;
@@ -31,10 +32,10 @@ namespace BrightGlimmer.Api
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.AddMediatR();
services.AddMediatR(typeof(Cqrs.Cqrs).Assembly); // Registers handlers in Cqrs project
services.AddScoped<StudentRepository, StudentRepository>(); /* REMOVE LATER */
services.AddDbContext<SqliteContext>(options => options.UseSqlite(Configuration.GetConnectionString("DefaultConnection")));
services.AddTransient<SqliteContext>();
services.AddMediatR(typeof(Cqrs.Cqrs).Assembly); // Registers handlers in services project
services.AddScoped(typeof(IRepository<>)); /* FIGURE OUT LATER */
services.AddDbContext<BgContext>(options => options.UseSqlite(Configuration.GetConnectionString("DefaultConnection")));
services.AddTransient<BgContext>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@@ -55,7 +56,7 @@ namespace BrightGlimmer.Api
// Makes sure that the database is in fact created
using (var serviceScope = app.ApplicationServices.GetService<IServiceScopeFactory>().CreateScope())
{
var context = serviceScope.ServiceProvider.GetRequiredService<SqliteContext>();
var context = serviceScope.ServiceProvider.GetRequiredService<BgContext>();
context.Database.EnsureCreated();
}
}