Archives
-
ASP.NET Core Pitfalls – Async File Uploads
When performing file upload(s) to an asynchronous action, it may happen that the uploaded file(s) may not be accessible, resulting in an ObjectDisposedException. This is because the uploaded files are saved to the filesystem temporarily by ASP.NET Core and then removed, after the request has been processed, which is generally what we want. If we issue an asynchronous task with an uploaded file and don’t wait for it to finish, it may happen that it occurs outside of the request’s scope, meaning, the uploaded file is already gone.
-
Inline Images with ASP.NET Core
The most common way to show an image in an HTML page is to use the <img> tag to load an external resource. Another option is to use a URL that is a Base64 encoded version of the image. There are some aspects worth considering:
-
Interfaces and Inversion of Control
The way I see it, there are three reasons for using an Inversion of Control (IoC) / Dependency Injection (DI) container:
-
ASP.NET Core Pitfalls – Dependency Injection Lifetime Validation
As you can imagine, it doesn’t make much sense to have a service that is registered as singleton to depend on another service that is registered as scoped, because the singleton instantiation will only happen once. Take this example:
-
ASP.NET Core Pitfalls Index
Last update on March 25th. Reversed order, latest ones first.
-
ASP.NET Core Pitfalls – Returning a Custom Service Provider from ConfigureServices
In pre-3.1 versions of ASP.NET Core, you could return your own service provider (AutoFac, Ninject, etc) by returning some IServiceProvider-implementing class from the ConfigureServices method. This is no longer supporting, and having code like this results in an NotSupportedException being thrown at startup:
-
ASP.NET Core Pitfalls - Localization with Shared Resources
Update: updated for ASP.NET Core 8, should work on earlier versions.
-
ASP.NET Core Pitfalls – Areas
There are a few problems with using areas:
-
Modern Web Development with ASP.NET Core 3 Discount Code
-
SharedFlat and Databases
This post is part of a series on SharedFlat. See here the first (introduction) and here the second (UI). This time I will be explaining how SharedFlat handles multitenant databases.
-
SharedFlat and Multitenant UI
In my previous post, I introduced SharedFlat, a library for making multitenant ASP.NET Core apps easier to build. This time I’m going to talk about how can we customize the UI per tenant.
-
Introducing SharedFlat
A multitenant web application is one that responds differently depending on how it is addressed (the tenant). This kind of architecture has become very popular, because a single code base and deployment can serve many different tenants.
-
Modern Web Development with ASP.NET Core 3 - Second Edition
-
ASP.NET Core OData Part 3
This will be the third post on OData and ASP.NET Core 3. Please find the first post (basics) here and the second post (querying) here. This time, I will talk about actions and functions. For demo purposes, let’s consider this domain model:
-
ASP.NET Core OData Part 2
Update: see the third post here.
-
Modern Web Development with ASP.NET Core 3.0 – Second Edition
-
ASP.NET Core OData Part 1
Update: see the second post here.
-
Dynamic Payloads in ASP.NET Core
It has always been possible (but a tad problematic) to submit dynamic contents to an ASP.NET Core controller action. In the dark, pre-Core days, we had to implement a custom model binder for this. Now it is no longer the case.
-
Unit Testing the HttpContext in Controllers
When it comes to unit testing, it is common to use mocking to replace “external” services, that is, those that are not part of the subject under test. Not everything can be mocked, and, sometimes, when we instantiate non-POCO classes, such as controllers (ControllerBase), there are lots of things that are not instantiated by the framework and are left for us do to. Just think, for example, if you want to access request or quest string data or know if the user is logged in?
-
Dynamic Routing in ASP.NET Core 3
ASP.NET Core 3 introduced a not so talked about feature which is dynamic routing. In a nutshell, it means that it is possible to decide at runtime the controller, action and route tokens that a request will be dispatched to. The idea is to map a route pattern to a dynamic route handler, like this:
-
Performance in .NET – Part 4
This is my fourth post on performance in the .NET world. See the first one on object instantiation here and the second on property copying here and the third here. This time I’m going to talk about collections, but focusing on the performance side.This time, I’ll be talking about value types.
-
Visual Studio Tips 5
This is the fifth post of my Visual Studio tips series. See the first one here, the second here, the third here and the fourth here.
-
Accessing the HttpContext from a DbContext
Sometimes it might be necessary to access the current HttpContext from inside a DbContext, namely, from inside the OnConfiguring or OnModelCreating methods. Why? Well, for once, because of multitenancy: we may want to be able to decide the connection string to use based on the requesting or the host's domain, the current user or some other request parameter. Here the internal dependency injection (Instance) can’t help, because it cannot be used inside these methods.
-
C# 8.0 and .NET Core 3.0 – Modern Cross-Platform Development - Fourth Edition Review