Redis as a cache server

Although Redis is much more than a cache, But it's possible to use as cache server especially in distributed applications. Redis lets you operate on the values and it's just a key-value pair in-memory database.

To getting started, get the latest version of Redis from here and install in your windows machine (Server) by instruction and run it in your services. Redis runs in your server machine (you can have Redis server and client in one machine which could be your client development machine) and you call it from a client by a library... Continue

Simple command handler in .net

I want to introduce a simple command handler pattern in order to separate commands and queries of your applications, if it’s needed. Sometimes specially in large scale applications you need to have two layers for read and write separated and assign two teams to work on them.

You can use the pattern in this post based on complexity and needs of your application. I recommend that don’t call this CQRS pattern as it’s something completely different and more complex.

 

Get started and Create an interface with no any member:... Continue

Introducing sqlbulktools

In my previews blog post I wrote about Z.bulkOperation. I migrated to sqlbulktools just because it's free with the same ability!(to be frank). Now to see the reason of my migration, fire up visual studio and Install the latest version of the library using the following command in console package manager:

Install-Package sqlbulktools

And get started!

  1.  static void Main(string[] args)
  2.         {
  3.  
  4.           &nb... Continue

Introducing Z.bulkOperation

Today I was tackling with a problem. It was about inserting and updating 200000 records of data. I just wanted to find a solution rather than writing Store Procedure. I just searched on the web and found a library named Z.BulkOperation

I dare say I had never seen handling this amount of data nicely in application level without even using a line of SQL code, it's awesome!

Fire up visual studio and a simple console or MVC application and install the package via:

PM> Install-Package Z.BulkOperations

PM> Install-Pac... Continue

Note about the Deferred Execution in LINQ component

Maybe you know about the deferred execution unconsciously. This sexy phrase refers to the point of LINQ queries when it executed. Although executing the LINQ query should be considered and after doing join, group, let and every LINQ instructions, finally, it should be executed; because it will be executed in every call if you don't execute it! Take a look at the following example:

  1.   public IEnumerable<Blog> GetAllPosts()
  2.         {
  3.          &... Continue

Access to configuration in asp.net core

While I was working with asp.net core, I encountered with getting the configuration setting from json file and After searching on the web I found out that there would be different ways to do that. I tested the following one and it worked. There is different configuration in each version of Asp.net core in Main method of program class. you should put the following configuration in this sample in main method because I didn’t tested it with other configurations to ensure you.

  1.  public static void Main(string[] args)
  2.      &nbs... Continue

Handling custom error in mvc

In asp.net mvc there is an custom error in web.config like below:

  1. <customErrors mode="On">
  2.  <error statusCode="404" redirect="~/404.html"/>
  3.  </customErrors>

Sometimes you want to redirect the user to your own custom error controller and log the error message. You can handle it! Firstly create your own Error controller:

  1.  public class ErrorController : Controller
  2.     {
  3.         public A... Continue

Call Asp.net Web API from C#

If you search in the web for calling web API from C# Code not from URL, you will find lots of sample on get and hardly enough on POST! I don't know why but I want to share with you a simple example. As a usual open visual studio and create a web API project from MVC project template.

Suppose these two simple post and get API actions:

  1.         [HttpPost]
  2.         [Route("api/Test/PostValue")]
  3.         public IHttpActionResult Po... Continue

IP filtering attribute for web API

Recently I came up with a solution for filtering the API requests by filtering the server IP. This is used when you want to make the received requests private and secure. It's a simple helper and I hope it could be useful for you as well.

  1. public class AuthorizeApiIPAddressAttribute : ActionFilterAttribute
  2.     {
  3.         public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
  4.         {
  5.     &nbs... Continue

Use yield instead of populating a temporary list

In C# programming language, to fetch an item from a list or collection, there are some ways. Most of the developers forget to use yield keyword and they create a list and populate it based on needed condition in the simplest possible form. Look at the following sample of populating a list in order to fetch some integer values:

  1.  public List<int> FetchValuesLessThanTen(List<int> source)
  2.         {
  3.             var finalList = ne... Continue