Commit ac6fbd12 authored by Steve Smith's avatar Steve Smith

Configured web to use inmemory

Set up basic list of items and populate method
parent c841e0c4
namespace CleanArchitecture.Core.SharedKernel
{
public abstract class ValueObject
{
}
}
\ No newline at end of file
...@@ -19,7 +19,29 @@ namespace CleanArchitecture.Web.Controllers ...@@ -19,7 +19,29 @@ namespace CleanArchitecture.Web.Controllers
public IActionResult Index() public IActionResult Index()
{ {
return View(); var items = _todoRepository.List();
return View(items);
}
public IActionResult Populate()
{
if (_todoRepository.List().Any()) return Ok(0);
_todoRepository.Add(new ToDoItem()
{
Title = "One",
Description = "The first item"
});
_todoRepository.Add(new ToDoItem()
{
Title = "Two",
Description = "The second item"
});
_todoRepository.Add(new ToDoItem()
{
Title = "Three",
Description = "The three item"
});
return Ok(3);
} }
} }
} }
using CleanArchitecture.Core.Interfaces; using System;
using CleanArchitecture.Core.Interfaces;
using CleanArchitecture.Core.Entities;
using CleanArchitecture.Core.SharedKernel;
using CleanArchitecture.Infrastructure; using CleanArchitecture.Infrastructure;
using CleanArchitecture.Infrastructure.Data; using CleanArchitecture.Infrastructure.Data;
using CleanArchitecture.Infrastructure.DomainEvents; using CleanArchitecture.Infrastructure.DomainEvents;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using StructureMap;
using StructureMap.AutoMocking;
namespace CleanArchitecture.Web namespace CleanArchitecture.Web
{ {
...@@ -26,17 +32,41 @@ namespace CleanArchitecture.Web ...@@ -26,17 +32,41 @@ namespace CleanArchitecture.Web
public IConfigurationRoot Configuration { get; } public IConfigurationRoot Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container. // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) public IServiceProvider ConfigureServices(IServiceCollection services)
{ {
// Add framework services. // Add framework services.
// TODO: Add DbContext and IOC // TODO: Add DbContext and IOC
services.AddDbContext<AppDbContext>(options => services.AddDbContext<AppDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); options.UseInMemoryDatabase());
//options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddMvc(); services.AddMvc();
services.AddTransient<IDomainEventDispatcher, DomainEventDispatcher>(); var container = new Container();
container.Configure(config =>
{
config.Scan(_ =>
{
_.AssemblyContainingType(typeof(Startup)); // Web
_.AssemblyContainingType(typeof(BaseEntity)); // Core
_.Assembly("CleanArchitecture.Infrastructure"); // Infrastructure
_.WithDefaultConventions();
_.ConnectImplementationsToTypesClosing(typeof(IHandle<>));
});
// ToDo: Add Registry Classes
// TODO: Move to Infrastucture Registry
config.For(typeof(IRepository<>)).Add(typeof(EfRepository<>));
//Populate the container using the service collection
config.Populate(services);
});
return container.GetInstance<IServiceProvider>();
services.AddTransient<IRepository<ToDoItem>, EfRepository<ToDoItem>>();
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
......
@{
ViewData["Title"] = "ToDo List";
}
@model IEnumerable<CleanArchitecture.Core.Entities.ToDoItem>
<h2>To Do Items</h2>
<ul>
@foreach (var item in Model)
{
<li>@item.Title</li>
}
</ul>
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0", "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.AspNetCore.StaticFiles": "1.0.0", "Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0", "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
"Microsoft.EntityFrameworkCore.InMemory": "1.0.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0", "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0", "Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0", "Microsoft.Extensions.Logging": "1.0.0",
......
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