Thursday, January 17, 2019

Working with NuGet packages

This article presents NuGet packages, discusses what they are, what features they have, and how they can be used.

In general, a NuGet package (or bundle) is a file which contains code that can be re-used in various projects. If you have a project that you want to use many times, it may be good to create a NuGet package, especially if you plan to give the project to a third party.

[...] a NuGet package is a single ZIP file with the .nupkg extension that contains compiled code (DLLs), other files related to that code, and a descriptive manifest that includes information like the package's version number [Microsoft Docs].

NuGet packages are created and used in Visual Studio.

A .nupkg file is a NuGet package.

A .nupkg file is a .zip file. If you change the extension of a .nupkg file to .zip, you will be able to view the dll assemblies view inside of the package.

.nupkg files are built from .nuspec files, and the latter are built from .dll files.

Wednesday, January 9, 2019

Make money blogging as a programmer

You can earn good money by blogging. This is a rule of thumb, but the way to the point of actually earning is long and winding. Just as in any other niche.

For a programmer, it is usually easier to just find a job and show family and friends that you can do something to pay the bills. Attempting to do a similar thing by blogging is not the way they would like to see you. However, if you put enough time and effort to publishing good posts, your blog will finally become well-known and the money will come with this.

It is essential to note that the money you receive from blogging is a passive income, which means that it comes whether you constantly work on your posts or you have many posts already published and now you can finally go to sleep. Usually, though, the money is rather meagre; if you aim at a good monthly salary, you have to become a full-time blog writer who can come up with very original ideas every once in a while and you need a bit of luck!

If you can write one good blog post every day, it is already a good start. The more good and long posts you have, the more probable it is that many people will visit your blog. And the more people visit your blog with good posts, the more possible it is that they will advertise it and make you rank higher in the search engines.

Friday, January 4, 2019

Using Dapper in ASP.NET Core

Dapper is a free micro-ORM which can be used in any ASP.NET application to communicate with the database.

Dapper is free, simple, small, and very fast – its distributors claim that it is almost just as fast as the raw ADO.NET Data Reader!  At the same time, it is much clearer and intuitive for the developer. Besides, its set of methods works with any database in a similar way: you don't need to use separate methods for MS SQL database, MySQL, Oracle, PostgreSQL, and so on.

The logic behind how Dapper works can be explained in 3 simple steps:
  • You create an IDbConnection object (Dapper extends the IDbConnection interface from the System.Data namespace);
  • You write a query to perform a CRUD (Create, Read, Update, Delete) operation;
  • You call the Execute() method, passing the query as its parameter.
In order to use it in you project, you need to install Dapper from NuGet Package Manager, for instance by writing the following command in the Package Manager Console in Visual Studio:

PM> Install-Package Dapper -Version 1.50.5


After a successful installation, you can create POCO classes from SQL databases, and you can also create C# methods from SQL procedures. In order to do this, you have to create a file with a .tt extension, and add it anywhere in the project folder. The .tt file will automatically generate classes and other necessary elements in a .cs file which it will create.

Methods offered by Dapper are:
  • Execute()
  • Query()
  • QueryFirst()
  • QueryFirstOrDefault()
  • QuerySingle()
  • QuerySingleOrDefault()
  • QueryMultiple()
Parameters passed to Dapper's methods may be:
  • anonymous (using var);
  • dynamic (using a DynamicParameters object);
  • list;
  • string.
The result of a Dapper's method may be of the following types:
  • anonymous;
  • strongly typed;
  • multi-mapping;
  • multi-result;
  • multi-type.