Posts

Showing posts from April, 2014

Dependency Injection in ASP.NET MVC 5 with StructureMap

Dependency Injection(DI) is a design pattern that let you write loosely coupled testable code. Typically your classes depend on other classes. Take a look at the following example. The above example shows the " HomeController " of an asp.net mvc application. Within the index method, you can see that it requires to create an instance of " Student " class to get the full name of a student. It is very clear that the Index method is tightly coupled with the Student class.  This is a disadvantage when it comes to testing HomeController . Suppose that you have other methods, with similar types of class dependencies. So, each time when you test the code, you have to pass an actual instance Student class. This is tedious. You don't have the luxury of passing a fake student class to easily test your controllers.  So how do we decouple the Student class from HomeController? This is where DI comes in handy. You can inject dependencies in several ways. Today i will sho

Bootstrap Code Samples

Image
Twitter Bootstrap makes life easy. If you are not much into designing layouts from pure CSS, twitter-bootstrap is ideal for you. Following shows some code samples that you might often need. Setting up bootstrap is trivial. Setting-Up - Download Bootstrap from  http://getbootstrap.com/ - Unzip the folder. You may find following folders in it. - Include these three folders in your Project folder. - Add link to your index.html to bootstrap.css within in <head> tag as follows <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/> - Add bootstrap script tags just above the </body> tag. Make sure you have jquery.js file <script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript" src="js/bootstrap.js"></script> - That's it. To check if you have properly setup bootstrap, Write this line of code within the body section