Tagged: c#

C# 8 records 0

Immutable Records could be added in C# 8.x

There are talks about this feature being postponed to a minor version after 8.0 is released, as it might not be ready for the major C# 8.0 release. The features for C# 8.0 still hasn’t been decided yet, so that means this information is still subject to change! Since Microsoft rebuilt the C# compiler into what is now the Roslyn compiler, the language teams’ feature implementation speed has been phenomenal, they are cranking features out in record time.  Pro C# 7: With .NET and .NET Core Microsoft is committed to continuously update the C# language. They have even given us incremental updates of features that were not yet ready for the major versions release date and subsequently added it in minor language updates, such as C# 7.1, 7.2 and 7.3. Their speed is incredible and it doesn’t seem that long ago that we were introduced to C# 7, and many developers might not even have started using its features. If you haven’t caught up on C# 7, you can take a look at this book: Pro C# 7: With .NET and .NET Core But alas! C# 8 is on its way and has been for some time now. The problem If you have some years under your belt as a software developer, you know the code smell of passing primitives, like ints and strings around your system. Value Objects keep encapsulation in place Consider the following code: Here we are notifying a class that the user state has changed. The user state is spread across...

Redis connection lost 0

Redis connection issues

At my current client, we have been dealing with an ongoing problem while scaling their cloud systems to the ever increasing customer-base. As it is with any software that needs to scale, we’ve been seeing and solving scalability problems along the way. Anyone who has ever dealt with scaling a system to accommodate a lot of concurrent users, knows that issues will be showing up places you aren’t expecting. While scaling the system, we’ve made it more resilient and fault tolerant, and also learned to mitigate many of the problems as they are arising. We’ve improved logging and metrics, so we know exactly what is happening, and can see stability problems before they affect the end-users. Redis loses connection, and will not reconnect In our system, we use StackExchange.Redis(v1.2.6) to communicate with our Redis server. The Redis instance handles all cached data and all communication between services. It is a vital part of our architecture, and currently the architecture is heavily dependent on this connection. The odd thing is that we keep losing connection to it, but Redis is not even breaking a sweat. StackExchange.Redis is supposed to be able to recover from outages, and in most cases it does. But every once in a blue moon, it doesn’t. It think it does, and it thinks it is connected, but in reality all subsequent calls fail, and the pub/sub connection is completely dead, until the application is restarted. We have multiple services, and it will always just be one of them that goes down, every...

0

Re-use Controllers, Views and Tag-helpers in ASP.NET Core

I recently ran into a situation, where I needed to implement the same functionality, the same views and even the same tag-helpers for different customers. Like most other developers I hate copy-pasting code that should be shared across multiple projects. I had come across a similar need a few years back, but remembered that it was cumbersome in ASP.NET 3-5, to achieve this, and the solutions back then didn’t feel right. But since my recent switch to dotnet core, I knew there was a chance that Microsoft had a prepared an early christmas present for me. So I started researching my options, searching for titles similar to this blog post, and finally found a solution on the third place on google (Yes I was that desperate). Introducing Application Parts / App Parts With the introduction of ASP.NET Core v1.0, MVC came with a new concept called “Application Parts”, which is how the features and resources is populated into a ASP.NET Core MVC application. MVC loads it’s features from different application parts, which is a new type in ASP.NET Core. Specifically for my use-case, it can load the parts of an application from another Assembly (read: dll file). By creating an AssemblyPart object, you can discover controllers, views and tag helpers from a shared library. Adding controllers from a shared project Consider that I have a basic MVC site called “MyWebApp”, and another project called “SharedModule”, of which MyWebApp has a reference to. The SharedModule is created as an Empty MVC site, and then later populated...