Commit 5f0182a0 authored by Steve Smith's avatar Steve Smith

Working on removing project ref from web to infrastructure

parent f2cb9398
using System.Collections.Generic;
using CleanArchitecture.Core.SharedKernel;
namespace CleanArchitecture.Core.Interfaces
{
public interface ISeedData
{
void PopulateTestData();
}
}
\ No newline at end of file
...@@ -31,9 +31,9 @@ namespace CleanArchitecture.Core.SharedKernel ...@@ -31,9 +31,9 @@ namespace CleanArchitecture.Core.SharedKernel
return !(obj1 == obj2); return !(obj1 == obj2);
} }
public bool Equals(ValueObject obj) public bool Equals(ValueObject other)
{ {
return Equals(obj as object); return Equals(other as object);
} }
public override bool Equals(object obj) public override bool Equals(object obj)
......
using CleanArchitecture.Core.Entities; using CleanArchitecture.Core.Entities;
using CleanArchitecture.Infrastructure.Data;
namespace CleanArchitecture.Web namespace CleanArchitecture.Infrastructure.Data
{ {
public static class SeedData public class SeedData
{ {
public static void PopulateTestData(AppDbContext dbContext) private readonly AppDbContext _dbContext;
public SeedData(AppDbContext dbContext)
{
_dbContext = dbContext;
}
public void PopulateTestData()
{ {
var toDos = dbContext.ToDoItems; var toDos = _dbContext.ToDoItems;
foreach (var item in toDos) foreach (var item in toDos)
{ {
dbContext.Remove(item); _dbContext.Remove(item);
} }
dbContext.SaveChanges(); _dbContext.SaveChanges();
dbContext.ToDoItems.Add(new ToDoItem() _dbContext.ToDoItems.Add(new ToDoItem()
{ {
Title = "Test Item 1", Title = "Test Item 1",
Description = "Test Description One" Description = "Test Description One"
}); });
dbContext.ToDoItems.Add(new ToDoItem() _dbContext.ToDoItems.Add(new ToDoItem()
{ {
Title = "Test Item 2", Title = "Test Item 2",
Description = "Test Description Two" Description = "Test Description Two"
}); });
dbContext.SaveChanges(); _dbContext.SaveChanges();
} }
} }
......
using CleanArchitecture.Core.Interfaces;
using CleanArchitecture.Infrastructure.Data;
using StructureMap;
namespace CleanArchitecture.Infrastructure
{
public class InfrastructureRegistry : Registry
{
public InfrastructureRegistry()
{
For(typeof(IRepository<>)).Add(typeof(EfRepository<>));
}
}
}
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\CleanArchitecture.Core\CleanArchitecture.Core.csproj" /> <ProjectReference Include="..\CleanArchitecture.Core\CleanArchitecture.Core.csproj" />
<ProjectReference Include="..\CleanArchitecture.Infrastructure\CleanArchitecture.Infrastructure.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
...@@ -27,6 +26,7 @@ ...@@ -27,6 +26,7 @@
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" /> <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" PrivateAssets="All" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0" PrivateAssets="All" /> <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0" PrivateAssets="All" />
<PackageReference Include="StructureMap.Microsoft.DependencyInjection" Version="1.4.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
......
...@@ -38,17 +38,15 @@ namespace CleanArchitecture.Web ...@@ -38,17 +38,15 @@ namespace CleanArchitecture.Web
{ {
config.Scan(_ => config.Scan(_ =>
{ {
_.AssemblyContainingType(typeof(Startup)); // Web _.AssembliesAndExecutablesFromApplicationBaseDirectory();
_.AssemblyContainingType(typeof(BaseEntity)); // Core //_.AssemblyContainingType(typeof(Startup)); // Web
_.Assembly("CleanArchitecture.Infrastructure"); // Infrastructure //_.AssemblyContainingType(typeof(BaseEntity)); // Core
//_.Assembly("CleanArchitecture.Infrastructure"); // Infrastructure
_.WithDefaultConventions(); _.WithDefaultConventions();
_.ConnectImplementationsToTypesClosing(typeof(IHandle<>)); _.ConnectImplementationsToTypesClosing(typeof(IHandle<>));
_.LookForRegistries();
}); });
// TODO: Add Registry Classes to eliminate reference to Infrastructure
// TODO: Move to Infrastucture Registry
config.For(typeof(IRepository<>)).Add(typeof(EfRepository<>));
//Populate the container using the service collection //Populate the container using the service collection
config.Populate(services); config.Populate(services);
...@@ -59,7 +57,8 @@ namespace CleanArchitecture.Web ...@@ -59,7 +57,8 @@ namespace CleanArchitecture.Web
public void ConfigureTesting(IApplicationBuilder app, public void ConfigureTesting(IApplicationBuilder app,
IHostingEnvironment env, IHostingEnvironment env,
ILoggerFactory loggerFactory) ILoggerFactory loggerFactory,
ISeedData seedData)
{ {
this.Configure(app, env, loggerFactory); this.Configure(app, env, loggerFactory);
SeedData.PopulateTestData(app.ApplicationServices.GetService<AppDbContext>()); SeedData.PopulateTestData(app.ApplicationServices.GetService<AppDbContext>());
......
...@@ -26,7 +26,7 @@ namespace CleanArchitecture.Tests.Integration.Data ...@@ -26,7 +26,7 @@ namespace CleanArchitecture.Tests.Integration.Data
// Create a new options instance telling the context to use an // Create a new options instance telling the context to use an
// InMemory database and the new service provider. // InMemory database and the new service provider.
var builder = new DbContextOptionsBuilder<AppDbContext>(); var builder = new DbContextOptionsBuilder<AppDbContext>();
builder.UseInMemoryDatabase() builder.UseInMemoryDatabase(Guid.NewGuid().ToString())
.UseInternalServiceProvider(serviceProvider); .UseInternalServiceProvider(serviceProvider);
return builder.Options; return builder.Options;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment