<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Erick Gallani on Medium]]></title>
        <description><![CDATA[Stories by Erick Gallani on Medium]]></description>
        <link>https://medium.com/@erickgallani?source=rss-bca8c219db68------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*vJvv3dqD9uIppT__rE0HjQ.jpeg</url>
            <title>Stories by Erick Gallani on Medium</title>
            <link>https://medium.com/@erickgallani?source=rss-bca8c219db68------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 14:31:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@erickgallani/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to apply a heartbeat pattern to your AWS SQS consumers in .Net]]></title>
            <link>https://medium.com/@erickgallani/how-to-apply-a-heartbeat-pattern-to-your-aws-sqs-consumers-in-net-f87399c1231c?source=rss-bca8c219db68------2</link>
            <guid isPermaLink="false">https://medium.com/p/f87399c1231c</guid>
            <category><![CDATA[aws-sqs]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[event-driven-architecture]]></category>
            <category><![CDATA[parallelism]]></category>
            <category><![CDATA[dotnet-core]]></category>
            <dc:creator><![CDATA[Erick Gallani]]></dc:creator>
            <pubDate>Mon, 13 Mar 2023 09:56:59 GMT</pubDate>
            <atom:updated>2023-03-13T09:56:59.334Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to apply a heartbeat pattern to your AWS SQS consumers in .Net</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*coeViy2xBknkLuvp0vLW2w.jpeg" /></figure><p>I’ve highlighted in <a href="https://medium.com/@erickgallani/async-communication-with-aws-sqs-and-sns-d6339de81f2e">this AWS SQS post</a> how SQS is a powerful tool for implementing an Event Driven architecture, easy to use, and highly scalable.</p><p>But SQS has its own limitations and peculiarities and for some use cases, the <a href="https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-visibility-timeout.html">Visibility Timeout</a> can be a challenge/problem and can cause unexpected behaviors in production if not used correctly.</p><blockquote><em>TLDR;</em><br>Visibility Timeout is the time you define when configuring a queue that your application instance has to process the message before it becomes visible again and can be processed by another application instance.</blockquote><p>The Visibility Timeout can be as lower as 0 seconds to a maximum of 12 hours, which means that your application would have a maximum of 12 hours to process the message and delete it from the queue.</p><h4>But wait, where is the problem?</h4><p>When you define a Visibility Timeout of 30 seconds, for example, you are saying that all messages on the queue will need to be processed within 30 seconds, if your application takes more than that the message will become available again and can be picked up by another process to be processed.</p><p>And if for any reason your application receives a message that will take 5 minutes to process, for example, that means the same message will be processed by multiple processes at the same time and this can be dangerous or at least inefficient.</p><p>So in summary, Visibility Timeout works great for predictable processing time, but there are some use cases where the processing time can be unpredictable and different messages in the same queue can take from 1 minute to 1 hour to be processed.</p><p><strong>Oh, that’s easy, let’s set the visibility timeout to 1 hour and “job done”, right?</strong></p><p>Well, this approach would work as long as no message takes more than 1 hour, but there is a bigger problem with this approach.</p><p>Let’s imagine your application just pulled from the queue 10 messages, processed 1 with success after 1 minute, but the container where your application was running went down, and as the good engineer you are another container was raised automatically and everything works as designed.</p><p>Here is the problem, the other 9 messages not processed because the application instance went down are now invisible for 59 minutes and will only be processed by another instance when it becomes visible again.</p><p>Can you see how this problem can scale and create a very bad usage of the available resources?</p><p>That’s when the heartbeat pattern becomes the most effective solution.</p><h4>First of all, what is a heartbeat pattern?</h4><p>From the <a href="https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-visibility-timeout.html#:~:text=create%20a%20heartbeat%20for%20your%20consumer%20process">AWS official documentation</a></p><blockquote>If you don’t know how long it takes to process a message, create a heartbeat for your consumer process: Specify the initial visibility timeout (for example, 2 minutes) and then — as long as your consumer still works on the message — keep extending the visibility timeout by 2 minutes every minute.</blockquote><p>The heartbeat pattern is a strategy of keep sending signals in regular intervals to an external service to keep that service aware of the processing status.</p><h4>How this can be used on an AWS SQS queue?</h4><p>The <a href="https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-visibility-timeout.html#:~:text=message%2C%20create%20a-,heartbeat,-for%20your%20consumer">heartbeat pattern on SQS</a> is the strategy of setting a minimum visibility timeout and keeps extending that (<em>using the ChangeVisibilityTimeout API</em>) as long as the message is still been processed (<em>to a max of 12 hours</em>).</p><p>So going back to our example where 9 messages weren’t processed, if we were using the heartbeat pattern of 5 minutes for example, now instead of having the messages “blocked” or invisible for 59 minutes they would be at max 5 minutes away from become available again to be processed, <strong>promoting better scalability, disaster recovery and good usage of the resources.</strong></p><h4>Here is an example of how can we implement this pattern.</h4><blockquote>This example is built in .Net but conceptually can be implemented in any language that allows for thread control.</blockquote><p>We can use parallel threading processing to start 2 threads per message. One thread to process the message, executing the needed logic, and another parallel thread to keep sending signals to AWS (<em>ChangeVisibilityTimeout requests</em>) while the message is still being processed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/894/1*VpJxzD7xdCW81PnDSOtAvw.png" /></figure><p>How the thread lifecycle is managed will depend on the technology chosen, but in .Net we can use <strong>CancellationToken</strong> with linked tokens so one thread can communicate with its pair when the process has finished or interrupted.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ba2fb00e2cde9584b4acf60610368626/href">https://medium.com/media/ba2fb00e2cde9584b4acf60610368626/href</a></iframe><p>On the <strong>ProcessMessageAsync </strong>method, we create two token sources, one for the handler that will process the message and one for the heartbeat.</p><p>Once the processing handler finishes we call the <strong>heartBeatLinkedToken.Cancel() </strong>so we cancel the heartbeat thread from continuing resetting the visibility timeout.</p><p>The <strong>StartBeat </strong>method will keep resetting the message visibility timeout as long as the <strong>ProcessingThread </strong>is still processing.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bab1691bb86f1e54fa39c557fc849afd/href">https://medium.com/media/bab1691bb86f1e54fa39c557fc849afd/href</a></iframe><p>On the <strong>StartBeatAsync </strong>method, the <strong>ChangeMessageVisibilityAsync </strong>is called while the cancellation token is not canceled, and this cancellation token will only be canceled when the process of the message is finished.</p><p>If any issues are raised while trying to change the message visibility timeout the message processing cancelation token is canceled to prevent issues with processing the same message twice at the same time.</p><p>Ideally the <strong>VisibilityTimeout </strong>and the <strong>Task.Delay</strong> configurations should be configurable in the application configuration settings but for the sake of this example, we will leave them as constants.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a0d68082351008fe0176c08cf6fb1ae8/href">https://medium.com/media/a0d68082351008fe0176c08cf6fb1ae8/href</a></iframe><p>On the <strong>ReceiveMessageAsync </strong>we request the available messages to AWS and we start as many threads as the messages received to process in parallel, once all those messages are processed a new batch of messages is requested.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/99df2666e85c55a256422f1fe2a836ec/href">https://medium.com/media/99df2666e85c55a256422f1fe2a836ec/href</a></iframe><p><strong>DoStuff </strong>is the method that mimics the function that would do something with the message requested from SQS.</p><p><strong>Console output</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/715/1*YLXXPLxngxwcTY7GpTOmMw.png" /></figure><p>Check the full application code here: <a href="https://github.com/ErickGallani/AWS_SQSHeartBeat">https://github.com/ErickGallani/AWS_SQSHeartBeat</a></p><p>In summary, the <strong>heartbeat </strong>pattern is very powerful for non-deterministic processes that maybe depend on external sources or data volumes that can vary too much.</p><p>How this was useful for you, I’m keen to hear your thoughts.</p><p>Thank you for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f87399c1231c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Async communication with AWS SQS and SNS]]></title>
            <link>https://medium.com/@erickgallani/async-communication-with-aws-sqs-and-sns-d6339de81f2e?source=rss-bca8c219db68------2</link>
            <guid isPermaLink="false">https://medium.com/p/d6339de81f2e</guid>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[aws-sqs]]></category>
            <category><![CDATA[event-sourcing]]></category>
            <category><![CDATA[aws-sns]]></category>
            <dc:creator><![CDATA[Erick Gallani]]></dc:creator>
            <pubDate>Mon, 22 Aug 2022 10:56:31 GMT</pubDate>
            <atom:updated>2022-08-22T10:56:31.456Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KlJJ0s4PGkj18zPqJ33t-g.jpeg" /></figure><p>With the increase of microservices and distributed systems become more and more important to understand async communication pattern, why they are important, and how those services communicate with each other.</p><h3>Why async communication is important?</h3><p>There are two types of communication patterns, async and sync.</p><p>Sync communication can be, for example, a call to an API where the caller needs to wait for a response from the API to keep doing its work.</p><p>Async communication is defined by two or more services communicating with each other through messages/events where the sender doesn’t know (and doesn’t need to know) when the listener will consume that message.</p><p>Async communication is a key pattern to improving the decoupling and scalability of the many parts of a system. Those “parts” can be seen as microservices.</p><p>There are many services out there to provide the functionality necessary to publish and receive events, probably the most famous open sources are <strong>Apache Kafka, </strong>and <strong>RabbitMQ</strong>. Both are incredible message broker tools but suffer from the same problem, management effort, and complexity. You will need to install, config, and maintain it, which sometimes can be a very costly and time-consuming recurring task.</p><p>That’s where the cloud providers like AWS come in, offering a set of serverless tools for you to use where configuration, maintenance, and auto-scaling are a given. This is what I’ll be presenting in this article.</p><p><em>A note about microservices</em></p><blockquote>Microservices, in a very simplified way, are small pieces of a bigger system responsible for handling and processing smaller and self-content parts of the all process.</blockquote><h3>What is AWS SQS?</h3><p><a href="https://aws.amazon.com/sqs/">SQS or <em>Simple Queue Service</em></a><em> </em>is a service to publish events to be consumed by another application.</p><p>AWS SQS guarantees <strong>At-Least-Once</strong> Delivery, alongside almost unlimited scalability which in practical terms means, if you have a service publishing messages are a rate of<strong> 100 messages/s</strong> and you expect to have some spikes or increases in the throughput to, for example, <strong>500 messages/s </strong>you do not need to worry about that, AWS will guarantee the scalability and uptime.</p><p>SQS is great to build async communication between services, the API is very simple to use, and the fundamentals do not demand a big learning curve.</p><p>Worth to mention that the ordering is not guaranteed for a standard queue, although AWS will have the best-effort pattern to deliver the messages in order, it can’t be guaranteed. For guaranteed ordering we’ll need to use a FIFO queue, and will go there in a sec.</p><p>For example, we could have an Order processing system where we have one service responsible for validating the order, checking and debiting the stock let’s call it <strong>Order Service</strong>, and once the order is created it can send an event to the processing of the order handling the creation of a package and communicate with the shipping third party company. Let’s call this last service <strong>Processing Service</strong></p><p>So we would have this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/501/1*H9QjGQcJ19ghuaLKAq1eLg.png" /></figure><p><strong>Important keys of SQS</strong></p><p><a href="https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-delay-queues.html">Delay Queue</a>: This allows you to define a time in seconds to delay the delivery of new messages once they reach the queue, with a limit of 15 minutes.</p><p><a href="https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-visibility-timeout.html">Visibility Timeout</a>: Define the time in seconds the messages will be not visible to other consumers, with a limit of 12 hours.</p><p>So how actually does SQS work?</p><p>So in a <strong>very simplified view</strong>, on one edge you have a <strong>service creating new messages</strong> on an SQS queue, it will <strong>wait for the delay to be visible </strong>a the pool of available messages, and on the other edge, we have another service <strong>constantly pulling</strong> for new messages.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/931/1*QlAAS3AQ-lBcnHkb6I7hXA.png" /></figure><h3>What is AWS SNS?</h3><p><a href="https://aws.amazon.com/sns">SNS or <em>Simple Notification Service</em></a> is a service for publishing notification messages for multiple consumers.</p><p>Different from the SQS, SNS works in a pub/sub pattern, where you can have multiple subscribers for the same topic, so you can send the exact same message to multiple services, whereas SQS will deliver one message to one consumer.</p><p>Similar to SQS the scalability of SNS is great, but there are more restricted quotas per region, more information can be found <a href="https://docs.aws.amazon.com/general/latest/gr/sns.html">here</a>.</p><p>Following the example above for the Order System, let’s imagine now we have two more services interesting in knowing shipping was created, the communication department and the BI team, can is also called Fan-Out pattern, which I’ll go into more details below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EsBaHVAbgOnU7ucFP6x4-Q.png" /></figure><h4>The Fan-out pattern</h4><p>The Fan-Out pattern is a message broadcast in a one-to-many, so one publisher to many subscribers.</p><p>In the example, above we have multiple services interesting in knowing when shipping is created, so we use a Fan-Out pattern to be able to broadcast the same message to all subscribers of our notifications.</p><h3>FIFO Queue</h3><p><a href="https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/FIFO-queues.html">FIFO Queues</a> has the capability of processing messages in sequence by a defined id.</p><p>In order to guarantee order on the message, we must define a partition key, in this case for an SQS is called <strong>MessageGroupId</strong>.</p><p>By defining <strong>MessageGroupId </strong>AWS will guarantee the delivery of all messages with the same MessageGroupId will be processed by order, doesn’t matter how many consumers the queue has.</p><p>The diagram below highlights the differences between both approaches</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9MtVqtcU0bkWKpEBVPvfeA.jpeg" /></figure><h3>Resilience strategies</h3><h4><strong>Idempotency</strong></h4><p><strong>At-Least-Once</strong> Delivery means that the same message can be delivered more than once, for a lot of reasons, so your services need to take that into consideration, and idempotency is very important here.</p><p>Idempotency means that your service can identify if a message was already processed or not to avoid data corruption by processing twice the same thing.</p><p>There’s a log of idempotency strategies, like using a deterministic Id of the message payload or hash the all message payload and using that as the idempotency id. The strategy here will depend on the application and use case.</p><h4>Retries</h4><p>Transient errors happen, maybe a blip on the network, a temporary failed connection with the database, etc.</p><p>You can define the number of <a href="https://docs.aws.amazon.com/lambda/latest/operatorguide/sqs-retries.html">retries your queue</a> has before giving up of delivering that message.</p><h4>Dead Letter Queue</h4><p><a href="https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-dead-letter-queues.html">The Dead Letter Queue (DLQ)</a> is almost a cold storage of messages that your service for some reason wasn’t able to process but you can’t lose the message, you would prefer to save it for manually investigating what happen later and try to reprocess it.</p><p>DLQs can be automatically configured with the SQS Queue, so after the X number of retries, if all the tries failed, the messages are sent directly to the DLQ.</p><h3>Wrapping Up</h3><p>With AWS SQS and SNS you can take all advantage of async event sourcing communication with great scalability in no time, without the need for complex configurations and the heavy burden of maintaining your on message broker system.</p><p>Stay tuned for more about distributed systems and microservices patterns.</p><p>Thank you!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d6339de81f2e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The difference between null check with ‘is’ instead of ‘==’ in C#]]></title>
            <link>https://medium.com/@erickgallani/the-difference-between-null-check-with-is-instead-of-in-c-ed3d955a639e?source=rss-bca8c219db68------2</link>
            <guid isPermaLink="false">https://medium.com/p/ed3d955a639e</guid>
            <category><![CDATA[dotnet]]></category>
            <category><![CDATA[net-core]]></category>
            <category><![CDATA[csharp]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[development]]></category>
            <dc:creator><![CDATA[Erick Gallani]]></dc:creator>
            <pubDate>Mon, 27 Jun 2022 07:47:51 GMT</pubDate>
            <atom:updated>2022-06-27T07:47:51.950Z</atom:updated>
            <content:encoded><![CDATA[<p>What is the difference between <strong>myObject == null</strong> or<strong> myObject is null</strong>?</p><p>I found out that there are a lot of people that think <strong>is </strong>and <strong>is not </strong>(introduced in C# 9) for null checks is just syntax sugar for the equality or inequality operator (<strong>== and !=)</strong>.</p><p><strong>Note</strong></p><blockquote>Before C# 9 there wasn’t any “<strong>is not” </strong>support, to achieve the same result you will need to do “<strong>!(myObject is null)” </strong>a little more verbose and harder to read</blockquote><p>But in reality, is not only a syntax sugar, and we can use the IL and the C# decompiled code to take a look at what is happening behind the scenes.</p><p>Will be using <a href="https://sharplab.io/">sharplab.io</a>.</p><p><a href="https://sharplab.io/">SharpLab.io</a> is an incredible tool because it provides us with an easy way to decompile and inspect how the compiler is transforming our code, online without the need for any extra tools or IDEs like Visual Studio.</p><p>If you want a more complete IL to decompile tool to be able to easier navigate complex projects, I recommend the visual Studio extension <a href="https://marketplace.visualstudio.com/items?itemName=SharpDevelopTeam.ILSpy">ILSpy</a>.</p><p>So, without further ado, let’s take a look at a very simple case, an “<strong>if clause” </strong>to<strong> </strong>verify if an object instance is null or not.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eBTs1Qfcmlrq-ajxvbVrFA.png" /></figure><p>But wait, didn’t I say that the <strong>is </strong>wasn’t just a syntax sugar? The IL looks pretty much the same apart from the <strong>dup </strong>instruction which doesn’t cause any significant difference for this example. What the <strong>dup </strong>instruction is doing here is duplicating the top element of the STACK for performance reasons (<a href="https://docs.microsoft.com/en-us/dotnet/api/system.reflection.emit.opcodes.dup?view=net-6.0">more information can be found here</a>).</p><p>So what is actually the difference of <strong>is</strong> and <strong>==</strong>?</p><p>Well, as you may know (or may not), in C# <a href="https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/operator-overloading">we can override the default operator behavior</a>.</p><p>For Example, in that Test class above I can do something like this.</p><pre>public class Test {<br>    <br>    public static bool operator ==(Test x, Test y) =&gt; false;<br>    <br>    public static bool operator !=(Test x, Test y) =&gt; true;<br>}</pre><p>With that, I’m actually overriding the default behaviors of the equality and inequality operators.</p><p>For this example, completely messing up with the operational flow of these operators, by saying that <strong>==</strong> will always <strong>return false </strong>and <strong>!=</strong> will always <strong>return true</strong>.</p><p>Ok, so now that I’ve overwritten those operators&#39; behaviors how the IL looks like?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6PtHA39LcX8YVxz3vRO2aQ.png" /></figure><p>Ok, so now we can start seeing the difference.</p><p>On the image above you can see the <strong>equality operator</strong> will actually <strong>call</strong> the <strong>overwritten operator</strong> where the “<strong>is” </strong>remains the same.</p><p>Let’s take a look at the C# Compiled code to understand better, why that is happening.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-4aWkGwMnAMhvZ5-RAMoGQ.png" /></figure><p>At this point is pretty much obvious why the equality operator is calling the <strong>overwritten operator</strong> and the<strong> “is” operator </strong>isn’t.</p><p>The equality call must guarantee that your class signature is respected, that’s the reason for casting to the <strong>Test </strong>class and evokes our equality method, where the <strong>“is” operator </strong>cast to a plain object ignoring any custom implementation of the equality operator.</p><p><strong>Note:</strong></p><blockquote>Actually cast to <strong>object </strong>to doing the null check, is also the approach for the proposed <a href="https://dotnetcoretutorials.com/2022/02/18/c11-parameter-null-checking/">parameter null-checking in C# 11</a> which I’ll not approach in the post.</blockquote><p>So the result of the run will be</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/877/1*fGGrAk_TjhP2BAV9Rs56VQ.png" /></figure><p>Since the <strong>== </strong>is always returning false, the “<strong>if (test1 == null)</strong>”<strong> </strong>will never be true.</p><p>Things get a little bit more dangerous when we want to guarantee something is not null to avoid the infamous, <strong>NullReferenceException</strong>.</p><p>So let’s take a look now is the <strong>inequality operator</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lDx5wADGiF7ve-1puog6lQ.png" /></figure><p>The result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/809/1*7QUIzdPJ_YD3PgGJhOkw4w.png" /></figure><p>I believe at this point is pretty obvious the problem that this would have caused, right?</p><p>If you were validating that an object wasn’t null to safely access it properties you would have <strong>NullReferences </strong>all over the place.</p><p>You can be questioning at this point <strong><em>But why someone would do something like that?</em></strong></p><p>Well, we are very used to incorporating into our project <strong>third-party libraries</strong> from all sorts of sources, other companies&#39; packages, individual developers, some random package on the NuGet repository, etc.</p><p>And maybe some<strong> new release</strong> of those packages can introduce a bug like this one, intentionally or unintentionally, it can be very hard to spot where exactly your code is failing to guarantee an object is not null.</p><p>So should I go and change all my null checks everywhere to follow this pattern? The answer will be the good and old cliche “It depends”.</p><p>Does your project have<strong> one or more third-party libraries</strong>? They are from a trustworthy source?</p><p>So here are also some tips that regard changing the null checks from <strong>==</strong> to <strong>is</strong> should be followed to avoid big headaches.</p><ol><li>Always cover your code logical branches within unit tests, validating the null check is actually doing the checking correctly</li><li>Avoid adding third-party libraries to a production code from sources you do not trust or don’t know. I usually recommend using libraries well recognized by the community or with a good amount of contributors, like for example, MediatR, FluentValidation, AutoMapper, NewtonSoft, Dapper, etc. The risks will be lower.</li><li>Always check the release notes and the changes before updating an open-source library version.</li></ol><p>Hope that can help you understand the nuances of using “<strong>is</strong>” or “<strong>==</strong>” in your null checks.</p><p>Let me know what you think in the comments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ed3d955a639e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The power of Entity Framework Core and LINQ Expression Tree combined]]></title>
            <link>https://medium.com/@erickgallani/the-power-of-entity-framework-core-and-linq-expression-tree-combined-6b0d72cf41db?source=rss-bca8c219db68------2</link>
            <guid isPermaLink="false">https://medium.com/p/6b0d72cf41db</guid>
            <category><![CDATA[aspnetcore]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[csharp]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[net-core]]></category>
            <dc:creator><![CDATA[Erick Gallani]]></dc:creator>
            <pubDate>Sun, 19 Jun 2022 22:44:49 GMT</pubDate>
            <atom:updated>2022-06-19T22:44:49.726Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*58_WzBT6Rp7shU2n5T4FAA.jpeg" /></figure><p><em>Note: Is not mandatory but highly recommended to read first </em><a href="https://medium.com/@erick.gallani.1/asp-net-core-complex-model-binding-276156cc09d7"><em>this post</em></a><em> where we create the sorting class and give some bases for this post.</em></p><h4><strong>Important</strong></h4><p>This will be a long post because it tries to explain complex concepts, so bear with me on this and follow along. I’m pretty sure that you will find it quite interesting and hopefully didactic!</p><h4>Entity Framework Core</h4><p>Entity Framework Core is a great data access framework. It is based on the old Entity Framework which was available until the .Net Framework version 4.7.x.</p><blockquote>EF Core can serve as an object-relational mapper (O/RM) which enables .NET developers to work with a database using .NET objects and eliminates the need for most of the data-access code that typically needs to be written.</blockquote><p>If you don’t know EF Core, I recommend checking out the <a href="https://docs.microsoft.com/en-us/ef/core/">official documentation by Microsoft</a> which will give you a great overview and core fundamentals, there are also a bunch of courses on e-learning platforms like (Udemy, Pluralsight, etc…) that offer a detailed view of EF and all its features.</p><p>For the sake of simplicity, I’ll refer to Entity Framework Core as only EF during this article.</p><h4>What is an expression tree?</h4><blockquote>Expression trees represent code in a tree-like data structure, where each node is an expression<br>source <a href="https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/expression-trees/">Microsoft Docs</a></blockquote><p>In other words, Expression Trees is a very power full tool to express how a code should perform in runtime, doing modifications to the executable code, and the creation of dynamic queries using LINQ.</p><p>So let’s begin creating an abstract Repository class so our database resources can inherit.</p><blockquote>This is just a good practice for decoupling database infrastructure code from your service/application and taking the advantage of dependency injection to access I/O bound resources like files or databases.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fa3065832cad0b9de09c55a33f1cfa83/href">https://medium.com/media/fa3065832cad0b9de09c55a33f1cfa83/href</a></iframe><h3><strong>Let’s break down the AddSorting method</strong></h3><h4><strong>The Queryable object</strong></h4><p>What is an <strong>IQueryable&lt;TEntity&gt;</strong>?</p><p><a href="https://docs.microsoft.com/en-us/dotnet/api/system.linq.iqueryable?view=net-6.0">The IQueryable interface</a> is a data source agnostic interface that uses <a href="https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/linq/">LINQ</a> to allow us to express using code how a data collection should be queried, filtered, and ordered.</p><p>For example</p><pre>comments<br>  .Where(comment =&gt; <br>    comment.Description.Contains(&#39;great post&#39;) &amp;&amp; <br>    comment.CreatedAt &gt; &#39;2022-01-01&#39;)<br>  .OrderByDescending(comment =&gt; comment.CreatedAt);</pre><p>Will be translated to the appropriated SQL statement depending on the database technology.</p><p><em>If you are using MySQL for example, the code above will be translated by EF to</em></p><pre>SELECT `c`.`Id`, `c`.`Description`, `c`.`CreatedAt`<br>FROM `Comment` AS `c`<br>WHERE (LOCATE(CONVERT(&#39;great post&#39; USING utf8mb4) COLLATE utf8mb4_bin, `c`.`Description`) &gt; 0) AND (`c`.`CreatedAt` &gt; &#39;2022-01-01 00:00:00.000000&#39;))<br>ORDER BY `c`.`CreatedAt` DESC</pre><p>This is just an example and the actual query can change depending on the EF version you are using since they are constantly evolving and improving the framework.</p><p>This is a great functionality of Entity Framework since it takes away the need for us to build the SQL statements ourselves, avoiding big chunks of strings in the code that can’t be easily tested in isolation.</p><p>By using EF we can unit test everything since all queries are C# code.</p><p><strong>Note</strong>: Performance has been always a source of debate when talking about EF and is not my intention to discuss this topic here. As I said before, EF is constantly evolving and improvements are always added to the framework.<br>My suggestion is during the development phase to enable EF to output all SQL statements somewhere, for example, your application log output so you can check how the queries look like and follow <a href="https://docs.microsoft.com/en-us/ef/core/performance/efficient-querying">Microsoft guidelines for an efficient query</a>.</p><h4><strong>Expression Tree</strong></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/28d883ec88c57f0e559d1214f8b97d4c/href">https://medium.com/media/28d883ec88c57f0e559d1214f8b97d4c/href</a></iframe><p>We start building the tree expression by creating a parameter expression that will be used to set up the property we want to sort as a parameter input to the LINQ Sort By function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e9ba54e00047d90eb8264ee69df4397f/href">https://medium.com/media/e9ba54e00047d90eb8264ee69df4397f/href</a></iframe><p>After we create an expression that represents accessing the property we want to sort. This is known as Member Expression.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e0d56cb50238036c1757a0802c5c5aad/href">https://medium.com/media/e0d56cb50238036c1757a0802c5c5aad/href</a></iframe><p>We can see lambda expressions as an abstract runtime builder of a .Net method body.</p><p>For example</p><pre>public int Sum(int x, int y) <br>{<br>  return x + y;<br>}</pre><p>Can be expressed in a LambdaExpression tree as</p><pre>using System;<br>using System.Linq.Expressions;<br>using System.Collections.Generic;</pre><pre>ParameterExpression paramExprX = Expression.Parameter(typeof(int), &quot;x&quot;);<br>ParameterExpression paramExprY = Expression.Parameter(typeof(int), &quot;y&quot;);</pre><pre>LambdaExpression lambdaExpr = Expression.Lambda(<br>    Expression.Add(<br>        paramExprX,<br>        paramExprY<br>    ),<br>    new List&lt;ParameterExpression&gt;() { paramExprX, paramExprY }<br>);</pre><pre>Console.WriteLine(lambdaExpr);<br>// Outputs (x, y) =&gt; (x + y)</pre><pre>Console.WriteLine(lambdaExpr.Compile().DynamicInvoke(1, 2));<br>// Outputs 3</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9b1f29ba9e7ac4cd8db159ce17c3f2d2/href">https://medium.com/media/9b1f29ba9e7ac4cd8db159ce17c3f2d2/href</a></iframe><p>Here we are trying to identify which method we should use. The caveat with ordering a collection is we can have several “order by” clauses in a query, but how do we express this using LINQ?</p><p>Something like this</p><pre>myColletion<br>  .Where(x =&gt; x.Name == nameParam)<br>  .OrderBy(x =&gt; x.CreatedAt)<br>  .ThenBy(x =&gt; x.UpdatedAt)<br>  .ThenByDescending(x =&gt; x.CodeNumber)<br>  ....</pre><p>As you can see, we can’t just chain OrderBy method calls, because it doesn’t work like this.</p><p>LINQ needs to understand the sequence because it influences the end result.</p><p>So basically an <strong>IQueryable </strong>interface has access to <strong>OrderBy&lt;&gt;</strong> and <strong>OrderByDescending&lt;&gt;</strong>, and the return for both methods is an <strong>IOrderedQueryable </strong>which means that it already has at least 1 ordering setup, therefore, the <strong>IOrderedQueryable </strong>has access to <strong>ThenBy&lt;&gt;</strong> and <strong>ThenByDescending&lt;&gt;</strong></p><p>That’s the reason for verifying in the switch case the type of the query expression, so we can chain properly the correct sorting method expressions.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/265f965c1a3c4b935a8fc16f2bbe456c/href">https://medium.com/media/265f965c1a3c4b935a8fc16f2bbe456c/href</a></iframe><p>After identifying which method we want to add to the queryable object <strong>OrderBy&lt;&gt;</strong>, <strong>ThenBy&lt;&gt;</strong>, <strong>OrderByDescending&lt;&gt;</strong>, or <strong>ThenByDescending&lt;&gt;</strong> we store the MethodCallExpession, which is basically the method body signature, for example</p><pre>Expression&lt;Func&lt;int, int, int&gt;&gt; sum = (int x, int y) =&gt; x + y;<br>Console.WriteLine(sum.Body); // Outputs (x + y)</pre><p>But since the LINQ methods have an expression as a function we parse to MethodCallExpession to make sure it is compatible with the LINQ extensions parameters.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f30876d6934c7e32377f7db1800de759/href">https://medium.com/media/f30876d6934c7e32377f7db1800de759/href</a></iframe><p>Then we get the generic method definition, which you can see as the method blueprint.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/00d2e1c42d55f23a4612249a9901ea4d/href">https://medium.com/media/00d2e1c42d55f23a4612249a9901ea4d/href</a></iframe><p>After that, we use that blueprint to create our own method setting up the entity type and also which property type the method should use.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5a89d53a998cca6975f687d6221d5c99/href">https://medium.com/media/5a89d53a998cca6975f687d6221d5c99/href</a></iframe><p>And in the end, we set up how the generic method we created should be invoked using the lambda defined at the beginning.</p><p>All these concepts can look very abstract and complex, and indeed is one of the most complex topics of the framework, but also one of the most powerful resources of .Net.</p><p>Once you get your head around it you see that everything becomes easier to understand.</p><p>Here is a more detailed demonstration of what is going on behind the scenes</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ca6e8b02490116c74f29134e2550936a/href">https://medium.com/media/ca6e8b02490116c74f29134e2550936a/href</a></iframe><p>You check a running example of the above code here <a href="https://dotnetfiddle.net/Qd71N0">https://dotnetfiddle.net/Qd71N0</a>. I encourage you to play around, change the parameters, expressions, and methods and check the console output, this is the best way for learning.</p><h4><strong>Repository Class Example</strong></h4><p>So how this would look like in a repository class?</p><p>Is a good practice to create a class to hold all the possible filters and queries, and in this example, we have created a class that will hold the search string and the list of sorts (Sort class <a href="https://medium.com/@erick.gallani.1/asp-net-core-complex-model-binding-276156cc09d7">created here</a>)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/927a3e99912bbd406881ccaaedeacf8b/href">https://medium.com/media/927a3e99912bbd406881ccaaedeacf8b/href</a></iframe><p>The concrete implementation of the repository class</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6eaeea03fbfc08acf4ea3435d6473691/href">https://medium.com/media/6eaeea03fbfc08acf4ea3435d6473691/href</a></iframe><p>In the example above the first line creates an instance of an IQueryable object</p><pre>var catalogQuery = _context.Catalog.AsNoTracking();</pre><p>So basically we get “Catalog” <a href="https://www.learnentityframeworkcore.com/dbset">DbSet from the EF context</a> which holds the abstract collection of catalogs and we use the <strong>AsNoTracking </strong>to signal EF to not track these objects in the context.</p><p>I<strong>s a good practice</strong> when we are querying <strong>for a read-only scenario</strong> to prevent EF from tracking all objects, this will improve the performance. <a href="https://docs.microsoft.com/en-us/ef/core/querying/tracking">More details here</a>.</p><p>Once we have the <strong>“var catalogQuery” </strong>as an IQueryable instance, we can start a chain of LINQ expressions to this object.</p><p>Every time we call <strong>“catalogQuery.Where(…” </strong>what this is actually doing is adding a where expression and returning the instance of the object now with the where. This is called a <strong>Builder Pattern</strong></p><p>So when we do <strong>“catalogQuery = catalogQuery.Where(…” </strong>we are replacing the instance reference from the variable <strong>catalogQuery</strong> with a new one containing the <strong>Where </strong>clause now.</p><p>Looping over the sorting collection, what is does, it receives the <strong>Queryable </strong>object and adds a sorting expression to this object for each Sort item in the list.</p><p>And in the end returns the <strong>Queryable</strong> object with all the queries, filters, and ordering attached to it.</p><p>The last part executes everything and returns the result.</p><pre>return await catalogQuery.ToListAsync(cancellation);</pre><p>By now we have a fully unit testable dynamic sorting mechanism where no matter which properties you want to sort, the Entity type, or the number of changes you will do on the Entity itself, adding or removing properties, this Sort mechanism is<strong> Close for Modifications and Open of Extensibility (</strong>one of the principles of S<strong>O</strong>LID - Open-Close) because basically, this code doesn’t need to change anymore do accommodate any future change in the software, but it can be extended.</p><h4>Conclusion</h4><p>Hope this can show all the flexibility, extensibility, and power of the .Net framework features.</p><p>As a role of thumb for me, if I’m doing something that looks excessively difficult, is resulting in a code that is becoming scary to change in the future, or you feel that is too much work for an apparently small thing this usually is because there’s a simpler way for doing it you just need to study the framework.</p><h4><strong>References</strong></h4><ul><li><a href="https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/expression-trees/how-to-use-expression-trees-to-build-dynamic-queries">Querying based on the runtime state</a></li><li><a href="https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/expression-trees/">Expression Trees</a></li><li><a href="https://docs.microsoft.com/en-us/ef/core/">Entity Framework Core</a></li><li><a href="https://docs.microsoft.com/en-us/ef/core/performance/efficient-querying">Efficient Querying</a></li><li><a href="https://docs.microsoft.com/en-us/ef/core/querying/tracking">EF Core Tracking</a></li></ul><p>Was this useful to you? I’m keen to hear your thoughts.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6b0d72cf41db" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ASP.Net Core Complex Model Binding]]></title>
            <link>https://medium.com/@erickgallani/asp-net-core-complex-model-binding-276156cc09d7?source=rss-bca8c219db68------2</link>
            <guid isPermaLink="false">https://medium.com/p/276156cc09d7</guid>
            <category><![CDATA[aspnet]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[net-core]]></category>
            <category><![CDATA[csharp]]></category>
            <dc:creator><![CDATA[Erick Gallani]]></dc:creator>
            <pubDate>Sat, 04 Jun 2022 08:59:20 GMT</pubDate>
            <atom:updated>2022-06-19T22:46:26.449Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UjsRHJr3zgJlPVnoAM_uqg.jpeg" /></figure><p>Did you ever face a situation where you have a search UI, like a front-end application, that has a data table and you need to support a complex query construction that can contain Free Text search, Sorting of multiple columns, and extra filters and query parameters starts to look a nightmare on your controllers?</p><p>ASP.Net offers great flexibility, extensibility, and customization to graceful handle these situations.</p><h4><strong>The problem</strong></h4><p>Let’s imagine the scenario where you need to create a Search API to provide data to a Data Table in a UI, and this search needs to allow free text search, multiple sortings for different properties, and add any other extra piece of filtering property.</p><h4><strong>API Contract</strong></h4><p>So you have an API Contract something like this.</p><pre>{<br>  &quot;term&quot;: &quot;cool stuff&quot;,<br>  &quot;countryAlphaCode2&quot;: &quot;US&quot;,<br>  &quot;sorts&quot;: [<br>     &quot;asc|percentualDelivered&quot;,<br>     &quot;desc|percentualPaid&quot;<br>  ]<br>}</pre><p>So as you can see there, the sort will be sent to the API following the pattern <strong>{direction[asc|desc]}|{propertyName} </strong>which is a fair pattern and easy for URL query parameters to send over.</p><p>But the problem with this approach is if we just received the parameters as pure strings on the controller, this will pollute our controller, we’ll not use the advantage of the binding pipeline for fail-fast for example, and it will demand a propagation of raw string to be parsed and interpreted.</p><p>Another problem is that every time a new query parameter is introduced a lot of changes will be required on the controller action signature and the code inside.</p><h4>Controller using primitives only</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/41c1d15631f4b7228f68b42cec93716c/href">https://medium.com/media/41c1d15631f4b7228f68b42cec93716c/href</a></iframe><h4>How the request for this example above would look like?</h4><pre><a href="https://my-api.com/search?term=cool">https://my-api.com/search?term=cool</a> stuff&amp;countryAlphaCode2=US&amp;sorts[0]=asc|percentualDelivered&amp;sorts[1]=desc|percentualPaid</pre><h4><strong>Parsed URI request</strong></h4><p>The query parameter actually needs to be encoded before the request, so you will see something like the below.</p><pre>https://my-api.com/search?term=cool%20stuff&amp;countryAlphaCode2=US&amp;sorts%5B0%5D=asc%7CpercentualDelivered&amp;sorts%5B1%5D=desc%7CpercentualPaid</pre><p>Now let’s take a step forward and create a class that will represent the query parameters</p><h4>Search query parameter class</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/986bf69a12fd1f87909d3507c058f5ab/href">https://medium.com/media/986bf69a12fd1f87909d3507c058f5ab/href</a></iframe><p>As you may notice instead of an array of strings in the Sorts we’ll use a class to interpret the string pattern <strong>{direction[asc|desc]}|{propertyName} </strong>and create a complex type instead of an array of primitives (strings).</p><p>The problem here is that if we just add a class there will not work quite well because by default a complex type model binder bind values direct to the properties, by <a href="https://docs.microsoft.com/en-us/aspnet/core/mvc/models/model-binding?view=aspnetcore-6.0#complex-types">Microsoft documentation</a></p><blockquote>A complex type must have a public default constructor and public writable properties to bind. When model binding occurs, the class is instantiated using the public default constructor.</blockquote><p>Which in this case will not help us too much because having a class with a public setter that holds an array of strings will bring no advantages at all.</p><p>Wouldn’t be great if we could have a class that will hold all the “sort” pattern parse logic, receiving the sort string in the constructor and building it in a complex meaningful type with validations and more enriched values?</p><p>Well, in fact, we can with the <a href="https://docs.microsoft.com/en-us/aspnet/core/mvc/advanced/custom-model-binding?view=aspnetcore-6.0">Custom Model Binding</a>.</p><p>So let’s create a ModelBinder class and also our Sort class.</p><h4>Sort Model Binder</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/48e10b62976b9fc93aee1fc16d2991f4/href">https://medium.com/media/48e10b62976b9fc93aee1fc16d2991f4/href</a></iframe><h4>Sort Query class</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a65323adcd73c4027c5ec19c82638257/href">https://medium.com/media/a65323adcd73c4027c5ec19c82638257/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ed025b7587a367708f8dae390d045c7d/href">https://medium.com/media/ed025b7587a367708f8dae390d045c7d/href</a></iframe><p><strong>And this is how it works.</strong></p><p>When data comes from an HTTP request ASP.Net framework will loop over all the parameters in the controller action signature looking through the available sources in the HTTP request and trying to find matching names between the parameters and the query params in our example (<em>remember parameters can come [FromQuery], [FromBody], [FromRoute], [FromForm], and [FromHeader]</em>) and try to parse the received value to the controller parameter type.</p><p>So if we want .Net to do more fancy work for us we need to instruct the framework on how to do it, and that’s basically what the code above is doing.</p><p><strong>SortModelBinder </strong>is used on the <strong>Sort </strong>class declaration <strong>[ModelBinder(BinderType = typeof(SortModelBinder))] </strong>to instruct .Net that, for building the Sort class it needs to run our custom binding algorithm and our algorithm will instantiate a <strong>Sort </strong>class for each string value of the Sorting array received on the request.</p><p>So now we can do a lot of complex work delegated to the framework, like on the <strong>Sort </strong>class where we receive a string in the constructor and actually do a series of validations for a fail-fast approach, convert the string direction “asc” and “desc” to an enum “Ascending” and “Descending”, standardizing the string to lower case, respecting the single principle from SOLID by creating classes that only have one reason to change, and easy to unit test.</p><p>And finally….</p><h4><strong>Controller using a complex </strong>type model<strong> binding</strong></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/83809323f1d3c895fb2491cd553c0007/href">https://medium.com/media/83809323f1d3c895fb2491cd553c0007/href</a></iframe><p>Is way better don’t you think? Cleaner and a better design to use the strength of the framework in our favor.</p><h4>Conclusion</h4><p>As you can see ASP.Net is a very powerful and flexible framework with a lot of extensible features to make your code more readable, testable, flexible, and enriched.</p><h4>Reference</h4><p>Microsoft Documentation: <a href="https://docs.microsoft.com/en-us/aspnet/core/mvc/advanced/custom-model-binding?view=aspnetcore-6.0">https://docs.microsoft.com/en-us/aspnet/core/mvc/advanced/custom-model-binding?view=aspnetcore-6.0</a></p><p><a href="https://medium.com/@erickgallani/the-power-of-entity-framework-core-and-linq-expression-tree-combined-6b0d72cf41db">In this post</a>, I’ll cover how can we use this alongside <strong>Entity Framework Core</strong> and <strong>Linq Expression Tree</strong> to easily <strong>add sorting dynamically</strong> to a <strong>Queryable </strong>object using this binding we just created interacting with the <strong>Database</strong></p><p>Was this useful to you? I’m keen to hear your thoughts.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=276156cc09d7" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>