Azure NoSQL in ASP.NET Core 2.0


How to use Azure NoSQL database in ASP.NET Core.


Create a class library and add NuGet package: Microsoft.Azure.DocumentDB.Core

Add a class to encapsulate settings:

Add a class for repository, which will work with a generic type. Add a constructor and private methods to initialise the Azure client:

Add methods to get one or more items:

Now add public methods for the repository:

Inject and use repository:

In ASP.NET Core Web Application, configure services:


The sample code will require you to setup Azure account, NoSQL database and collection. Instructions for these could be found at:

Source Code


Leave a Reply