Cross cutting concerns (wiki) are common architectural elements such as logging, instrumentation, caching and transactions. In this article, we will explain how we integrate these into our projects. The functional classes in our project may use logging or caching within their method. Or they may not know that these other classes exist. We will cover both scenarios.

Decorator pattern

Decorator pattern is an elegant solution to implement cross-cutting concerns.…

Read More

Dijkstra’s algorithm computes the shortest distance between two vertices in a graph. Vertices in a graph are connected by an edge with a positive length.

static int SingleSourceShortestPathForNonNegativeEdgeLength(Vertex v)
{
    int min = short.MaxValue;
    var crossingEdges = new MinHeap<short, short>(N);
    var minVertices = new bool[N]; 
    minVertices[v.Id - 1] = true;
    
    foreach (var outgoingEdge in v.OutgoingEdges)
    {
        // Use a Heapify operation!
Read More

Knockout provides an elegant way of updating the user interface using Javascript View models. Javascript has an inheritance model. With that, we can create a hierarchy of classes. Consider the following HTML with Knockout bindings.

<div id="main">
    <div data-bind="text: name"></div>
    <div data-bind="text: detail"></div>
</div>

We use a simple Model class. Load it with data. And bind it to the HTML.

var model = new Model();
model.load();
Read More

FAST is a search engine used for enterprise search. In FAST, a View specifies how content is structured. It has collections. A collection has documents. Each document has a specific structure, specified by fields.

Apart from specifying the content, a View has certain parameters to fine-tune the search. For example, parameters like lemmatisation and spell-check control the results returned by a search.…

Read More

HttpClient

The typical way to access a REST API is using the HttpClient. Create a HttpClient object. Pass in request headers. Call the PostAsync method with the URL and the request body. Use await keyword to wait for the response. Get the message as a JSON string. Use JavaScriptSerializer to convert the JSON to a C# object.

async Task<int> GetResultUsingHttpClient()
{
    Uri uri = new Uri("http://localhost/api/Algebra
                      /DoAlgebra?num1=3&num2=4");
Read More