Thursday, 30 July 2015

What is MongoDB and Why to use it?

MongoDB is one of the most popular open-source NoSQL database written in C++. As of February 2015, MongoDB is the fourth most popular database management system. It was developed by a company 10gen which is now known as MongoDB Inc.



MongoDB is a document-oriented database which stores data in JSON-like documents with dynamic schema. It means you can store your records without worrying about the data structure such as the number of fields or types of fields to store values. MongoDB documents are similar to JSON objects.



Happy Coding !!


Introduction to ASP.NET vNext and MVC 6

Microsoft has announced the next generation of ASP.NET at TechEd North America on 12 May 2014, which is called ASP.NET vNext. ASP.NET vNext includes new cloud optimized versions of MVC6, Web API3, Web Pages4, SignalR3 and Entity Framework7.

Features of ASP.NET vNext
  1. ASP.NET vNext includes new cloud-optimized versions of MVC, Web API, Web Pages, SignalR, and Entity Framework.
  2. MVC, Web API and Web Pages have been merged into one framework, called MVC 6. This will follow common programming approach between all these three i.e. a single programming model for Web sites and services.
For example, there is unified controller, routing concepts, action selection, filters, model binding, and so on. In this way, You will have a single controller that returns both MVC views and formatted Web API responses, on the same HTTP verb.


  1. MVC 6 has no dependency on System.Web since it was quite expensive. A typical HttpContext object graph can consume 30K of memory per request and working with small JSON-style requests this is very costly. With MVC 6 it is reduced to roughly 2K. The result is a leaner framework, with faster startup time and lower memory consumption.
  2. ASP.NET vNext has new project extension project.json to list all the dependencies for the application and astartup class in place of Global.asax.
  3. ASP.NET vNext apps are cloud ready by design. Services such as session state and caching will adjust their behavior depending on hosting environment either it is cloud or a traditional hosting environment. It uses dependency injection behind the scenes to provide your app with the correct implementation for these services for cloud or a traditional hosting environment. In this way, it will easy to move your app from on-premises to the cloud, since you need not to change your code.
  4. .NET next version, .NET vNext is host agnostic. Hence you can host your ASP.NET vNEXT app in IIS, or self-host in a custom process.
  5. .NET vNext support true side-by-side deployment. If your app is using cloud-optimized subset of .NET vNext, you can deploy all of your dependencies including the .NET vNext (cloud optimized) by uploading bin to hosting environment. In this way you can update your app without affecting other applications on the same server.
  6. Dependency injection is built into the framework. Now, you can use your preferred IoC container to register dependencies.
  7. .NET vNext use the Roslyn compiler to compile code dynamically. Hence you will be able to edit a code file and can see the changes by refreshing the browser; without stopping or rebuilding the project.
  8. .NET vNext is open source and cross platform. It can run on Mono, on Mac and Linux.
Happy Coding...

What's the difference between ViewData and ViewBag?

  1. ViewData
  • ViewData is a dictionary of objects that is derived from ViewDataDictionary class and accessible using strings as keys. 
  •  ViewData requires typecasting for complex data type and check for null values to avoid error
  • Example:

    public ActionResult Index()
    {
    ViewData["Name"] = "Dhiren Web developer";
    return View();
    }
     2. ViewBag

  • ViewBag is a dynamic property that takes advantage of the new dynamic features in C# 4.0. 
  •  ViewBag doesn’t require typecasting for complex data type.
  • Example:
              public ActionResult Index()
           {
                      ViewBag.Name = "
Dhiren Web developer";
                      return View();
            }

Calling in View

@ViewBag.Name
@ViewData["Name"]

Happy Coding...

Picking between Xamarin and Apache Cordova


 Xamarin is generally better when you:
  • Need to do apps with less shared UI, more shared logic. Xamarin.Forms changes this, but it’s still very new at the moment
  • Have .Net developers
  • Need a high performing, native looking app
Cordova with Visual Studio is generally better when you:
  • Want to share more UI between platforms, with fewer native looking elements.
  • Share UI assets with a mobile websit
  • Have HTML \ JS developers
  • Are OK with a somewhat less smooth UI on older Android and iOS devices, or don’t plan on supporting older Android (pre 4.2)
The Xamarin experience for developers is generally better than the
Cordova experience, having been around a bit longer. Cordova can be really
difficult if you don’t use the new Visual Studio integration.

Xamarin has a license cost, Cordova does not. However, the difference in
the license cost can quickly be eaten up by having to do more work to account
for different Android versions on a Cordova app.

Xamarin has a much greater need for access to a Mac while developing iOS
apps than Cordova. Cordova apps can be built against an iOS
emulator running in Chrome
. You absolutely still have to do testing against
physical devices.

My preference is usually for Xamarin, but there are situations that are
better suited to Cordova-based apps. I wouldn’t do Cordova apps without the new
Visual Studio support.

I’m finding more and more services companies using Xamarin, and more
startups using Cordova. Services companies can quickly recover the Xamarin
license cost through improved productivity, whilst startups have a need to keep
costs down, whilst being real responsive to changes in their product on
multiple platforms, including the web.

Happy Coding !! Enjoy

See You Soon...

Wednesday, 29 July 2015

Types of ASP.NET MVC Views

I have found that many entry level developers get confused by the various kinds of Views in ASP.NET MVC Applications. In this post I am trying to clarify these different types of Views.
The type of ASP.NET MVC View depends on the way the data is passed to it from the Controller. There are three ways data can be passed to Views from a Controller. They are as follows:

Using ViewBag or ViewData
  1. Using object of the model which is strongly typed
  2. Using any dynamic type value
On the basis of data transfer mechanism ASP.NET MVC views are categorized as two types:

  1. Dynamic view
  2. Strongly typed view
ViewBag allows you to share data dynamically from Controller to View. You can pass data from Controller to View using ViewBag as follows:


public ActionResult Index()
        {
            ViewBag.ApplicationTitle="Book App";
            ViewBag.Genere = from r in GetAuthors()
                             select r.Genere;
            return View();
        }


ViewBag is a dynamic object and properties get added to it at run time. There is no predefined property for ViewBag. In a View, the ViewBag property can be accessed using the same property name. You can use ViewBag in a View as follows:

@{
    ViewBag.Title = ViewBag.ApplicationTitle;
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>ViewBag.ApplicationTitle</h2>



While using ViewBag in a View, you may notice that intellisense is not working. This is because the data gets passed dynamically from Controller to View.

When you use ViewBag to pass data, the View is known as a dynamic view.

The second way to pass data from a Controller to a View is using a dynamic type. We are passing a List of Authors as a dynamic type from the Controller to a View as shown below:

public ActionResult Index()
        {
           ViewBag.ApplicationTitle = "Book App";
           var result = from r in GetAuthors()
                             select r.Genere;
            return View(result);
        }


Next create a View for the Index action. To create the View, right click on the action and from the context menu select Add View Option. In Add View dialog box make sure you select the Empty template without model option.
dynamicview



On View you can access a dynamic object passed from the Controller using the dynamic keyword as shown in the image below. Views created using dynamic type data are known as dynamic views.
dynamictype
Intellisense does not help in dynamic views. You can access various properties of dynamic data using dot operator as shown below without help of Intellisense.