Building Blazor ”Hello, Blinky” IoT Application

Build your Blazor IoT app in the blink of an eye!

I thought my first ASP.NET Core edition of Hello, Blinky would be my last, at least for a long time. But then something reminded me of Blazor, and I thought why not build a Blazor edition of Hello, Blinky for Windows IoT Core and Raspberry Pi? After some hacking, I made it work. Here's my Hello, Blinky for Blazor.

You may also like: Building an ASP.NET Core ''Hello, Blinky'' IoT Application

Who the Heck Is Hello, Blinky?

Hello, Blinky is sort of like the "Hello, World" from Raspberry Pi and other microboards. While it's possible to do a "Hello, World" with these boards, why not do something more interesting with connected electronics? Isn't that what those boards were made for anyway?

Dependency Injection in Azure Functions

Azure Functions V2 supports ASP.NET Core functions like dependency injection. It is especially good if we write wrapper functions for shared libraries and components we are also using in web and other applications of our solution. This blog post shows how to use dependency injection in Azure Functions.

To get started with the code, check out Azure Functions with DI GitHub repository by @MikaBerglund. It's simple and minimal Visual Studio solution without any overhead.

HttpClient: How to Remove Charset From Content-Type Header

I was writing a client library for one online service and faced a situation where I had to remove the charset definition from the Content-Type header. It was like the content type was an application/json or the response was a 415 "Unsupported media type." I was using the HttpClient class to communicate with the service and without any additional effort charset doesn't go away. Here is how I got the charset definition away from the Content-Type header.

Problem

My problematic code was similar to the code shown here.

Building Blazor Shared Components

Blazor has experimental support for shared components. Developers can build application-agnostic Blazor components and, when packed with a Blazor shared components library, these components can be shared between Blazor applications. This blog post shows how to build shared Blazor components.

Prerequisites

This blog post was written when the following prerequisites were valid:

Writing to a CSV File From Multiple Threads

I was writing document and metadata exporter that reads data from SharePoint and writes it to multiple files. I needed to boost up performance of my exporter and I went with multiple threads pumping out the data from SharePoint. One problem I faced — writing metadata to CSV files from multiple threads in parallel. This blog post shows how to do it using concurrent queues.

This posting uses CsvHelper library to write objects to CSV-files. Last time I covered this library in my blog post Generating CSV-files on .NET.

File Uploads in ASP.NET Core Integration Tests

Writing integration tests for ASP.NET Core controller actions used for file uploads is not a rare need. It is fully supported by ASP.NET Core integration tests system. This post shows how to write integration tests for single and multiple file uploads.

Getting Started

Suppose we have controller action for file upload that supports multiple files. It uses a complex composite command for image file analysis and saving. Command is injected to action by framework-level dependency injection using controller action injection.

Using ASP.NET Core Identity Users in Integration Tests

I have an application that uses ASP.NET Core Identity with classic logins and there's a need to cover this application with integration tests. Some tests are for anonymous users and others for authenticated users. This blog post shows how to set selectively set authenticated ASP.NET Core user identities for ASP.NET Core integration tests.

Getting Started

We start with an ASP.NET Core web application where basic authentication is done using ASP.NET Core Identity. There's an integration tests project that uses a fake startup class and custom appsettings.json from my blog post, Using custom startup class with ASP.NET Core integration tests. Take a look at this post as there are some additional classes defined.

Custom appsettings.json File for ASP.NET Core Integration Tests

ASP.NET Core introduced the concept of TestServer for the integration testing of web applications. Integration tests need web applications to run with all the bells and whistles to make sure that all the components work together with no flaws. Often we need special settings for integration tests as web applications cannot use live services and the easiest way to do it is to use a special appsettings.json file. This blog post shows how to do it.

Getting Started

Let's start with minimalistic integration test from ASP.NET Core integration tests document.

Conditionally Include Partial View in ASP.NET Core

I have an ASP.NET Core web application where I need to include a partial view only if it exists. The application uses areas and some areas may have their specific side menu. This blog post shows two ways to conditionally include a partial view in an ASP.NET Core layout page.

My goal is to do it the easiest way possible by using out-of-the-box things and making sure I don't create an ugly looking mess. I wanted to avoid all kinds of additional classes to wrap dirty secrets away from controllers and views.

Implementing INotifyPropertyChanged

This is a short post about how to implement INotifyPropertyChanged without using any advanced tooling. I have some small UWP applications where I'm using MVVM to separate presentation and logic. Here is how I use INotifyPropertyChanged with a base class for multiple view models.

First, one's introduction to INotifyPropertyChanged comes usually through some existing view model. The interface is used to communicate to the view that some properties in the view model have changed. Take a look at thePropertyChanged event and theNotifyPropertyChanged method (this method is not part of the interface).

ASP.NET Core Code Coverage Reports On Azure DevOps

After making ASP.NET Core code coverage reports work on a local box, I took it a step further and made code coverage reports available also on Azure DevOps. This blog post shows how to generate code coverage reports for .NET and ASP.NET Core applications on Azure DevOps.

Getting Started

This blog post expects that there is .NET or ASP.NET Core project with unit tests and code coverage reports. It also assumes the existence of an Azure DevOps build pipeline that is connected to a source code repository. It's covered well on a previous blog post about automated testing, "Code coverage reports for ASP.NET Core."

Code Coverage Reports for ASP.NET Core

Code coverage reports for ASP.NET Core projects are not provided out-of-the-box, but by using the right tools we can build decent code coverage reports. I needed code coverage reports in some of my projects and here is how I made things work using different free libraries and packages.

Getting Started

To get started, we need a test project and some NuGet packages. Test project can be a regular .NET Core library project. Adda reference to web application project and write some unit tests if you start with a new test project. We also need some NuGet packages to make things work:

Optimized Hierarchy Traverser

My first draft of hierarchy traversing component got some serious feedback, and it's time to make some changes before moving on to the next challenges. Hierarchy traverser is not optimal yet as it uses tail-call recursion and it's easy to run to Stack Overflow with it. This blog post solves this problem and prepares for the next challenges like node cache and continue-from-given-node.

Problem: Running to Stack Overflow

As reader Ants pointed out then, .NET runtime doesn't always optimize tail-call recursion and using this simple piece of code, it's possible to run to Stack Overflow fast.

Breaking Static Dependency: How to Make Code Testable


Static dependency can be a nightmare for developers who write tests for their code. There is not much to do to get rid of static dependencies if they come with third-party libraries or NuGet packages. This blog post introduces two tricks to make code with static dependencies testable.

As a sample, I take one piece of non-commercial code that has a famous static dependency.

Dependency Injection in .NET Core Console Applications

ASP.NET Core uses a built-in dependency injection mechanism provided by Microsoft. This blog post introduces how to use the same mechanism in .NET Core console applications. For those who like other DI/IoC frameworks, this article provides a demo about how to use Autofac with .NET Core framework-level dependency injection.

Framework-Level Dependency Injection in ASP.NET Core

I don't describe here details of dependency injection in ASP.NET Core. Those who want to find out more about it can skim through these writings: