March 6, 2014

C# Most FAQ in Interview

  1. What is the difference between Abstract class & Interface? When to use Interface and when to use Abstract class?
  2. What is the scenario for multiple inheritances? Can you give an example?
  3. What are differences between IQueryable & IEnumerable?
  4. What are the difference between List & IEnumerable? Which is better?
  5. What is anonymous type? What is the difference between ‘var’ & ‘dynamic’?
  6. Can you explain about dependency injection?
  7. What are delegate and multi-cast delegate?
  8. What is anonymous method? 
  9. What is the lamda expression and expression tree?
  10. What is Lazy loading in C#?
  11. What is generation mechanism in memory management?
  12. What is extension method?
  13. What is the difference between finally and finalize?
  14. What is a strong name in assembly? What is satellite assembly?
  15.  What is delay signing? What are the type of signing in assembly & whats the difference?
  16. What are the types of inheritance? Describe all.
  17. What is the difference between a class & structure?
  18. What is a virtual class? Why we use virtual class?
  19. Suppose I need to use an DLL & I want to overwrite DLL method. What are the steps to achieve this?
  20. What is serialization? Why we use it? What are the types of serialization?
  21. What is a threading? What are its different types?

FAQs in ASP.NET MVC

  1. What is the benefit of Razor w.r.t. ASPX view engine?
  2. What are Action Link and Action Result in MVC? Can you list out the different types of action results returned by action method?
  3. What are areas in MVC?
  4. Does MVC support view state? If not, how can we can manage the same?
  5. What are Html helpers?
  6. How to create custom data annotation?
  7. What is filter in MVC? What are the types of filters in MVC?
  8. What is rout table in MVC?
  9. What is a view engine? Which is faster: Razor or ASPX?
  10. How MVC works to process a new request?
  11. What is the difference between MVC and MVVM?
  12. What are the difference between ASP.NET MVC and aspx web forms? When you will choose MVC architecture and when to choose ASPX web forms? 
  13. What is data annotation? Can you define how can I define custom data annotation?
  14. What is view bag, view data and temp data?
  15. How you will pass parameters to controllers? What are different techniques to pass parameters from view to controllers?

March 5, 2014

ServiceStack - An Introduction

What is a ServiceStack?

ServiceStack is an open source, cross-platform for .Net and Mono REST web service framework and can run on both .Net framework as well in Mono platform too. ServiceStack have the flexibility of auto configuration of all standard output formats – XML, JSON, CSV, JSV, SOAP1.1, SOAP1.2 and endpoints –REST, RPC, SOAP without any configuration. It embraces only the concepts of DTO and not RPC concept. Whereas, WCF has the option of both. Service developed in service stack can run in windows environment using .Net framework or in Linux OS with Mono* support.

*Mono supported OS are:

Linux, Mac OS X, iOS, Sun Solaris, BSD, MS Windows, Nintendo Wii, Sony PlayStation 3 etc.


Why ServiceStack?

ServiceStack is not instead of WCF for its better performance, but main feature is that it can be deployed and works in cross platform like Windows, Mono, Linux, iOS, Mac OS etc.


ServiceStack versus WCF:

- WCF can be deployed only windows platform whereas Service Stack supports cross OS environment deployment.
- WCF works on both DTO and RPC concepts whereas Service Stack works uses DTO concept only.
- In WCF, if we do not define attribute [DataContract] then it will ignore it. But Service Stack will serialize it in plain text.


Hosting a Service Stack: 
Service Stack can be hosted in any of the following:

  1. Stand-alone mode
  2. With an existing ASP.Net  web application
  3. Windows service
  4. Console application
For more detail, please read here.


Creating First Service Stack Web Service:

Download Service Stack libraries from visual studio package manager. To download run command:

Install-package ServiceStack

Steps to create a service stack:

Common name space:

using System.Web.UI;
using ServiceStack;
using ServiceStack.CacheAccess;
using ServiceStack.ServiceInterface;
using ServiceStack.WebHost.Endpoints;
using ServiceStack.CacheAccess;
using ServiceStack.ServiceInterface.ServiceModel;
using ServiceStack.OrmLite;
using ServiceStack.Common;

Step: 1 Create an empty web application and then install packages for service stack.

Step: 2 Add a class file ad define request and response class.

[Route("/HelloRequest")]
[Route("/HelloRequest/{Name}")]
public class HelloRequest
{
   public string Name { get; set; }
}

public class HelloResponce
{
   public string Result { get; set; }
}

public class HelloService : IService
{
   public object Any(EmployeeRequest reqObj)
   {
     return new HelloResponce { Result = "You have entered: " + reqObj.Name };
   }

  public object Get(EmployeeRequest reqObj)
  {
    Return your_definedtype;
  }
}


Step: 3 Add a class for AppHost.

public class HelloAppHost : AppHostBase
{
  public HelloAppHost() : base("Here is your service:", typeof(HelloService).Assembly)
 {

 }

  public override void Configure(Funq.Container container)
  {
    // Defined this route in class attribute
    Routes.Add("/HelloRequest")
   .Add("/HelloRequest/{Name}");
  }
}


Step: 4 Add a Global.asax file and add the following code line to initialize the service request.

protected void Application_Start(object sender, EventArgs e)
{
   new HelloAppHost().Init();
}


Step: 5 Add the following lines in Web.config file.


Step: 6 Build the service and run it. On browse you can see the following result, if everything is correct.






Step: 7 To test, type the URL as:

localhost:51391/hellorequest?name=navin&format=xml

This will display the result as you have passed in query string.