Posts tagged .net
Context I noticed that an application was flooding the database with simple SELECTs. The investigation revealed some bugs in the health check which theoretically implemented caching (to avoid quer...
Context I am currently working on migrating a legacy application to an ASP.NET Core + Angular application. The Web API's main project is based on Jason Taylor's template (clean architecture) and a...
Note: this is based on my question on SO and subsequent activity there I am trying to add resilience using Polly to HTTP calls that are performed using Refit library. I am using the Refit factory...
I have followed Nick Chapsas' tutorial to avoid throwing a ValidationException to treat validation errors and instead rely on LanguageExt.Common.Result<> from LanguageExt library. I have ma...
I have just created an ASP.NET Core 6 application and added NLog support for logging: NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger() However, this API is almost deprecated as ...
I am using linq/EF core to retrieve data via an API call. How do I sort the collection of related data for each retrieved entity? Assume the following structure: an Order is made on a certain da...
Context This Q&A from SO suggests that throwing exceptions is incredibly expensive when compared to returning values (return codes): that with return codes instead of exceptions the same pr...
I am using MediatR in an ASP.NET Core 3.1 application and I want use a generic query and a generic request that deals with getting lists of some standard items I am using in drop-downs and similar:...
Our team deals with a legacy application that relies on a rather old deployment process and infrastructure: we deploy the application on an environment very similar to the production called Clon...
I am caching some very static information (changes once per day) in my ASP.NET Core application. This is normally done when needed ("lazy"). One such cache item is a 50K list of items that are tak...
One of the legacy applications our team manages contained the following pattern (in the controller): // initialization private readonly IServiceScopeFactory _serviceScopeFactory; public FooCon...
A few of my services rely on LazyCache and they use it by injecting IAppCache. For unit testing, I would like to mock this. I have found MockCachingService, but it does not do any caching (as spec...
I have an ASP.NET Core 5 web application that provides functionality that involves file upload + rather large processing (memory consumption mainly). After each processing (with success or not) the...
Let's say I have some collection of data. My goal is to provide different kind of view of ItemsControl depending on user`s preference. For simplicity, we can assume that user can select only betwe...
Issue I have recently discussed with a friend a performance issue he and his colleagues have encountered in an ASP.NET Core 5 application (a checkout app, microservices architecture). The problem...
I have recently stumbled across the Maybe (or Optional) modal usage in .NET Code: example code or this one example article Based on everything I read, there are multiple advantages on relyi...
I handle several projects that use yaml files for configuration, and load them with YamlDotNet. It is sometimes useful to log the effective configuration when the program starts, to aid future debu...
After upgrading a Web application from ASP.NET Core 3.1 to ASP.NET Core 5.0, it worked fine on an existing server. However, when deployed on a server that had only .NET 5.0 installed, the applicat...
Context Our team has begun migrating a pretty old internal application and one aspect that got my attention is the impersonation. This is implemented as follows: only administrators are allowed...
Context My ASP.NET Core application got stuck in Production with a 5xx error. By inspecting the logs, I have noticed that a database error occurred during application initialization, namely a SQL ...
I'm used to working in Python, but my current project is in C#/.NET and uses log4net for logging. Out of the box, log4net uses an XML file for configuration. I dislike XML and want to use something...
In C#, I have two lists and need to mark records in the first based on the second. Here's a sample: public class Vehicle { public string Make { get; set; } public string VIN { get; set;...
I have to add health checks to a rather new application (Web API, not a microservice) and I and a colleague are not agreeing about what other systems I should include in the check. This application...
I'm trying to write an interface to define the set of operations I expect my repositories' Unit of Work implementations to have, and I want this interface to be fulfilled by EF Core's DbContext cla...
I am slowly modernizing an older ASP.NET Core Web API and one of the steps involved migrating from database first to code first. Now, all schema changes and seeding is covered by migrations which ...
I have recently started a project based on the clean architecture principle and noticed that it did not rely on generic repositories since Entity Framework's DbSets are doing the job just fine. In ...
I am interested in performing a LEFT JOIN using LINQ-2-SQL when working with method call notation. This answer suggests a way that relies on GroupJoin but it is more verbose than expected: var le...
Which concept is best for managed background services? 1. RunAsync(CancellationToken): interface IWorker { Task RunAsync(CancellationToken cancellationToken = default); } ... IWorker worker =...
This is an unanswered code review request of mine from Code Review Stack Exchange. Overview I have developed a small ASP.NET Core 3.1 Web API that provides information that is rarely changed (sever...
This is basically an unanswered code review request of mine from CodeReview Stack Exchange. I want to be able to log as accurately as possible, the time spent by a certain Web API action in an ASP....
I am working at a proof-of-concept for porting an ASP.NET MVC application to an ASP.NET Core API + Angular SPA. One of the features of the existing application is the ability of an admin (typically...
Note: this is an aggregate of the answer provided for this question. I want to get the LINQ equivalent of the following from SQL: SELECT .. FROM entity1 e1 JOIN entity2 e2 ON e1.field1 = e2.fie...
Note: This is basically a question from Stack Overflow that was closed for a very long period of time and I fear it might get closed again as primarily opinion based. I am wondering if my ASP.NET C...