Code Maze Author

Vladimir Pecanac

Hi, my name is Vladimir Pecanac, and I am a full-time .NET developer and DevOps enthusiast. I created this blog so I can share the things I learn in the hope of both helping others and deepening my own knowledge of the topics I write about. The best way to learn is to teach.
Also find me here:


MY ARTICLES:

C# Delegates

In this article, we're going to talk about C# delegates, which are a prerequisite for learning events-based programming. Delegates are one of the fundamental building blocks of flexible applications, as they can be found in the vast majority of .NET framework code...

Events in C#

Events in C# are a mechanism that classes use to send notifications or messages to other classes. They are a specialized delegate type that we use to notify other classes when something they listen to happens. Events are a vital part of many applications, and a...

10 Things You Should Avoid in Your ASP.NET Core Controllers

Keeping controllers clean and tidy is something we've learned we should do the first time we've stumbled upon the MVC pattern. But as the project grows and other team members enter the project, things might get out of hand. Especially when deadlines need to be met,...

User Secrets vs Environment Variables in ASP.NET Core

ASP.NET Core gives us two ways to keep secrets out of source control on a development machine: user secrets, stored per project in a file outside the repository, and environment variables, stored per machine or per shell session. Both feed straight into...

Custom Configuration Provider in ASP.NET Core With EF Core

A configuration provider is the piece of ASP.NET Core that turns one source of settings (a JSON file, environment variables, a database) into flat key-value pairs the rest of the app reads through IConfiguration. A custom one is two small classes: an...

ASP.NET Core Configuration Providers

A configuration provider is one source of settings. JSON files, environment variables, command-line arguments, a key vault, a database table: each is a provider, and each contributes key-value pairs to the single dictionary the application reads through...

Options Validation in ASP.NET Core

Options validation turns a bad configuration value into a clear failure instead of a strange bug three layers down. ASP.NET Core offers three ways to write the rules and one way to decide when they run. The rules go on the options class as data annotations, in a...

Options Pattern in ASP.NET Core With IOptions

The options pattern binds a section of configuration to a class and hands that class to whatever needs it through dependency injection. Instead of asking IConfiguration for "Pages:HomePage:Color", a service asks for IOptions<TitleConfiguration> and reads .Color....

How to Use IConfiguration in ASP.NET Core

ASP.NET Core configuration is a single flat dictionary of string keys and string values, assembled at startup from several sources and read through one interface, IConfiguration. Nested JSON becomes flat keys joined by colons, so Logging:LogLevel:Default reaches the...

Dependency Injection in ASP.NET Core

In this article, we're going to talk about dependency injection, one of the most frequently used design patterns out there. There are many tutorials about dependency injection, but in this one, we're going to focus on understanding why the dependency injection is used...

A Few Different Ways to Concatenate Strings in C#

In this quick tutorial, we are going to talk about different ways to concatenate strings. Splitting and joining strings are commonly used operations in almost any real-world application, so let's see how we can concatenate strings through some examples. We won't cover...

Differences between String and string in C#

In this article, we're going to tackle the popular question among many developers, and that's "What's the difference between string and String" and "When should I use string, and when should I use String" in my applications. Both of these versions exist for a reason,...

HATEOAS in ASP.NET Core Web API

HATEOAS, Hypermedia as the Engine of Application State, is the REST constraint that says a response carries the links describing what the client can do next. Instead of building URLs from a documented template, the client reads them out of the payload it already has....

Data Shaping in ASP.NET Core Web API

Data shaping lets the client decide which fields come back. A request for /api/owners?fields=name,dateOfBirth returns owners carrying those two properties and nothing else. The pattern travels under several names. JSON:API calls it sparse fieldsets, Google's API...

Sorting in ASP.NET Core Web API With a Dynamic OrderBy

Sorting a Web API means turning a query string like ?orderBy=name,dateOfBirth desc into an ORDER BY clause the database runs. The client names the fields at request time, so the ordering cannot be written into the code ahead of it. That is the whole problem in one...

Searching in ASP.NET Core Web API With Query Parameters

Searching in a Web API means accepting a free-text term as a query parameter and narrowing the result set to the rows that contain it. One extra property on the parameters class, one Where() call in the repository, and GET /api/owners?name=anna works. Searching is not...

Filtering Data in ASP.NET Core Web API

Filtering a Web API means letting the client narrow a collection endpoint with query-string parameters the API has declared: ?minYearOfBirth=1975&maxYearOfBirth=1997 returns only the owners born in that range. This is not the same thing as an ASP.NET Core filter....

Pagination in ASP.NET Core Web API: How to Implement Paging

Pagination in an ASP.NET Core Web API means the client asks for a slice of a collection, ?pageNumber=2&pageSize=10, and the API answers with those ten records plus the numbers needed to ask for the next ten. Two things have to be built. A parameters class binds...

How to Configure PostgreSQL in Entity Framework Core

In this article, we are going to learn how to configure PostgreSQL, a popular and reliable open-source relational database, in our .NET Core application, and connect it to Entity Framework Core to utilize its full potential. If you want to learn more about Entity...