Posts

Multitenancy Techniques for EF Core

Introduction Multitenancy is a hot topic, which I covered a few times on my old blog. I won't dwell on its concepts, but, instead, I will present ways to apply multitenancy to EF Core. When it comes to data, multitenancy means that we should only retrieve data for the current tenant. I will present three ways to obtain the tenant id from inside of a  DbContext , which can then be used to set up query filters, connection strings, or mapping configuration. Multitenancy in Databases So, as I blogged before, there are essentially three strategies for applying multitenancy to databases: Using a tenant column on tenant-aware tables and filter by it Using a different schema, meaning, tenant-aware tables will be duplicated in different schemas and for each request, one schema will be used Using different databases, one for each tenant, and, for each request, pick the right connection string There are obviously pros and cons to each approach, but I won't go through them now. Instead,...

ASP.NET Core API Versioning

Image
This was ported from my original blog post here . Introduction When you have an existing deployed REST API that you want to change, you generally need to be very careful. Why would you want to change it? There can be a number of reasons: Changes to the request contract (adding, removing or modifying request parameters) Changes to the response contract (same as above) Changes to the behaviour of the existing actions (they now do something slightly different) Changes to the HTTP methods that the existing actions accept (not so common) Changes to the HTTP return status codes … In a controlled environment, you can change at the same time the server and the client implementations, which means that you can update your clients accordingly, but, unfortunately, this is not always the case. Enter versioning! With versioned APIs, you can have multiple versions of your API, one that the legacy clients will still recognise and be able to talk to, and possibly one or more that are more suitable for ...

Getting Location and Weather from an IP Address

This was ported from my original blog post here . Introduction The concept of getting the location for a given IP address is not exactly new, and some posts have been written about it already. Still, I wanted to write about it because I will need it for a later article, and, to add something, also explain how to get the weather forecast for the given location. Let's start by getting the location for a given IP address. Geo Location There are plenty of services available for free or a fee on the Internet that will give you some information about the location of an IP address (geo location by IP). To name just a few, in no particular order: https://www.iplocation.net https://hackertarget.com/geoip-ip-location-lookup https://ip-api.com https://ipapi.co https://freeipapi.com https://ipgeolocation.io Some of these offer free services (with possibly some limitations, such as rate limiting per hour/day) where others offer full working sets. Also, the amount of information varies, al...