Becoming a software developer – episode XXI

Becoming a software developer – episode XXI

Welcome to the twenty-first episode of my course “Becoming a software developer” in which we will use MongoDB which is a NoSQL database for storing the data of our application.

All of the materials including videos and sample projects can be downloaded from here.
The source code repository is being hosted on GitHub.


 

Scope

  • MongoDB

Abstract

MongoDB

This is one of the most popular NoSQL databases in the world. Beware that NoSQL is just a catchy buzzword – there are many different NoSQL databases with totally unique behavior and destination. Basically, whenever you hear NoSQL, you should think about data storage where you can put the data in a so-called collection that does not require any particular schema and is very flexible. Quite often JSON is used as the primary data type for storing the documents. Opposite to the SQL database, usually, NoSQL databases do not handle transactions and reference keys. On the other hand, it’s quite simple to map even 1:1 class to the document stored within such database which makes them a very interesting choice as the primary data storage type for the variety of applications. To connect to the database, you can use Robomongo which is a free GUI client.

In order to start with MongoDB and .NET Core, it is required to install MongoDB.Driver. Once completed, we can create custom MongoSettings, configure the IoC module and implement the actual repository for the users:

Before we start using our brand new Mongo repository, let’s create so-called conventions and initialize them in a Startup class:

Eventually, we can secure the database by adding user to it and then fix the connection string property within the application settings:

Next

In the next episode, we will use the SQL Server and Entity Framework Core to store the data in a typical SQL Server database.

7 Comments Becoming a software developer – episode XXI

  1. Pingback: Dew Drop - June 15, 2017 (#2501) - Morning Dew

  2. YueYaNg

    你好!
    hi, in these articles, you add services with Autofac by RegisterModule. And In “.NET Core Microservices” , you do these just with extension methods by AddSingleton or AddScoped. What’s the difference and which one is recommended?

    Reply
    1. Piotr Gankiewicz

      Hi, under the hood you will achieve the same, the question is do you need a more advanced IoC container such as Autofac for your project. If that’s the case, go for this one.

      Reply
      1. YueYaNg

        Hi, now in the .net core 2.0, running “.NET Core Microservices” ‘s code directly would cause an exception when it calls “app.ApplicationServices.GetService()…” in the Configure() method. And i heard init database in the Configure() is not recommended now. So I have 2 questions. 1, How to get services in the Configure() in .net core 2.0? 2, How to init database with standard way in .net core 2.0?

        Reply

Leave A Comment

Your email address will not be published. Required fields are marked *