Extracting Values From Types

Learned a cool little trick a while back from Khalid. As a developer, you will often run into scenarios that require you to get a subset of all fields from a model. There are many ways to achieve this task, returning the type and then grabbing each property, for example, take the following User type. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 public class User { public User(string name, DateTime dob) { var random = new Random(); Id = random....

April 10, 2022 · Yunier

Preventing Invalid Assembly Dependencies

.NET makes it super simple to update the dependencies of a project. If you are following a solution structure like Clean Architecture where the Web project should not be referenced by the Core project or you have created your own solution structure that requires certain projects do not reference another project then you might need a way to avoid having developers incorrectly adding dependencies. The diagram above gives a high-level view of all project dependencies in a Clean Architecture solution....

March 12, 2022 · Yunier

The Order Of Interfaces Impacts Performace

I was looking through some of my bookmarked Github issues when I rediscovered issue #32488, in that issue a comment was made that caught my attention. The comment stated that in .NET the order of interfaces impacts performance. This is because in the .NET CLR all class definitions have a collection of methods and interface definitions. Casting is a linear search that walks the interface definition. If you are constantly casting to an Interface located at the end then the CLR must do a longer walk....

August 28, 2021 · Yunier

The Problem With AcquireRequestState

In my second post, I wanted to cover AcquireRequestState. In my four years as a developer I have encountered issues with AcquireRequestState twice. So, what in the world is AcquireRequestState. AcquireRequestState is part of the ASP.NET Life Cycle, this is an event raised by the HttpApplication, it keeps session state in sync. Though I suspect that most developers are familiar with this event for being a major performance pain in their ....

September 3, 2020 · Yunier

Configure Serilog Sub-Loggers Using XML App Settings

Serilog has a neat feature that allows you to configure sub-loggers. With this feature you can essentially have log specific instances running on your application. I recently had to configure a .NET Framework application to use two different sub-loggers and while I was able find many examples online on how to configure sub-loggers through AppSettings.json, I did not find any examples on how to configure them through AppSettings.config/App.config so I wanted to document that process on this post....

August 31, 2020 · Yunier