Automatic Build From the GitHub Repository via Jenkins

In this post, I am going to create an automatic build trigger via Jenkins Jobs. Basically, after pushing a new piece of code to the target repository/branch, Jenkins will create a new build package from the updated source code. If Jenkins has not been installed yet in your environment, I had explained “How to install Jenkins” in one of the previous articles. If you want to read it, you can access it from here.

Continue reading Automatic Build From the GitHub Repository via Jenkins

Azure Function App IHttpClientFactory Implementation

In this post, I am going to implement IHttpClientFactory to the Azure Function App and inject it to the sample function. To be able to do this, the Azure Function App should have a Startup.cs file. If your app does not have a Startup.cs file, you can use the sample from this article.

Continue reading Azure Function App IHttpClientFactory Implementation

Azure Function App Security Headers | Proxies.json

The aim of this post is to show the proxies.json file usage for the Azure Function Apps. It might be possible to use for different cases. For this case, the proxy will return some extra response headers from the function requests.

Continue reading Azure Function App Security Headers | Proxies.json

How to Write .Net Core Web Api via MongoDB on Windows Computer

Hi,

I will try to explain “How to write .net core web api via MongoDB” in this post. Firstly, I should install MongoDB to my computer. Let’s get start. I used this link for download. Example screenshot is as follows.

After downloaded application, Let’s start to install it. The screenshots are as follows.

You can cancel MongoDB Compass. I didn’t install it.

After installation, I added new value in environment variables. This is for command prompt. I used mongoDB setup location in this step. My one is C:\Program Files\MongoDB\Server\4.2\bin If you want, you can skip this step.

I added two times. First one User variables for Your Username area and second one is system variables area. You should restart your computer after this step.
Let’s check MongoDB commands. I checked some commands. First command is;

mongo

show databases

use databaseName

db.CreateCollection(“ExampleCollection”)

db.DropDatabase()

That examples are enough for now. Maybe we can check all commands in another article. Now, let’s get start to web api.

I created and opened my project. After created project, I added mongoDB driver in my project. I used command for this as follows.

dotnet add package MongoDB.Driver –version 2.9.2

You can see this package in your .csproj file.

I started from model folder for development. Firstly, I created base model file. I added Id field because mongoDB is using Id field in collections. I created base model file for this. The screenshot is as follows.

After this file, I created an example model for my web api methods.

Now, I created a base repository for my models. I will use this with my model repository.

Example model repository is as follows.

I added connection string property in appconfig.json file. I will use this in startup.cs file.

Startup.cs is as follows.

Example methods are as follows.

Now, I can see my database on command prompt.

You can download my example project in this link.

Thanks.