29 April 2023

298 links · Saturday

Why do I want to Email Myself Every Day?

After creating an Apps Script to email myself every day from a Google Sheet, someone asked: Why? Overall I find I can face the day better when I have timed reminders inside my inbox. My deep work is deeper, and almost nothing gets forgotten, when I want to ex…

ChatGPT-4 outperformed 90% developers

Discover how ChatGPT-4 surpasses 90% of developers in solving coding challenges. Explore the future and potential of AI in software development.

Drop down lists in ASP.NET MVC | no dogma blog

Full source code is a attached here. This post shows two methods of implementing drop down lists in ASP.NET MVC 4. The code for data access and the general layout of the application should not be considered suitable for anything other than pedagogical purposes…

The Circuit Breaker pattern with Polly | no dogma blog

Full source code available here. Want to learn more about Polly? Check out my Pluralsight course on it. This post on the Polly circuit breaker is part of a larger series of post on the Polly Resilience Framework, see here for the others, or check out my Plural…

Installing Rider on Linux with .NET 7 | no dogma blog

While trying to use Rider on Linux, I hit these errors "load failed", "MSBuild is required to load project 'HelloLinux' but it was not found", and "MSBuild (Microsoft Build Engine) is required to load and build project 'HelloLinux'". If you got any of these, r…

Caching in Polly and the HttpClientFactory | no dogma blog

Full source code here. Want to learn more about Polly? Check out my Pluralsight course on it. Polly allows you to cache a response for reuse by a subsequent request, it supports both local an distributed caches, full information can be found here https://githu…

Fluent Validation in ASP.NET Core | no dogma blog

Full source code available here. I have written about Fluent Validation a couple of times. There is a new library available for .Net Core. How to return to validation messages back to the caller is not immediately obvious.

Testing Your Code When Using Polly | no dogma blog

Full source code here. Want to learn more about Polly? Check out my Pluralsight course on it. When developing an application with Polly you will also probably want to write some unit tests.

The Simplest Hello World in Node.js | no dogma blog

Full source code available here. I am learning Node.js and have found it a bit of a struggle to locate good, simple documentation. It feels like most people writing in the space assume a lot of existing knowledge, like you know how plenty of JavaScript, or how…

Cached nuget packages causing you problems? | no dogma blog

Short version If you are having problems with nuget packages and think it might be related to local caching delete packages from these directories - %LocalAppData%\NuGet\Cache and %userprofile%\.nuget\packages\ Long version I was making nuget package, lets cal…

Pizza Delivery IoT Project Pt. 2

Continuing from Pizza Delivery IoT Project Pt. 1, I have completed much of the circuit design on my breadboard and completed the basic code necessary to interact with the sensors on the board. To interact with the various components on the board, I ...

Dotclear blog editing problem | no dogma blog

The dotclear blogging engine has some issues when including pre-formated html; it removes all leading spaces and mangles empty lines. This is a significant problem when posting nicely coloured code snippets like those produced by hilite.

Accidental LLM Backdoor - Prompt Tricks

In this video we explore various prompt tricks to manipulate the AI to respond in ways we want, even when the system instructions want something else. This c...

Web API 2 and ninject, how to make them work together | no dogma blog

Full source code to download. I’ve been using ninject for a few years, but every time I use it with Web Api I hit some problem and they usually stem from not including the right nuget packages, not changing the DependencyResolver or (once) forgetting how to ma…

Downloading an in-memory file using Web Api 2 | no dogma blog

Download full source code At first you think it’s going to be easy to download a file from Web Api, but as I discovered, it was not. In my case I wanted to load data from the database, perform some processing and return a subset of the data as a file.

Creating an ASCII Table with C# | no dogma blog

I was re-watching The Martian a few weeks ago. There is a scene Mark Watney needs an ASCII table, he rummages through the laptop of one of the crew to find one. This got me thinking that it should be very easy to create a table with a simple program.

Simmy Chaos Engine for .NET – Part 3, Adding Latency | no dogma blog

Full source code here. Want to learn more about Polly? Check out my Pluralsight course on it. This is the third in my series on chaos engineering with Simmy. The first two posts dealt with the fault policy throwing exceptions and returning failed responses rat…

Entity Framework Core 2 Unit Testing in .NET Core 2 | no dogma blog

Full source code available here. Unit testing Entity Framework used to be quite a chore, but over the past few years it has become significantly easier. In this post I’m going to show you how to use the InMemory database with named instances.

Web API 2 Controller with multiple get methods | no dogma blog

I have two other posts on multiple GET methods, one for ASP.NET 5 Web Api, and another for Web Api 2. It seems that every version of Web API changes how it handles default routes or route prefixes or whatever the next name will be.

Polly and Blazor, Part 3 - Dependency Injection | no dogma blog

Using Polly with Blazor is simple, as I've shown in the previous two posts. In this, I will define the Wait and Retry Policy in the `Startup`, add it to the service collection and use dependency injection to pass it into the Razor page.

Adaptive/dynamic page numbering in c# | no dogma blog

If you need to show many results (tens, hundreds or thousands), in a paged manner, you won’t want to display links to all those pages. I looked online for some c# that would adapt the number of page links shown to with the number of pages returned, but found n…

Unit Testing .NET Core 2 Web Api | no dogma blog

Full source code available here. Unit testing Web API controllers in .NET Core 2 is very easy. I have very simple GET and POST methods. 1[Route("api/[controller]")] 2public class ValuesController : Controller 3{ 4[HttpGet] 5 public async Task<IActionResult> Ge…

Reusing Polly Policies with Dependency Injection | no dogma blog

Download full source code. Want to learn more about Polly? Check out my Pluralsight course on it. In my previous post “A simple Polly example with WebApi 2” I showed how to make a request to an unreliable endpoint protected by a Polly retry policy.

AutoMapper, ProjectTo() – Static Version | no dogma blog

Full source code available here. I’ve been using AutoMapper for quite a few years, but one of the features that I like the most is the ProjectTo method. When using Entity Framework it lets me reduce the number of fields I query from the database to match the m…

Hugo Aliases Workaround with Netlify | no dogma blog

I love using Hugo and Netlify for my blog, but one thing I have not been able to get working is aliases, it might be because of a custom permalink I'm using, my slugs, or something else, but here is a workaround.

Executing a Method on All Implementations of an Interface | no dogma blog

Full source code available here. Have you ever wanted to execute a method on all implementations of an interface? Say you have an interface called IGenerator and four implementations of it – GeneratorA, GeneratorB, GeneratorC, and GeneratorD.

Unit testing Entity Framework Core Stored Procedures | no dogma blog

Full source code available here. Entity Framework Core has made unit testing CRUD functions much easier, see here for an example of using the In Memory Database, it allows you to search, add, remove and update rows.

Entity Framework Core and calling a stored procedure | no dogma blog

Download full source code here. I thought this would be easy, there is a method called ExecuteSqlCommand which takes the stored proc name and an array of parameters. I wanted to pass in two parameters and get one back, no problem, I’ve done this with ADO.

Value cannot be null. Parameter name: constructor | no dogma blog

Using Entity Framework I occasionally get the following error when reading from the database - `exceptionMessage=Value cannot be null. Parameter name: constructor` My Person class looked like this - 1 public class Person 2 { 3 public Person(string firstname, s…

Using the Polly Timeout when making a Http Request | no dogma blog

Full source code available here. Want to learn more about Polly? Check out my Pluralsight course on it. When making remote service requests the remote side will sometimes take longer than acceptable to respond.

re:Invent Session on Refactoring

Yesterday I had the honor and privilege of sharing the re:Invent stage once again with my good friend and colleague Runeet Vashisht for our session “Refactoring strategies for .NET applications as you migrate to the cloud” In this session, we were co...

How to use HttpClientFactory Inside Program.cs | no dogma blog

Full source code here. Over the past week I have written a few articles about HttpClientFactory and dependency injection in .NET Core 2.1. There is one scenario I didn’t deal with - calling a HttpClient from inside the Main method in Program.

Letting a request fail with Polly | no dogma blog

Want to learn more about Polly? Check out my Pluralsight course on it. Polly is fantastic for transparently retrying a request but there is always a point at which you must give up.

Using .NET 7 With Code Build

Introduction AWS CodeBuild is one of AWS’s core development services for creating CI/CD Pipelines. CodeBuild is a fully managed service that helps developers to create automated builds of their development projects. With CodeBuild there is no develop...

Support this site | no dogma blog

If you found this blog or podcast useful, please help support it by buying me a coffee or by using this Amazon referrer link when you buy items from Amazon. Using this link does not affect the price of the items.

Streaming your IoT Data to DynamoDB

Setting up your "Thing" in the AWS Console. This post is the third in my series IoT for the .NET Developer. You can find the companion video for this blog post here: Sending IoT Data to AWS IoT Core using .NET - YouTube. In the last post in this seri...

Building .NET 7 Applications using Amazon CodeCatalyst

This past re:Invent AWS Launched Amazon CodeCatalyst the new All-In-One DevOps service. CodeCatalyst provides you with a single pane of glass to source control management, handling pull requests, issue management and software builds. CodeCatalyst use...

Unit Testing a Method That Uses HttpClient | no dogma blog

Full source code available here. In this post I’m going to show you how to test an action method of controller that uses a HttpClient. When performing this test you want to isolate just the code of the action method for testing, you want to remove the dependen…

Using MediatR with API Endpoints | no dogma blog

The mediator pattern is very helpful for keeping business logic out of your API endpoints. This post provides a simple example of this with the MediatR library.

CastleWindsor chained dependency | no dogma blog

Source code is available here. I recently had a problem where I wanted an MVC controller to use constructor injection of specified dependency and have that dependency load another specified dependency using Windsor.

Deserializing to an enum | no dogma blog

I have an application where I deserialize an xml stream from a third party. One of the fields is a task code which can be one of only three values, insert, update and delete.

Why I blog | no dogma blog

I’ve been developing software for some years and found that simple usually beats complicated and pragmatic choices beat dogmatic ones. In this blog, I want to share some useful pieces of code and ideas.

C# and AWS Lambdas, Part 1 - Hello World | no dogma blog

First in a series of posts on using .NET with AWS Lambdas. It will start with the simplest example that converts a lowercase string to an uppercase string, but by the end, you will be running a .NET Web API powered by Lambda, fronted by an API gateway where al…

Amazon CodeCatalyst Development Environments

If you are like me, you like to be able to write code anywhere. While I pretty much always have my laptop set up with development tools, I also have a bad habit of not pushing my changes when I get done. I then pull out a different device and get rea...

Simple Func<T> and Func<T1, T2, TResult> Examples | no dogma blog

Full source code available here. About a month ago I wrote a post with a simple explanation of how to use methods that take Action or Action<T> as parameters. Actions themselves take 0 to 16 parameters and return nothing.

Saving Enums with Entity Framework Core | no dogma blog

Full source code here. A few years ago I wrote a post about saving enums to the database with Entity Framework. It was able to save the enum as a string to the database and when reading from the database it was able to take that string and populate the enum co…

Why you should use IDictionary, IList, etc | no dogma blog

Summary When returning objects from a method try to use IList, IDictionary, etc instead of List and Dictionary. This is especially important when the method is inside a class library which you distribute.

Creating an Automation Document Using C# and CDK

Introduction When you are looking to deploy infrastructure into an AWS Account, one of the best practices is to use Infrastructure as Code (IaC). This is a recommended approach because it allows the process to be repeatable, and traceable. It also al...

Let's Encrypt Cert Error and Polly Retry | no dogma blog

Let's Encrypt updated their root cert recently and now calls from some systems to APIs that use Let's Encrypt certs are failing. Here's one way to fix it with Polly and the HttpClientHandler.

Calling Generic Methods Using Reflection | no dogma blog

Full source code here. Accessing generic methods by reflection is not easy. A while ago I needed to do just that and found relatively little information out there. So I dug in and figured it out for myself.

Fluent Validation with Web Api 2 | no dogma blog

Full source code here. I wrote blog post in 2015 on using the Fluent Validation NuGet package for complex validation needs. In the post the validator checked that a create person request had at least one active primary phone and at least one active primary ema…

Securing Lab Environments Part 1

One of the great things that operating in the cloud allows us to do, is create lab environments. With Infrastructure as Code (IoC) tools, it makes it really easy for users to create preconfigured lab environments to try new things, and experiment wit...

Web Api 2 Without MVC | no dogma blog

Download full source code. When building a Web Api 2 application there is much unneeded MVC baggage that comes along with it. To start with all the css, html and javascript can go, then most of the packages, most of referenced dlls and almost all the C#.

Simple Action and Action<string> Examples | no dogma blog

Full source code available here. A junior engineer colleague of mine recently asked me “how the f* * * do I call this method?”. Seemed like a reasonable question. It was a method that took a complicated Func and an Action with a series of parameters.

Getting Error Messages and Status Codes from Typed HttpClients | no dogma blog

Full source code here. I have been using HttpClientFactory for a while and have generally preferred using named clients over typed clients. With a named client you get the HttpClient just before you are going to use it, and you have full access to the HttpResp…

Starting the Presenter View in PowerPoint | no dogma blog

When practicing a presentation on a single screen it is helpful to see the notes, next slide, time information, etc., that you normally get with multiple monitors. This can be done with the Presenter View.

Securing Lab Environments Part 2

In my last post I wrote about securing your AWS lab environments by using Managed Microsoft Active Directory as an authentication provider and configuring that active directory with randomly created passwords. This is a great first step in helping to...

Using Other Verbs with Web API | no dogma blog

Full source code available here. You will often use the GET verb when making requests to an API. You have probably used it like this - www.example.com/person/ or www.example.com/person/1 or www.

POST with HttpClient and Basic Authorization | no dogma blog

Full source code here. A non .NET developer friend asked me to help him write a sample C# application that exercises a POST endpoint he wrote, it requires Basic authorization. After a quick search, I found that there are relatively few good examples of doing t…

Serializing a stack to XML in C# | no dogma blog

Serializing a class to XML in C# is straightforward; most collections can be easily serialized also. Something like the following will work in most scenarios - 1public string GetSerializedString<T>(T objectToSerialize) 2{ 3 var serializer = new XmlSerializer(t…

Re-authorization and onRetry with Polly | no dogma blog

Full source code available here. Want to learn more about Polly? Check out my Pluralsight course on it. In a previous post I showed how to use Polly to make a simple call, retrying in the event of failure.

Connecting your RaspberryPi to AWS IoT

In my last article "IoT for the .NET Developer", I covered how you can get .NET 7 installed and running on your RaspberryPi. In this article, I am going to cover how to get your Raspberry Pi set up and connected to AWS's IoT Core. There are two main ...

Hour of Code:

I wanted to start the year with a post about one of my favorite activities. The organization Code.org has an annual event that they run called Hour of Code. The idea of Hour of Code is to have technology professionals like you and I go into the class...

Complex model validation using Fluent Validation | no dogma blog

Full source code is available here. A common problem is validating an object using a complicated set of rules. I started using the Fluent Validation package some time back, it is commonly used with MVC and Web API applications but can be used with in any scena…

A simple Polly example with WebApi 2 | no dogma blog

Download full source code. Want to learn more about Polly? Check out my Pluralsight course on it. If you are calling APIs and you haven’t heard about The Polly Project, you should check it out.

Reusing HttpClient with Dependency Injection | no dogma blog

Full source code available here. If you are using HttpClient to make requests for you, you might have come across some articles discussing how to reuse HttpClient. They strongly advocate for using a single HttpClient for as many requests as possible, i.

IoT for the .NET Developer

In this blog post, we are going to start the process of developing an Internet of Things (IoT) solution using .NET 7 on a Raspberry Pi. IoT systems often run a lightweight Linux OS and leverage ARM hardware with low-power processors and have small am...

Pizza Delivery IoT Project Pt. 1

Introduction There is an ongoing project each year for the Developer Advocates to build sample applications. This year my sample application is going to be built around an IoT use case. This project was the catalyst for my IoT for the .NET developer ...

Enum ToString(), Caching for Performance | no dogma blog

Full source code available here. A while ago I was working on a program that had to convert enums values to strings as it saved data. When I removed the enum value from the data that was saved it went noticeably faster.

SSN checking and formatting | no dogma blog

Here’s something I worked on a few days ago. It shows six ways of verifying that an incoming string has nine numeric characters and then returns a string in the standard social security number format.

Web Api Routing in .NET Core | no dogma blog

Full source code available here. Routing in .NET Core Web Api (1.1 and 2) is a little different than in earlier versions. I’ve written about this a few times, you can find those posts here.

C# Is BAD At MATH!!! Can You Explain THIS?

When maths and programming don't overlap, we might be in for some weird surprises! #shorts #csharp #dotnet #programming #programmingtips Join this channel to...

A .NET Discussion with Isaac Levin

Remember: you can also always follow the show on Twitter @dotnetcoreshow, and the shows host on Twitter @podcasterJay or visit our Contact page. Welcome to s...

Pro EP 45 :

Since .NET 6 this file is the entry point of our application. It is doing work of both Program and Startup file if we look it via previous…

MassTransit Commute - Endpoint Dependencies

In MassTransit v8.0.15, the ability to specify endpoint dependencies was added. Using this new capability, receive endpoints can be configured so that they d...

dotNetDave Rocks the Copenhagen Developers Festival 2023

I’m so excited to announce that for the first time, the For Those About To Code: World Wide Tour will be at the 2023 Copenhagen Developers Festival in Copenhagen Denmark! I will present my se…

C# and nullable reference types

Nullable reference types are not new, but I love them so much that I had to do a video about them! And also the required keyword introduced in C# 11 improved...

Today’s random F# code: Using measures to give types more meaning

We use NodaTime in our application to deal with time. As you may remember, time is very important in our application - it's a attendance time-tracking tool with duty planning and many more features. For example, we use Instant to model a point in time. But som…

LINQPad AI

https://www.linqpad.net/https://twitter.com/linqpad/status/1643192136974868481

ABP React Template

React Starter Template for ABP application with Next.js and Tailwind CSS is ready to use. You can use this template to start your next project.#react #nextjs...

Health Checks In ASP.NET Core For Monitoring Your Applications

We all want to build robust and reliable applications that can scale indefinitely and handle any number of requests. But with distributed systems and microservices architectures growing in complexity, it's becoming increasingly harder to monitor the health of…

Medium

Milan Jovanović

Tech Entrepreneurship • Software Engineering • .NET

gefs

Recently, I have been working on a new file system called gefs. It isn't yet trustworthy, but it's ready for testing. The code is available here: https://shithub.us/ori/gefs/HEAD/f.html