Skip to Content
Serverless computing in Azure with .NET
book

Serverless computing in Azure with .NET

by Sasha Rosenbaum
August 2017
Intermediate to advanced
468 pages
12h 5m
English
Packt Publishing
Content preview from Serverless computing in Azure with .NET

Dependency injection

The code in the previous section does not conform to the ASP.NET Core best practices. The best practice is to register the new service ( DbContext) during application startup, and inject it into the classes that are using it, such as MVC controllers, using Dependency Injection rather than initializing the context inline in the TextScoresDBContext class. To learn more about Dependency Injection, view the documentation at https://docs.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection.

Let's take a look at the following steps:

  1. To change the code to conform to best practice, open TextScoreDBContext.cs, and replace the following lines of code:
 protected override void OnConfiguring(DbContextOptionsBuilder ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Azure Serverless Computing

Mastering Azure Serverless Computing

Lorenzo Barbieri, Massimo Bonanni
Implementing Azure: Putting Modern DevOps to Use

Implementing Azure: Putting Modern DevOps to Use

Florian Klaffenbach, Oliver Michalski, Markus Klein, Mohamed Wali

Publisher Resources

ISBN: 9781787288393Supplemental Content