Sunday, October 23, 2011
JSON Serialization and Deserialization in ASP.NET
Saturday, October 15, 2011
Developers, UX Is Your Business Too!
Software developers often think the user experience as something better left to either the interaction designers or the visual designers on their teams. In actuality, developers can have profound impacts on the user experience of the products they’re working on. This article will explore some areas of experience design in which the development process has a more direct role. This is not to say that developers can substitute for UX and interaction designers, but they can play a role in making compelling applications.
Limit the User’s Choices
This may sound counterintuitive, but when a user is given too many choices, it makes it harder for the user to make any choices. When faced with an excess of choice, the user might abandon the application altogether, which is certainly not the choice we want them to make....read more
By Chris Griffith
Tuesday, October 11, 2011
Simple, fast and useful MiniProfiler for ASP.NET MVC
MiniProfiler is very lightweight, simple, fast and useful profiler for ASP.NET websites including ASP.NET MVC. It is designed to help you find possible performance issues and have very nice and clear view over each operation that happens in your web applications.
MiniProfiler was created by the Stack Overflow guys for their internal use, but they have put it as an open source project under Apache License 2.0 for all ASP.NET and WCF developers! (Thanks guys!)
To get started using MiniProfiler, you have to install it first.
You have two options available:
Installation
1. Using NuGet Package Manager
- In VS.NET 2010, go to Tools –> Library Package Manager –> Manage NuGet Packages…
Install MiniProfiler.MVC3
Once installation is successful, both MiniProfiler will be ticked.
If you want to use MiniProfiler for Entity Framework too, then install the MiniProfiler.EF too.
2. Install manually from here (you have github clone too)
Setting up
Once you are done with installation, if you have used NuGet manager to install MiniProfiler, you are almost done
The new dlls added by the NuGet are marked:
Besides dlls, there is also a MiniProfiler.cs class inside App_Start folder
The next thing you need to do is to include MiniProfiler in the master layout page. Once you expand the Views –> Shared, you can see that with installing MiniProfiler there is _MINIPROFILER UPDATED Layout.cshtml that is an example master layout regarding how to include MiniProfiler in your Layout page.
Copy the marked line and add it to your actual _Layout.cshtml
In my example:
<!DOCTYPE html>
<html>
<head>
<title>@ViewBag.Title</title>
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery-1.4.4.min.js")" type="text/javascript"></script>
@MvcMiniProfiler.MiniProfiler.RenderIncludes()
</head>
<body>
@RenderBody()
</body>
</html>
Using MiniProfiler
Now, run your application… you can see MiniProfiler is running in the top left corner:
If you want to see what does MiniProfiler includes for us, check View Source in your browser:
If you want to start the mini profiler for specific requests only (e.g. local requests), you can use MiniProfiler.Start() method. The best place to add this is in the Global.asax Application_BeginRequest.
Grouping Profiler Steps
Using MiniProfiler we can group profiling steps very easily. Yep, this might make your code in some segments a bit more dirty, but if you have clean code you should no worry…
To perform grouping by steps in your Controller, first add using MvcMiniprofiler; directive
using MvcMiniProfiler;Create instance of MiniProfiler by adding the MiniProfiler.Current that represents the currently running profiler in the HttpContext
Use the Step() method in using code block to create profiler step.
Example:
Then in my Products ActionResult add the following code:
public ActionResult Products()
{
List<Product> listProducts = new List<Product>();
MiniProfiler profiler = MiniProfiler.Current;
using (profiler.Step("Load Product Items", ProfileLevel.Info))
{
System.Threading.Thread.Sleep(1000); //1 second sleep
listProducts.Add(new Product() { ProductID = 1, Name = "Product 1", Price = 100 });
listProducts.Add(new Product() { ProductID = 2, Name = "Product 2", Price = 200 });
listProducts.Add(new Product() { ProductID = 2, Name = "Product 3", Price = 300 }); }
using (profiler.Step("Add Products to List", ProfileLevel.Info))
{
System.Threading.Thread.Sleep(2000); //2 seconds sleep
ViewBag.Products = listProducts;
}
return View();
}
In this example we have two profiler steps: Load Product Items and Add Products to List.
Now add new View to display products list by right clicking somewhere above the code in Products() method and Add View with name Products.
In the view add the following code (just for the demo…):
@{
ViewBag.Title = "Products";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Products</h2>
<p>
<ul>
@foreach (var item in ViewBag.Products)
{
<li>
@item.Name ($@item.Price)
</li>
}
</ul>
</p>
Now run the web page and navigate to /Home/Products
once you click the button at the top-left corner you will get this:
Profiling Database Queries
To use MiniProfiler for profiling database queries, first you will need to de-comment one (or both) of the database related line/s inside App_Start/MiniProfiler.cs PreStart() method
//TODO: To profile a standard DbConnection:
// var profiled = new ProfiledDbConnection(cnn, MiniProfiler.Current);
//TODO: If you are profiling EF code first try:
MiniProfilerEF.Initialize();
In our example I will be using the EF Mini Profiler.
First, I have rewritten the Products method with the following code:
public ActionResult Products()
{
AdventureWorksEntities context = new AdventureWorksEntities();
ViewBag.Products = (from p in context.Products
join pm in context.ProductModels on p.ProductModelID equals pm.ProductModelID
join pmx in context.ProductModelProductDescriptionCultures on pm.ProductModelID equals pmx.ProductModelID
join pd in context.ProductDescriptions on pmx.ProductDescriptionID equals pd.ProductDescriptionID
select new ProductViewModel
{
ProductID = p.ProductID,
Name = p.Name,
Description = pd.Description.Substring(0, 200)
});
return View();
}
I am using AdventureWorks database with EF. I have added one query that joins four tables. Now just run the application.
if we click on 1 sql, the MiniProfiler will give us some detailed info regarding generated SQL query and the time needed to execute and finish
If we have some query that is executing very long or we have multiple queries which create performance issues, MiniProfiler will give us warnings…
For example, lets add loop of executing the above query 50 times
public ActionResult Products()
{
AdventureWorksEntities context = new AdventureWorksEntities();
List<ProductViewModel> productList = new List<ProductViewModel>();
for (int i = 0; i < 50; i++)
{
productList.AddRange(from p in context.Products
join pm in context.ProductModels on p.ProductModelID equals pm.ProductModelID
join pmx in context.ProductModelProductDescriptionCultures on pm.ProductModelID equals pmx.ProductModelID
join pd in context.ProductDescriptions on pmx.ProductDescriptionID equals pd.ProductDescriptionID
orderby p.Name descending, p.ProductID ascending, pd.Description descending, pd.ModifiedDate descending
select new ProductViewModel
{
ProductID = p.ProductID,
Name = p.Name,
Description = pd.Description.Substring(0, 200)
});
}
ViewBag.Products = productList;
return View();
}
Once we run the app, it will take few seconds to load…
Summary
ASP.NET MVC MiniProfiler is a great tool that you must have in your toolset for building scalable, fast and performance optimized web applications. You can have clear view of what is causing performance issues in your application in almost all levels and layers.
For those that are interested to get access to the MiniProfiler source code and want to dig more, check this page.
I hope this was useful blog post for you.
Regards,
Hajan
Similar readings
Thursday, September 15, 2011
Windows Communication Foundation Basics
What Is The Difference Between Software Development And Web Development?
What Is The Difference Between Software Development And Web Development?
Every entrepreneur has to do two tasks at a time - one, to learn more efficient ways to progress fast in the business and second, to promote his business well for winning the attention of prospective customers and preventing them to turn to others. For the best business experience in terms of these two, he has to gauge what exactly he requires for the different needs that arise per se: a strong web presence, a responsive web application, a desktop application, and whatever. At such junctures, many business doers realize that web development and software application development may not be the same. Knowledge will only do good to you, better than getting a software made to work on your business infrastructure when you actually needed a web service. Let me differentiate the two for you: the software development and the web development.
Software development can be a part of web development, but web development is not always so. When you need a website or a web segment to run on it, you are looking for website development services. But, if you want a program that runs only on your PC or all the interconnected computers in your organization, you might be on your way to a desktop application or software. So, while a desktop software runs off the web, a web-based software application is intended to run in the web environment.
Most application development companies work on both the types of technologies. Here, you should know that technologies used in web-based activities often get replaced by something superior and more effective than the earlier one. Hence, you couldn't always stick to one that had been done once. As such, the role of a professional application and web developer could come in real handy for you. With his domain expertise, he could give you all the necessary support-based services for all types of your projects.
On the other hand, many business applications are better suited to be run on individual desktops, as they are clearly technologically defined and programmed to a specific purpose and also security concerns and legacy issue come to resolution. This kind of software development is without a subscription fee over the life of the software use. It's made once and purchased outright. Coming to the use of software in a web-based environment, there are a few common procedures like monitoring of online lead generation, customer conversion rates etc. for which a business would require web-based software programs.
Whether applications running on the web or offline and backend apps, both are handled by the professional software application development firms. They would always try to understand the business nature of the concerned firm before they work on any type of development strategy for it. You need not get worried about the quality of work produced by them. Just be clear on your needs and in telling them about the same.
Thursday, September 8, 2011
Monday, September 5, 2011
Top 100 Agile Books (Edition 2011)
One year ago, at the Agile 2010 conference, I came up with the idea to publish a Top 100 Agile Books. Like many of my other top 100 lists it was a great success (in terms of blog traffic).
This year I am not at the Agile 2011 conference (for various reasons, both good and bad). But nevertheless, I decided to publish a new edition of the Top 100 Agile Books, especially for my friends at Agile 2011 who are enjoying a great conference without me.
This list is based on quality (averate ratings) and quantity (number of ratings), both on Amazon.com and GoodReads.com. The age of the books also played a minor factor in the calculations. (Older books should keep acquiring new ratings, or else they drop in the list.)
Congratulations are in order for Roy Osherove, who pushed Mike Cohn away from the #1 slot, and Jonathan Rasmussen, the highest new entry this year with The Agile Samurai. Other high new entries are Specification by Example (Gojko Adzic), The Clean Coder (Bob Martin), The Elements of Scrum (Chris Sims), The Concise Executive Guide to Agile (Israel Gat) and Management 3.0 (hey, that’s me!).
Enjoy the list!
Update 12 August: I fixed an error in the calculations. The book Continuous Delivery (Jez Humble, David Farley) is now a new entry at #50.
TY = position this year
LY = position last year

