Caching method results easily with AOP

In many cases, using a caching mechanism can drastically improve performances. Processed results of methods can be stored in memory or in files so they are ready to be returned immediately when we call the methods again.

In some .NET applications, we can use the MemoryCache class from System.Runtime.Caching to store data in memory. However, using such library in a basic way may induce some problems such as:

  • Adding caching in each method which needs it may result in less readable and polluted code.
  • The repetitive use of such code may induce errors (especially copy-pasted code).
  • Depending on the nature of projects (mobile apps, websites, web services, desktop apps), we may need a different caching approach.

In order to avoid all these problems, I have written a generic caching aspect using Autofac and Castle DynamicProxy.

Continue reading “Caching method results easily with AOP”

EventToCommand in Xamarin Forms Apps

This component is a part of Pillar, a lightweight MVVM framework that I made for Xamarin.Forms 1.x and 2.x. Please check it out on Nuget or GitHub.

An EventToCommand behavior can be used to bind any event on a visual element to an ICommand. Typically, this element is used in XAML to connect the attached element to a command located in a ViewModel.

When I started playing with Xamarin Forms, I found myself in a situation where I had to bind the ItemTapped event of the ListView to a command. I managed to do so by using the Behaviors from the Cavalli Corrado’s nuget package.

But since Xamarin Forms officially supports Behavior in version 1.3, I wanted to write my own.

Continue reading “EventToCommand in Xamarin Forms Apps”