Changed parts of how data project stucture
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BrightGlimmer.CQRS\BrightGlimmer.Cqrs.csproj" />
|
||||
<ProjectReference Include="..\BrightGlimmer.CQRS\BrightGlimmer.Services.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -13,9 +13,9 @@ namespace BrightGlimmer.Api.Controllers
|
||||
public class StudentController : ControllerBase
|
||||
{
|
||||
// private readonly IMediator mediator;
|
||||
private readonly SqliteStudentRepository studentRepository;
|
||||
private readonly StudentRepository studentRepository;
|
||||
|
||||
public StudentController(SqliteStudentRepository studentRepository)
|
||||
public StudentController(StudentRepository studentRepository)
|
||||
{
|
||||
this.studentRepository = studentRepository;
|
||||
}
|
||||
|
||||
@@ -32,10 +32,9 @@ 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<SqliteStudentRepository, SqliteStudentRepository>(); /* REMOVE LATER */
|
||||
services.AddScoped<MongoStudentRepository, MongoStudentRepository>(); /* REMOVE LATER */
|
||||
services.AddDbContext<SqliteDatabaseContext>(options => options.UseSqlite(Configuration.GetConnectionString("DefaultConnection")));
|
||||
services.AddTransient<SqliteDatabaseContext>();
|
||||
services.AddScoped<StudentRepository, StudentRepository>(); /* REMOVE LATER */
|
||||
services.AddDbContext<SqliteContext>(options => options.UseSqlite(Configuration.GetConnectionString("DefaultConnection")));
|
||||
services.AddTransient<SqliteContext>();
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
@@ -56,7 +55,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<SqliteDatabaseContext>();
|
||||
var context = serviceScope.ServiceProvider.GetRequiredService<SqliteContext>();
|
||||
context.Database.EnsureCreated();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,18 +4,14 @@
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Domain\Interfaces\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.2.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.4" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
|
||||
<PackageReference Include="mongocsharpdriver" Version="2.8.0" />
|
||||
<PackageReference Include="RabbitMQ.Client" Version="5.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Interfaces\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
@@ -7,13 +6,9 @@ namespace BrightGlimmer.Data.Domain
|
||||
{
|
||||
public class Phone
|
||||
{
|
||||
[BsonElement("Id")]
|
||||
public Guid Id { get; set; }
|
||||
[BsonElement("Type")]
|
||||
public PhoneType Type { get; set; }
|
||||
[BsonElement("AreaCode")]
|
||||
public int AreaCode { get; set; }
|
||||
[BsonElement("Number")]
|
||||
public int Number { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
@@ -7,17 +6,11 @@ namespace BrightGlimmer.Data.Domain
|
||||
{
|
||||
public class Student
|
||||
{
|
||||
[BsonElement("Id")]
|
||||
public Guid Id { get; set; }
|
||||
[BsonElement("FirstName")]
|
||||
public string FirstName { get; set; }
|
||||
[BsonElement("MiddleName")]
|
||||
public string MiddleName { get; set; }
|
||||
[BsonElement("LastName")]
|
||||
public string LastName { get; set; }
|
||||
[BsonElement("Email")]
|
||||
public string Email { get; set; }
|
||||
[BsonElement("Phones")]
|
||||
public List<Phone> Phones { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
namespace BrightGlimmer.Data.Migrations
|
||||
{
|
||||
[DbContext(typeof(SqliteDatabaseContext))]
|
||||
[DbContext(typeof(SqliteContext))]
|
||||
[Migration("20190420001348_CreateDatabase")]
|
||||
partial class CreateDatabase
|
||||
{
|
||||
|
||||
@@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
namespace BrightGlimmer.Data.Migrations
|
||||
{
|
||||
[DbContext(typeof(SqliteDatabaseContext))]
|
||||
[DbContext(typeof(SqliteContext))]
|
||||
partial class SqliteDatabaseContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
using BrightGlimmer.Data.Domain;
|
||||
using MongoDB.Driver;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace BrightGlimmer.Data.Repositories
|
||||
{
|
||||
public class MongoStudentRepository
|
||||
{
|
||||
private const string dbName = "bright_glimmer";
|
||||
private const string collectionName = "Students";
|
||||
private IMongoDatabase db;
|
||||
|
||||
public MongoStudentRepository()
|
||||
{
|
||||
var client = new MongoClient("mongodb://localhost:27017"); /* REMOVE LATER */
|
||||
db = client.GetDatabase(dbName);
|
||||
}
|
||||
|
||||
public List<Student> GetStudents()
|
||||
{
|
||||
return db.GetCollection<Student>(collectionName).Find(x => true).ToList();
|
||||
}
|
||||
|
||||
public Student GetStudent(Guid id)
|
||||
{
|
||||
return db.GetCollection<Student>(collectionName).Find(student => student.Id == id).SingleOrDefault();
|
||||
}
|
||||
|
||||
public Student GetStudentByEmail(string email)
|
||||
{
|
||||
return db.GetCollection<Student>(collectionName).Find(student => student.Email == email).Single();
|
||||
}
|
||||
|
||||
public void Create(Student student)
|
||||
{
|
||||
db.GetCollection<Student>(collectionName).InsertOne(student);
|
||||
}
|
||||
|
||||
public void Update(Student student)
|
||||
{
|
||||
var filter = Builders<Student>.Filter.Where(x => x.Id == student.Id);
|
||||
db.GetCollection<Student>(collectionName).ReplaceOne(filter, student);
|
||||
}
|
||||
|
||||
public void Remove(Guid id)
|
||||
{
|
||||
var filter = Builders<Student>.Filter.Where(x => x.Id == id);
|
||||
var operation = db.GetCollection<Student>(collectionName).DeleteOne(filter);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,12 +7,12 @@ using System.Text;
|
||||
|
||||
namespace BrightGlimmer.Data.Repositories
|
||||
{
|
||||
public class SqliteStudentRepository
|
||||
public class StudentRepository
|
||||
{
|
||||
private readonly SqliteDatabaseContext context;
|
||||
private readonly SqliteContext context;
|
||||
|
||||
|
||||
public SqliteStudentRepository(SqliteDatabaseContext context)
|
||||
public StudentRepository(SqliteContext context)
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
@@ -6,9 +6,9 @@ using System.Text;
|
||||
|
||||
namespace BrightGlimmer.Data
|
||||
{
|
||||
public class SqliteDatabaseContext : DbContext
|
||||
public class SqliteContext : DbContext
|
||||
{
|
||||
public SqliteDatabaseContext(DbContextOptions<SqliteDatabaseContext> options)
|
||||
public SqliteContext(DbContextOptions<SqliteContext> options)
|
||||
: base(options)
|
||||
{
|
||||
}
|
||||
@@ -3,13 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.28803.156
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BrightGlimmer.Api", "BrightGlimmer.Api\BrightGlimmer.Api.csproj", "{3E910B69-E79C-4418-BD6B-7ABB72ECF463}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BrightGlimmer.Api", "BrightGlimmer.Api\BrightGlimmer.Api.csproj", "{3E910B69-E79C-4418-BD6B-7ABB72ECF463}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BrightGlimmer.Services", "BrightGlimmer.Services\BrightGlimmer.Services.csproj", "{AAB743E1-637F-45CF-A013-A1E612FF95C6}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BrightGlimmer.Data", "BrightGlimmer.Data\BrightGlimmer.Data.csproj", "{E14193BB-31C7-4E3B-81F0-A930B866EC5D}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BrightGlimmer.Data", "BrightGlimmer.Data\BrightGlimmer.Data.csproj", "{E14193BB-31C7-4E3B-81F0-A930B866EC5D}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BrightGlimmer.Cqrs", "BrightGlimmer.CQRS\BrightGlimmer.Cqrs.csproj", "{AA6A646D-C493-43DC-BBE4-FF253852D9BF}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BrightGlimmer.Services", "BrightGlimmer.CQRS\BrightGlimmer.Services.csproj", "{AA6A646D-C493-43DC-BBE4-FF253852D9BF}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@@ -21,10 +19,6 @@ Global
|
||||
{3E910B69-E79C-4418-BD6B-7ABB72ECF463}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{3E910B69-E79C-4418-BD6B-7ABB72ECF463}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{3E910B69-E79C-4418-BD6B-7ABB72ECF463}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{AAB743E1-637F-45CF-A013-A1E612FF95C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{AAB743E1-637F-45CF-A013-A1E612FF95C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{AAB743E1-637F-45CF-A013-A1E612FF95C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{AAB743E1-637F-45CF-A013-A1E612FF95C6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{E14193BB-31C7-4E3B-81F0-A930B866EC5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E14193BB-31C7-4E3B-81F0-A930B866EC5D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E14193BB-31C7-4E3B-81F0-A930B866EC5D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
|
||||
Reference in New Issue
Block a user