Add missing scoped repo's and dbContext to startup.cs (#11425)

pull/11534/head
Jim Stott 2019-03-18 10:39:26 -04:00 committed by Scott Addie
parent 107a15841e
commit ed50d9a138
1 changed files with 12 additions and 1 deletions

View File

@ -1,8 +1,11 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using WebApiSample.DataAccess;
using WebApiSample.DataAccess.Repositories;
#region snippet_ApiControllerAttributeOnAssembly
[assembly: ApiController]
@ -20,6 +23,14 @@ namespace WebApiSample.Api._22
public void ConfigureServices(IServiceCollection services)
{
services.AddScoped<ProductsRepository>();
services.AddScoped<PetsRepository>();
services.AddDbContext<ProductContext>(opt =>
opt.UseInMemoryDatabase("ProductInventory"));
services.AddDbContext<PetContext>(opt =>
opt.UseInMemoryDatabase("PetInventory"));
#region snippet_ConfigureApiBehaviorOptions
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
@ -30,7 +41,7 @@ namespace WebApiSample.Api._22
options.SuppressModelStateInvalidFilter = true;
options.SuppressMapClientErrors = true;
options.ClientErrorMapping[404].Link =
options.ClientErrorMapping[404].Link =
"https://httpstatuses.com/404";
});
#endregion