"
ASP.NET (snapshot 2017) Microsoft documentation and samples

Register the database context

In this step, the database context is registered with the (xref:)dependency injection container. Services (such as the DB context) that are registered with the dependency injection (DI) container are available to the controllers.

Register the DB context with the service container using the built-in support for (xref:)dependency injection. Replace the contents of the Startup.cs file with the following code:

[!code-csharpMain]

   1:  using Microsoft.AspNetCore.Builder;
   2:  using Microsoft.EntityFrameworkCore;
   3:  using Microsoft.Extensions.DependencyInjection;
   4:  using TodoApi.Models;
   5:   
   6:  namespace TodoApi
   7:  {
   8:      public class Startup
   9:      {       
  10:          public void ConfigureServices(IServiceCollection services)
  11:          {
  12:              services.AddDbContext<TodoContext>(opt => opt.UseInMemoryDatabase("TodoList"));
  13:              services.AddMvc();
  14:          }
  15:   
  16:          public void Configure(IApplicationBuilder app)
  17:          {
  18:              app.UseMvc();
  19:          }
  20:      }
  21:  }

The preceding code:



Comments ( )
Link to this page: //www.vb-net.com/AspNet-DocAndSamples-2017/aspnetcore/includes/webApi/register_dbContext.htm
< THANKS ME>