From ed50d9a138b9e2cd6b5ce911617963e3eaeda31b Mon Sep 17 00:00:00 2001 From: Jim Stott Date: Mon, 18 Mar 2019 10:39:26 -0400 Subject: [PATCH] Add missing scoped repo's and dbContext to startup.cs (#11425) --- .../samples/WebApiSample.Api.22/Startup.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/aspnetcore/web-api/define-controller/samples/WebApiSample.Api.22/Startup.cs b/aspnetcore/web-api/define-controller/samples/WebApiSample.Api.22/Startup.cs index bb409d4ccf..49306f92ca 100644 --- a/aspnetcore/web-api/define-controller/samples/WebApiSample.Api.22/Startup.cs +++ b/aspnetcore/web-api/define-controller/samples/WebApiSample.Api.22/Startup.cs @@ -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(); + services.AddScoped(); + + services.AddDbContext(opt => + opt.UseInMemoryDatabase("ProductInventory")); + services.AddDbContext(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