<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:a10="http://www.w3.org/2005/Atom" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Tugberk's Blog</title><link>http://www.tugberkugurlu.com/Feeds/Rss</link><description>Tugberk's Blog</description><image><url>http://tugberkugurlu.com/Content/Images/feed-image.png</url><title>Tugberk's Blog</title><link>http://www.tugberkugurlu.com/Feeds/Rss</link></image><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/TugberkUgurlu" /><feedburner:info uri="tugberkugurlu" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item><guid isPermaLink="false">http://tugberkugurlu.com/148</guid><link>http://feedproxy.google.com/~r/TugberkUgurlu/~3/Xp18WdYMfdk/148</link><title>Getting Started With OWIN and the Katana Stack</title><description>&lt;p&gt;As usual, I tweeted about my excitement which finally led me to this blog post:&lt;/p&gt;
&lt;blockquote class="twitter-tweet"&gt;
&lt;p&gt;It was amazing to be able to pull assemblies through NuGet w/o being tied to GAC. Now it's super awesome to do the same for web servers &lt;a href="https://twitter.com/search/%23win"&gt;#win&lt;/a&gt;&lt;/p&gt;
&amp;mdash; Tugberk Ugurlu (@tourismgeek) &lt;a href="https://twitter.com/tourismgeek/status/330721178765385728"&gt;May 4, 2013&lt;/a&gt;&lt;/blockquote&gt;
&lt;script src="//platform.twitter.com/widgets.js"&gt;&lt;/script&gt;
&lt;p&gt;&lt;a href="http://owin.org/"&gt;OWIN&lt;/a&gt; and &lt;a href="https://katanaproject.codeplex.com/"&gt;Katana project&lt;/a&gt; is the effort moving towards that direction and even through it's at its early stages, the adoption is promising. Katana is a flexible set of components for building and hosting OWIN-based web applications. This is the definition that I pulled from its Codeplex site. The stack includes several so-called OWIN middlewares, server and host implementations which work with OWIN-based web applications. You can literally get your application going within no time without needing any installations on the machine other than .NET itself. The other benefit is that your application is not tied to one web server; you can choose any of the web server and host implementations at any time without needing to recompile your project's code.&lt;/p&gt;
&lt;p&gt;To get started with Katana today, the best way is to jump to your Visual Studio and navigate to Tools &amp;gt; Library Package Manager &amp;gt; Package Manager Settings. From there, navigate to Package Sources and add the following sources:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;MyGet Katana: &lt;a title="http://myget.org/F/katana/" href="http://myget.org/F/katana/"&gt;http://myget.org/F/katana/&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;MyGet Owin: &lt;a title="http://myget.org/F/owin/" href="http://myget.org/F/owin/"&gt;http://myget.org/F/owin/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Now, we should be able to see those sources through PMC (Package Manager Console):&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Getting-Started-With-the-Katana-Stack_11A36/image.png"&gt;&lt;img title="image" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" border="0" alt="image" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Getting-Started-With-the-Katana-Stack_11A36/image_thumb.png" width="644" height="240" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We performed these actions because latest bits of the Katana and &lt;a href="https://github.com/owin/owin-hosting"&gt;OWIN Hosting&lt;/a&gt; project are pushed to MyGet and those packages are what you want to work with for now. As you can guess, those packages are not stable and not meant to be for production use but good for demonstration cases :) Let's start writing some code and see the beauty.&lt;/p&gt;
&lt;p&gt;I started by creating an empty C# Class Library project. Before moving forward, I would like to take a step back and see what packages I have. I selected the MyGet Owin as the current package source and executed the following command: Get-Package -ListAvailable -pre&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Getting-Started-With-the-Katana-Stack_11A36/image_3.png"&gt;&lt;img title="image" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" border="0" alt="image" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Getting-Started-With-the-Katana-Stack_11A36/image_thumb_3.png" width="644" height="331" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;These packages are coming from the &lt;a href="https://github.com/owin/owin-hosting"&gt;OWIN Hosting project&lt;/a&gt; and I encourage you to check the source code out. Let's do the same for the MyGet Katana source:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Getting-Started-With-the-Katana-Stack_11A36/image_4.png"&gt;&lt;img title="image" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" border="0" alt="image" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Getting-Started-With-the-Katana-Stack_11A36/image_thumb_4.png" width="644" height="465" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We got more packages this time and these packages are coming from the Katana project which is hosted on Codeplex. These packages consist of OWIN middlewares, host and server implementations which we will have a chance to use some of them now.&lt;/p&gt;
&lt;p&gt;Let's start installing a host implementation: Microsoft.Owin.Host.HttpListener pre-release package. Now, change the current package source selection to MyGet OWIN and install Owin.Extensions package to be able to get the necessary bits and pieces to complete our demo.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The Owin.Extensions package will bring down another package named &lt;a href="http://owin.org/"&gt;Owin&lt;/a&gt; and that Owin package is the only necessary package to have actually. The others are just there to help us but as you can understand, there is no assembly hell involved when working with OWIN. In fact, the Owin.dll only contains one interface which is IAppBuilder. You may wonder how this thing even works then. The answer is simple actually: by convention and discoverability on pure .NET types. To get a more in depth answer on that question, check out &lt;a href="http://vimeo.com/57007898"&gt;Louis DeJardin's awesome talk on OWIN&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;What we need to do now is have a class called Startup and that class will have a method called Configuration which takes an IAppBuilder implementation as a parameter.&lt;/p&gt;
&lt;div class="code-wrapper border-shadow-1"&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;&lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;partial&lt;/span&gt; &lt;span style="color: blue;"&gt;class&lt;/span&gt; Startup {

    &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; Configuration(IAppBuilder app) {

        app.UseHandler(async (request, response) =&amp;gt; {

            response.ContentType = &lt;span style="color: #a31515;"&gt;"text/html"&lt;/span&gt;;
            await response.WriteAsync(&lt;span style="color: #a31515;"&gt;"OWIN Hello World!!"&lt;/span&gt;);
        });
    }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;For the demonstration purposes, I used the UseHandler extension method to handle the requests and return the responses. In our case above, all paths will return the same response which is kind of silly but OK for demonstration purposes. To run this application, we need to some sort of a glue which needs to tie our Startup class with the host implementation that we have brought down: Microsoft.Owin.Host.HttpListener. That glue is the OwinHost.exe which we can install from the MyGet Katana NuGet feed.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Getting-Started-With-the-Katana-Stack_11A36/image_5.png"&gt;&lt;img title="image" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" border="0" alt="image" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Getting-Started-With-the-Katana-Stack_11A36/image_thumb_5.png" width="644" height="161" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;OwinHost.exe is going to prepare the settings to host the application and give them to the hosting implementation. Then, it will get out of the way. To make it run, execute the OwinHost.exe without any arguments under the root of your project and you should see screen as below:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Getting-Started-With-the-Katana-Stack_11A36/image27ea34fb-bc6e-4c13-baba-eb5f1725f337.png"&gt;&lt;img title="image" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" border="0" alt="image" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Getting-Started-With-the-Katana-Stack_11A36/image_thumb_6.png" width="644" height="193" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We got this unfriendly error message because the OwinHost.exe was unable to locate our assemblies as it looks under the bin directory but our project outputs the compiled assemblies under bin\Debug or bin\Release; depending on the configuration. Change the output directory to bin through the Properties menu, rebuild the solution and run the OwinHost.exe again. This time there should be no error and if we navigate to localhost:5000 (as 5000 is the default port), we should see that the response that we have prepared:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Getting-Started-With-the-Katana-Stack_11A36/image_6.png"&gt;&lt;img title="image" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" border="0" alt="image" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Getting-Started-With-the-Katana-Stack_11A36/image_thumb_7.png" width="644" height="390" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Cool! You may wonder how it knows to which host implementation to use. The default behavior is the auto-detect but we can explicitly specify the server type as well (however, it's &lt;a href="https://katanaproject.codeplex.com/workitem/29"&gt;kind of confusing how to do it today&lt;/a&gt;):&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Getting-Started-With-the-Katana-Stack_11A36/image.png"&gt;&lt;img title="image" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" border="0" alt="image" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Getting-Started-With-the-Katana-Stack_11A36/image_thumb_8.png" width="644" height="184" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;OwinHost.exe is great but as you can guess, it's not our only option. Thanks to Katana project, we can easily host our application on our own process. This option is particularly useful if you would like to deploy your application as a Windows Service or host your application on &lt;a href="http://www.windowsazure.com"&gt;Windows Azure&lt;/a&gt; Worker Role. To demonstrate this option, I created a console application and referenced our assembly. Then, I installed Microsoft.Owin.Hosting package to be able to host it easily. Here is the code to do that:&lt;/p&gt;
&lt;div class="code-wrapper border-shadow-1"&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;&lt;span style="color: blue;"&gt;class&lt;/span&gt; Program {

    &lt;span style="color: blue;"&gt;static&lt;/span&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; Main(&lt;span style="color: blue;"&gt;string&lt;/span&gt;[] args) {

        &lt;span style="color: blue;"&gt;using&lt;/span&gt; (IDisposable server = WebApp.Start&amp;lt;Startup&amp;gt;()) {

            Console.WriteLine(&lt;span style="color: #a31515;"&gt;"Started..."&lt;/span&gt;);
            Console.ReadKey();
        }
    }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;When I run the console application now, I can navigate to localhost:5000 again and see my response:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Getting-Started-With-the-Katana-Stack_11A36/image_7.png"&gt;&lt;img title="image" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" border="0" alt="image" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Getting-Started-With-the-Katana-Stack_11A36/image_thumb_9.png" width="644" height="375" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I plan on writing a few more posts on OWIN-based applications but for now, that's all I can give away :) The code I demoed here is available on GitHub as well: &lt;a href="https://github.com/tugberkugurlu/OwinSamples/tree/master/HelloWorldOwin"&gt;https://github.com/tugberkugurlu/OwinSamples/tree/master/HelloWorldOwin&lt;/a&gt;. but run the Build.cmd file before starting.&lt;/p&gt;
&lt;p&gt;Note: Earlier today, I was planning to play with &lt;a href="http://www.asp.net/web-api"&gt;ASP.NET Web API&lt;/a&gt;'s official OWIN host implementation (which will come out in vNext) and writing a blog post on that. &lt;a href="https://github.com/tugberkugurlu/OwinSamples/tree/master/WebApi50OwinSample"&gt;The playing part went well&lt;/a&gt; but Flip W. was again a Sergeant Buzzkill :s&lt;/p&gt;
&lt;blockquote class="twitter-tweet"&gt;
&lt;p&gt;@&lt;a href="https://twitter.com/tourismgeek"&gt;tourismgeek&lt;/a&gt; writing a post now&lt;/p&gt;
&amp;mdash; Filip W (@filip_woj) &lt;a href="https://twitter.com/filip_woj/status/330668689953288192"&gt;May 4, 2013&lt;/a&gt;&lt;/blockquote&gt;
&lt;script src="//platform.twitter.com/widgets.js"&gt;&lt;/script&gt;
&lt;h3&gt;&amp;nbsp;&lt;/h3&gt;
&lt;h3&gt;References&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://katanaproject.codeplex.com/"&gt;Katana Project&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/owin/owin-hosting"&gt;Official OWIN Hosting Project which includes OWIN hosting components&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://vimeo.com/57007898"&gt;OWIN - Run your C# for the web anywhere by Louis DeJardin&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://whereslou.com/2012/05/14/owin-compile-once-and-run-on-any-server"&gt;OWIN &amp;ndash; compile once and run on any server&lt;/a&gt; (kind of an old but still very useful blog post by Louis DeJardin)&lt;/li&gt;
&lt;/ul&gt;&lt;img src="http://feeds.feedburner.com/~r/TugberkUgurlu/~4/Xp18WdYMfdk" height="1" width="1"/&gt;</description><pubDate>Sat, 04 May 2013 21:04:00 Z</pubDate><a10:updated>2013-05-04T21:04:00Z</a10:updated><a10:content type="text">&lt;p&gt;As usual, I tweeted about my excitement which finally led me to this blog post:&lt;/p&gt;
&lt;blockquote class="twitter-tweet"&gt;
&lt;p&gt;It was amazing to be able to pull assemblies through NuGet w/o being tied to GAC. Now it's super awesome to do the same for web servers &lt;a href="https://twitter.com/search/%23win"&gt;#win&lt;/a&gt;&lt;/p&gt;
&amp;mdash; Tugberk Ugurlu (@tourismgeek) &lt;a href="https://twitter.com/tourismgeek/status/330721178765385728"&gt;May 4, 2013&lt;/a&gt;&lt;/blockquote&gt;
&lt;script src="//platform.twitter.com/widgets.js"&gt;&lt;/script&gt;
&lt;p&gt;&lt;a href="http://owin.org/"&gt;OWIN&lt;/a&gt; and &lt;a href="https://katanaproject.codeplex.com/"&gt;Katana project&lt;/a&gt; is the effort moving towards that direction and even through it's at its early stages, the adoption is promising. Katana is a flexible set of components for building and hosting OWIN-based web applications. This is the definition that I pulled from its Codeplex site. The stack includes several so-called OWIN middlewares, server and host implementations which work with OWIN-based web applications. You can literally get your application going within no time without needing any installations on the machine other than .NET itself. The other benefit is that your application is not tied to one web server; you can choose any of the web server and host implementations at any time without needing to recompile your project's code.&lt;/p&gt;
&lt;p&gt;To get started with Katana today, the best way is to jump to your Visual Studio and navigate to Tools &amp;gt; Library Package Manager &amp;gt; Package Manager Settings. From there, navigate to Package Sources and add the following sources:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;MyGet Katana: &lt;a title="http://myget.org/F/katana/" href="http://myget.org/F/katana/"&gt;http://myget.org/F/katana/&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;MyGet Owin: &lt;a title="http://myget.org/F/owin/" href="http://myget.org/F/owin/"&gt;http://myget.org/F/owin/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Now, we should be able to see those sources through PMC (Package Manager Console):&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Getting-Started-With-the-Katana-Stack_11A36/image.png"&gt;&lt;img title="image" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" border="0" alt="image" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Getting-Started-With-the-Katana-Stack_11A36/image_thumb.png" width="644" height="240" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We performed these actions because latest bits of the Katana and &lt;a href="https://github.com/owin/owin-hosting"&gt;OWIN Hosting&lt;/a&gt; project are pushed to MyGet and those packages are what you want to work with for now. As you can guess, those packages are not stable and not meant to be for production use but good for demonstration cases :) Let's start writing some code and see the beauty.&lt;/p&gt;
&lt;p&gt;I started by creating an empty C# Class Library project. Before moving forward, I would like to take a step back and see what packages I have. I selected the MyGet Owin as the current package source and executed the following command: Get-Package -ListAvailable -pre&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Getting-Started-With-the-Katana-Stack_11A36/image_3.png"&gt;&lt;img title="image" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" border="0" alt="image" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Getting-Started-With-the-Katana-Stack_11A36/image_thumb_3.png" width="644" height="331" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;These packages are coming from the &lt;a href="https://github.com/owin/owin-hosting"&gt;OWIN Hosting project&lt;/a&gt; and I encourage you to check the source code out. Let's do the same for the MyGet Katana source:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Getting-Started-With-the-Katana-Stack_11A36/image_4.png"&gt;&lt;img title="image" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" border="0" alt="image" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Getting-Started-With-the-Katana-Stack_11A36/image_thumb_4.png" width="644" height="465" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We got more packages this time and these packages are coming from the Katana project which is hosted on Codeplex. These packages consist of OWIN middlewares, host and server implementations which we will have a chance to use some of them now.&lt;/p&gt;
&lt;p&gt;Let's start installing a host implementation: Microsoft.Owin.Host.HttpListener pre-release package. Now, change the current package source selection to MyGet OWIN and install Owin.Extensions package to be able to get the necessary bits and pieces to complete our demo.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The Owin.Extensions package will bring down another package named &lt;a href="http://owin.org/"&gt;Owin&lt;/a&gt; and that Owin package is the only necessary package to have actually. The others are just there to help us but as you can understand, there is no assembly hell involved when working with OWIN. In fact, the Owin.dll only contains one interface which is IAppBuilder. You may wonder how this thing even works then. The answer is simple actually: by convention and discoverability on pure .NET types. To get a more in depth answer on that question, check out &lt;a href="http://vimeo.com/57007898"&gt;Louis DeJardin's awesome talk on OWIN&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;What we need to do now is have a class called Startup and that class will have a method called Configuration which takes an IAppBuilder implementation as a parameter.&lt;/p&gt;
&lt;div class="code-wrapper border-shadow-1"&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;&lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;partial&lt;/span&gt; &lt;span style="color: blue;"&gt;class&lt;/span&gt; Startup {

    &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; Configuration(IAppBuilder app) {

        app.UseHandler(async (request, response) =&amp;gt; {

            response.ContentType = &lt;span style="color: #a31515;"&gt;"text/html"&lt;/span&gt;;
            await response.WriteAsync(&lt;span style="color: #a31515;"&gt;"OWIN Hello World!!"&lt;/span&gt;);
        });
    }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;For the demonstration purposes, I used the UseHandler extension method to handle the requests and return the responses. In our case above, all paths will return the same response which is kind of silly but OK for demonstration purposes. To run this application, we need to some sort of a glue which needs to tie our Startup class with the host implementation that we have brought down: Microsoft.Owin.Host.HttpListener. That glue is the OwinHost.exe which we can install from the MyGet Katana NuGet feed.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Getting-Started-With-the-Katana-Stack_11A36/image_5.png"&gt;&lt;img title="image" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" border="0" alt="image" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Getting-Started-With-the-Katana-Stack_11A36/image_thumb_5.png" width="644" height="161" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;OwinHost.exe is going to prepare the settings to host the application and give them to the hosting implementation. Then, it will get out of the way. To make it run, execute the OwinHost.exe without any arguments under the root of your project and you should see screen as below:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Getting-Started-With-the-Katana-Stack_11A36/image27ea34fb-bc6e-4c13-baba-eb5f1725f337.png"&gt;&lt;img title="image" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" border="0" alt="image" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Getting-Started-With-the-Katana-Stack_11A36/image_thumb_6.png" width="644" height="193" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We got this unfriendly error message because the OwinHost.exe was unable to locate our assemblies as it looks under the bin directory but our project outputs the compiled assemblies under bin\Debug or bin\Release; depending on the configuration. Change the output directory to bin through the Properties menu, rebuild the solution and run the OwinHost.exe again. This time there should be no error and if we navigate to localhost:5000 (as 5000 is the default port), we should see that the response that we have prepared:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Getting-Started-With-the-Katana-Stack_11A36/image_6.png"&gt;&lt;img title="image" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" border="0" alt="image" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Getting-Started-With-the-Katana-Stack_11A36/image_thumb_7.png" width="644" height="390" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Cool! You may wonder how it knows to which host implementation to use. The default behavior is the auto-detect but we can explicitly specify the server type as well (however, it's &lt;a href="https://katanaproject.codeplex.com/workitem/29"&gt;kind of confusing how to do it today&lt;/a&gt;):&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Getting-Started-With-the-Katana-Stack_11A36/image.png"&gt;&lt;img title="image" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" border="0" alt="image" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Getting-Started-With-the-Katana-Stack_11A36/image_thumb_8.png" width="644" height="184" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;OwinHost.exe is great but as you can guess, it's not our only option. Thanks to Katana project, we can easily host our application on our own process. This option is particularly useful if you would like to deploy your application as a Windows Service or host your application on &lt;a href="http://www.windowsazure.com"&gt;Windows Azure&lt;/a&gt; Worker Role. To demonstrate this option, I created a console application and referenced our assembly. Then, I installed Microsoft.Owin.Hosting package to be able to host it easily. Here is the code to do that:&lt;/p&gt;
&lt;div class="code-wrapper border-shadow-1"&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;&lt;span style="color: blue;"&gt;class&lt;/span&gt; Program {

    &lt;span style="color: blue;"&gt;static&lt;/span&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; Main(&lt;span style="color: blue;"&gt;string&lt;/span&gt;[] args) {

        &lt;span style="color: blue;"&gt;using&lt;/span&gt; (IDisposable server = WebApp.Start&amp;lt;Startup&amp;gt;()) {

            Console.WriteLine(&lt;span style="color: #a31515;"&gt;"Started..."&lt;/span&gt;);
            Console.ReadKey();
        }
    }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;When I run the console application now, I can navigate to localhost:5000 again and see my response:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Getting-Started-With-the-Katana-Stack_11A36/image_7.png"&gt;&lt;img title="image" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" border="0" alt="image" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Getting-Started-With-the-Katana-Stack_11A36/image_thumb_9.png" width="644" height="375" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I plan on writing a few more posts on OWIN-based applications but for now, that's all I can give away :) The code I demoed here is available on GitHub as well: &lt;a href="https://github.com/tugberkugurlu/OwinSamples/tree/master/HelloWorldOwin"&gt;https://github.com/tugberkugurlu/OwinSamples/tree/master/HelloWorldOwin&lt;/a&gt;. but run the Build.cmd file before starting.&lt;/p&gt;
&lt;p&gt;Note: Earlier today, I was planning to play with &lt;a href="http://www.asp.net/web-api"&gt;ASP.NET Web API&lt;/a&gt;'s official OWIN host implementation (which will come out in vNext) and writing a blog post on that. &lt;a href="https://github.com/tugberkugurlu/OwinSamples/tree/master/WebApi50OwinSample"&gt;The playing part went well&lt;/a&gt; but Flip W. was again a Sergeant Buzzkill :s&lt;/p&gt;
&lt;blockquote class="twitter-tweet"&gt;
&lt;p&gt;@&lt;a href="https://twitter.com/tourismgeek"&gt;tourismgeek&lt;/a&gt; writing a post now&lt;/p&gt;
&amp;mdash; Filip W (@filip_woj) &lt;a href="https://twitter.com/filip_woj/status/330668689953288192"&gt;May 4, 2013&lt;/a&gt;&lt;/blockquote&gt;
&lt;script src="//platform.twitter.com/widgets.js"&gt;&lt;/script&gt;
&lt;h3&gt;&amp;nbsp;&lt;/h3&gt;
&lt;h3&gt;References&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://katanaproject.codeplex.com/"&gt;Katana Project&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/owin/owin-hosting"&gt;Official OWIN Hosting Project which includes OWIN hosting components&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://vimeo.com/57007898"&gt;OWIN - Run your C# for the web anywhere by Louis DeJardin&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://whereslou.com/2012/05/14/owin-compile-once-and-run-on-any-server"&gt;OWIN &amp;ndash; compile once and run on any server&lt;/a&gt; (kind of an old but still very useful blog post by Louis DeJardin)&lt;/li&gt;
&lt;/ul&gt;</a10:content><feedburner:origLink>http://tugberkugurlu.com/148</feedburner:origLink></item><item><guid isPermaLink="false">http://tugberkugurlu.com/147</guid><link>http://feedproxy.google.com/~r/TugberkUgurlu/~3/OcB_J6d2_ho/147</link><title>Cleaning up With PowerShell After Removing a Windows Azure Virtual Machine</title><description>&lt;p&gt;When you remove a &lt;a href="http://www.windowsazure.com"&gt;Windows Azure&lt;/a&gt; virtual machine, you are not actually removing everything. I hear you saying "What!!!"? Let's dive in then &lt;img src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Cleaning-up-After-Removing-a-VM_10D34/wlEmoticon-smile.png" alt="Smile" style="border-style: none;" class="wlEmoticon wlEmoticon-smile" /&gt;&lt;/p&gt;
&lt;p&gt;As each VM is kept under a cloud service, that cloud service one of those things that remain after you remove your VM. Other thing is the disk (or disks, depends on your case) which is attached to your VM. If you didn't attach any data disks, at least your OS disk will remain inside your storage account even if you remove your VM. However, you cannot go and directly delete that VHD file just like a typical blob because there is a lease on that blob as it's still viewed as one of your registered disks.&lt;/p&gt;
&lt;p&gt;Let's look at a case of mine on removing a Windows Azure VM. Yesterday, I created two VMs for demonstration purposes on a presentation and after the presentation, I removed those VMs by running "Remove-AzureVM" PowerShell command. So far, so good. When I go to the portal, I don't see those VMs as expected and I don't see any cloud services.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;If you create a VM, the new portal is not showing that you have a cloud service but it implicitly creates one for you under the covers. As soon as you attach another VM to that cloud service, the cloud service shows up on the new portal as well. In either of these cases, the generated cloud service is completely visible to you through the REST management API. So, you can view them through PowerShell Cmdlets.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Let's run "Get-AzureService" PowerShell command to see my cloud services:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Cleaning-up-After-Removing-a-VM_10D34/image.png"&gt;&lt;img height="307" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Cleaning-up-After-Removing-a-VM_10D34/image_thumb.png" alt="image" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;These are the generated cloud services which belong to my removed VMs. As far as I know, these cloud services won't cost me anything as they contain no deployments but it would be nice to remove them as I don't need them.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Cleaning-up-After-Removing-a-VM_10D34/image_3.png"&gt;&lt;img height="272" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Cleaning-up-After-Removing-a-VM_10D34/image_thumb_3.png" alt="image" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I got rid of the unnecessary cloud services. The next and final step of this cleaning is to remove the OS disks I have. This's actually more important because disk VHD files are stored inside the Windows Azure storage as blobs and each OS disk is approx. 127GB in size. So, I will pay for them as long as I keep them. Through new &lt;a href="http://michaelwasham.com/2013/03/27/windows-azure-powershell-cmdlets-now-supports-storage/"&gt;Windows Azure Storage PowerShell Cmdlets&lt;/a&gt;, I can view my VHD container to see which VHD files I have:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Cleaning-up-After-Removing-a-VM_10D34/imagee553a272-086d-41b6-83b0-8f714cde23b7.png"&gt;&lt;img height="237" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Cleaning-up-After-Removing-a-VM_10D34/image_thumb_4.png" alt="image" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;As you can see, I have two unnecessary VHD files which remained after my VM removal. At this stage, you might think directly deleting these blobs but as mentioned before, it will fail if we try to do that.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Cleaning-up-After-Removing-a-VM_10D34/image_4.png"&gt;&lt;img height="237" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Cleaning-up-After-Removing-a-VM_10D34/image_thumb_5.png" alt="image" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The error message I got is very descriptive actually: There is currently a lease on the blob and no lease ID was specified in the request. Let's run another PowerShell command to see which disks I have registered:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Cleaning-up-After-Removing-a-VM_10D34/image.png"&gt;&lt;img height="237" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Cleaning-up-After-Removing-a-VM_10D34/image_thumb_6.png" alt="image" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I have those two blobs registered as my disks and this prevents me from directly deleting them which is perfectly reasonable. To prove that this is actually the case, I will view the HTTP headers of one of those disks through &lt;a href="http://www.cloudberrylab.com/free-microsoft-azure-explorer.aspx"&gt;CloudBerry Explorer for Azure Blob Storage&lt;/a&gt;:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Cleaning-up-After-Removing-a-VM_10D34/image_5.png"&gt;&lt;img height="481" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Cleaning-up-After-Removing-a-VM_10D34/image_thumb_7.png" alt="image" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;You can see that "x-ms-lease-status" header is set to "locked" which states that there is a lease on the blob. Let's remove the "IstBootcampDemoTugberk-IstBootcampVM1-2013-4-27-132" disk from my registered disks:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Cleaning-up-After-Removing-a-VM_10D34/imagedb6fbd0b-91d9-4efd-a6d0-f1a50e0d98d3.png"&gt;&lt;img height="237" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Cleaning-up-After-Removing-a-VM_10D34/image_thumb_8.png" alt="image" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Now, let's look at the HTTP headers of the blob again:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Cleaning-up-After-Removing-a-VM_10D34/image_6.png"&gt;&lt;img height="481" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Cleaning-up-After-Removing-a-VM_10D34/image_thumb_9.png" alt="image" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The lease is now taken out and it's now possible to delete the blob:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Cleaning-up-After-Removing-a-VM_10D34/image.png"&gt;&lt;img height="228" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Cleaning-up-After-Removing-a-VM_10D34/image_thumb_10.png" alt="image" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;However, you can delete the disk from your registered disks list and the storage container in one go by running "Remove-AzureDisk" PowerShell Cmdlet with "DeleteVHD" switch:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Cleaning-up-After-Removing-a-VM_10D34/image_7.png"&gt;&lt;img height="228" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Cleaning-up-After-Removing-a-VM_10D34/image_thumb_11.png" alt="image" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The VHD file is completely gone. I hope the post was helpful &lt;img src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Cleaning-up-After-Removing-a-VM_10D34/wlEmoticon-smile.png" alt="Smile" style="border-style: none;" class="wlEmoticon wlEmoticon-smile" /&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TugberkUgurlu/~4/OcB_J6d2_ho" height="1" width="1"/&gt;</description><pubDate>Sun, 28 Apr 2013 17:10:00 Z</pubDate><a10:updated>2013-04-28T17:10:00Z</a10:updated><a10:content type="text">&lt;p&gt;When you remove a &lt;a href="http://www.windowsazure.com"&gt;Windows Azure&lt;/a&gt; virtual machine, you are not actually removing everything. I hear you saying "What!!!"? Let's dive in then &lt;img src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Cleaning-up-After-Removing-a-VM_10D34/wlEmoticon-smile.png" alt="Smile" style="border-style: none;" class="wlEmoticon wlEmoticon-smile" /&gt;&lt;/p&gt;
&lt;p&gt;As each VM is kept under a cloud service, that cloud service one of those things that remain after you remove your VM. Other thing is the disk (or disks, depends on your case) which is attached to your VM. If you didn't attach any data disks, at least your OS disk will remain inside your storage account even if you remove your VM. However, you cannot go and directly delete that VHD file just like a typical blob because there is a lease on that blob as it's still viewed as one of your registered disks.&lt;/p&gt;
&lt;p&gt;Let's look at a case of mine on removing a Windows Azure VM. Yesterday, I created two VMs for demonstration purposes on a presentation and after the presentation, I removed those VMs by running "Remove-AzureVM" PowerShell command. So far, so good. When I go to the portal, I don't see those VMs as expected and I don't see any cloud services.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;If you create a VM, the new portal is not showing that you have a cloud service but it implicitly creates one for you under the covers. As soon as you attach another VM to that cloud service, the cloud service shows up on the new portal as well. In either of these cases, the generated cloud service is completely visible to you through the REST management API. So, you can view them through PowerShell Cmdlets.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Let's run "Get-AzureService" PowerShell command to see my cloud services:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Cleaning-up-After-Removing-a-VM_10D34/image.png"&gt;&lt;img height="307" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Cleaning-up-After-Removing-a-VM_10D34/image_thumb.png" alt="image" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;These are the generated cloud services which belong to my removed VMs. As far as I know, these cloud services won't cost me anything as they contain no deployments but it would be nice to remove them as I don't need them.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Cleaning-up-After-Removing-a-VM_10D34/image_3.png"&gt;&lt;img height="272" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Cleaning-up-After-Removing-a-VM_10D34/image_thumb_3.png" alt="image" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I got rid of the unnecessary cloud services. The next and final step of this cleaning is to remove the OS disks I have. This's actually more important because disk VHD files are stored inside the Windows Azure storage as blobs and each OS disk is approx. 127GB in size. So, I will pay for them as long as I keep them. Through new &lt;a href="http://michaelwasham.com/2013/03/27/windows-azure-powershell-cmdlets-now-supports-storage/"&gt;Windows Azure Storage PowerShell Cmdlets&lt;/a&gt;, I can view my VHD container to see which VHD files I have:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Cleaning-up-After-Removing-a-VM_10D34/imagee553a272-086d-41b6-83b0-8f714cde23b7.png"&gt;&lt;img height="237" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Cleaning-up-After-Removing-a-VM_10D34/image_thumb_4.png" alt="image" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;As you can see, I have two unnecessary VHD files which remained after my VM removal. At this stage, you might think directly deleting these blobs but as mentioned before, it will fail if we try to do that.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Cleaning-up-After-Removing-a-VM_10D34/image_4.png"&gt;&lt;img height="237" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Cleaning-up-After-Removing-a-VM_10D34/image_thumb_5.png" alt="image" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The error message I got is very descriptive actually: There is currently a lease on the blob and no lease ID was specified in the request. Let's run another PowerShell command to see which disks I have registered:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Cleaning-up-After-Removing-a-VM_10D34/image.png"&gt;&lt;img height="237" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Cleaning-up-After-Removing-a-VM_10D34/image_thumb_6.png" alt="image" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I have those two blobs registered as my disks and this prevents me from directly deleting them which is perfectly reasonable. To prove that this is actually the case, I will view the HTTP headers of one of those disks through &lt;a href="http://www.cloudberrylab.com/free-microsoft-azure-explorer.aspx"&gt;CloudBerry Explorer for Azure Blob Storage&lt;/a&gt;:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Cleaning-up-After-Removing-a-VM_10D34/image_5.png"&gt;&lt;img height="481" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Cleaning-up-After-Removing-a-VM_10D34/image_thumb_7.png" alt="image" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;You can see that "x-ms-lease-status" header is set to "locked" which states that there is a lease on the blob. Let's remove the "IstBootcampDemoTugberk-IstBootcampVM1-2013-4-27-132" disk from my registered disks:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Cleaning-up-After-Removing-a-VM_10D34/imagedb6fbd0b-91d9-4efd-a6d0-f1a50e0d98d3.png"&gt;&lt;img height="237" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Cleaning-up-After-Removing-a-VM_10D34/image_thumb_8.png" alt="image" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Now, let's look at the HTTP headers of the blob again:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Cleaning-up-After-Removing-a-VM_10D34/image_6.png"&gt;&lt;img height="481" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Cleaning-up-After-Removing-a-VM_10D34/image_thumb_9.png" alt="image" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The lease is now taken out and it's now possible to delete the blob:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Cleaning-up-After-Removing-a-VM_10D34/image.png"&gt;&lt;img height="228" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Cleaning-up-After-Removing-a-VM_10D34/image_thumb_10.png" alt="image" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;However, you can delete the disk from your registered disks list and the storage container in one go by running "Remove-AzureDisk" PowerShell Cmdlet with "DeleteVHD" switch:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Cleaning-up-After-Removing-a-VM_10D34/image_7.png"&gt;&lt;img height="228" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Cleaning-up-After-Removing-a-VM_10D34/image_thumb_11.png" alt="image" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The VHD file is completely gone. I hope the post was helpful &lt;img src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Cleaning-up-After-Removing-a-VM_10D34/wlEmoticon-smile.png" alt="Smile" style="border-style: none;" class="wlEmoticon wlEmoticon-smile" /&gt;&lt;/p&gt;</a10:content><feedburner:origLink>http://tugberkugurlu.com/147</feedburner:origLink></item><item><guid isPermaLink="false">http://tugberkugurlu.com/146</guid><link>http://feedproxy.google.com/~r/TugberkUgurlu/~3/gCy33cka8-0/146</link><title>Windows Azure PowerShell Cmdlets In a Nutshell</title><description>&lt;p&gt;Managing your &lt;a href="http://www.windowsazure.com"&gt;Windows Azure&lt;/a&gt; services is super easy with the various management options and my favorite among these options is &lt;a href="http://msdn.microsoft.com/en-us/library/windowsazure/jj156055.aspx"&gt;Windows Azure PowerShell Cmdlets&lt;/a&gt;. It's very well-documented and if you know PowerShell enough, Windows Azure PowerShell Cmdlets are really easy to grasp. In this post I would like to give a few details about this management option and hopefully, it'll give you a head start.&lt;/p&gt;
&lt;h3&gt;Install it and get going&lt;/h3&gt;
&lt;p&gt;Installation of the Windows Azure PowerShell Cmdlets is very easy. &lt;a href="http://msdn.microsoft.com/en-us/library/windowsazure/jj554332.aspx"&gt;It's also well-documented&lt;/a&gt;. You can reach the download link from the &lt;a href="http://www.windowsazure.com/en-us/downloads/?fb=en-us"&gt;"Downloads" section on Windows Azure web site&lt;/a&gt;. From there, all you need to do is follow the instructions to install the Cmdlets through &lt;a href="http://www.microsoft.com/web/downloads/platform.aspx"&gt;Web Platform Installer&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;After the installation, we can view that we have the Windows Azure PowerShell Cmdlets installed on our system by running "Get-Module -ListAvailable" command:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/3477395e1f4d_135A1/image.png"&gt;&lt;img height="289" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/3477395e1f4d_135A1/image_thumb.png" alt="image" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;To get you started using Cmdlets, you can see the "&lt;a href="http://msdn.microsoft.com/en-us/library/windowsazure/jj554332.aspx"&gt;Get Started with Windows Azure Cmdlets&lt;/a&gt;" article which explains how you will set up the trust between your machine and your Windows Azure account. However, I will cover some steps here as well.&lt;/p&gt;
&lt;p&gt;First thing you need to do is download your publish settings file. There is a handy cmdlet to do this for you: Get-AzurePublishSettingsFile. By running this command, it will go to your account and create a management certificate for your account and download the necessary publish settings file.&lt;/p&gt;
&lt;p&gt;Next step is to import this publish settings file through another handy cmdlet: Import-AzurePublishSettingsFile &amp;lt;publishsettings-file-path&amp;gt;. This command is actually setting up lots of stuff on your machine.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Under "%appdata%\Windows Azure Powershell", it creates necessary configuration files for the cmdlets to get the authentication information.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/3477395e1f4d_135A1/image_3.png"&gt;&lt;img height="308" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/3477395e1f4d_135A1/image_thumb_3.png" alt="image" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;These configuration files don't actually contain certificate information on its own; they just hold the thumbprint of our management certificate and your subscription id.&lt;/li&gt;
&lt;li&gt;Actual certificate is imported inside your certificate store. You can view the installed certificate by running "dir Cert:\CurrentUser\My" command.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/3477395e1f4d_135A1/image_4.png"&gt;&lt;img height="272" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/3477395e1f4d_135A1/image_thumb_4.png" alt="image" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Now you are ready to go. Run "Get-AzureSubscription" command to see your subscription details and you will see that it's set as your default subscription. So, from now on, you don't need to do anything with your subscription. You can just run the commands without worrying about your credentials (of course, this maybe a good or bad thing; depends on your situation). For example, I ran the Get-AzureVM command to view my VMs:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/3477395e1f4d_135A1/image_5.png"&gt;&lt;img height="281" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/3477395e1f4d_135A1/image_thumb_5.png" alt="image" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;So, where is my stuff?&lt;/h3&gt;
&lt;p&gt;We installed the stuff and we just saw that it's working. So, where did all the stuff go and how does this thing even work? Well, if you know PowerShell, you also know that modules are stored under specific folders. You can view these folders by running the '&lt;em&gt;$env:PSModulePath.split(';')&lt;/em&gt;' command:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/3477395e1f4d_135A1/imageba8b64ba-dacb-48c8-b906-38e38283c022.png"&gt;&lt;img height="228" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/3477395e1f4d_135A1/image_thumb_6.png" alt="image" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Notice that there is a path for Windows Azure PowerShell Cmdlets, too. Without knowing this stuff, we could also view the module definition and get to its location from there:&lt;/p&gt;
&lt;div class="code-wrapper border-shadow-1"&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;Get&lt;span style="color: gray;"&gt;-&lt;/span&gt;Module &lt;span style="color: gray;"&gt;-&lt;/span&gt;ListAvailable &lt;span style="color: gray;"&gt;-&lt;/span&gt;Name Azure&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/3477395e1f4d_135A1/image_6.png"&gt;&lt;img height="228" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/3477395e1f4d_135A1/image_thumb_7.png" alt="image" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;"C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Azure" directory is where you will find the real meat:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/3477395e1f4d_135A1/image.png"&gt;&lt;img height="430" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/3477395e1f4d_135A1/image_thumb_8.png" alt="image" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;On the other hand, when we imported the publish settings, it puts a few stuff about my subscription under "%appdata%\Windows Azure Powershell". The certificate is also installed under my certificate store as mentioned before.&lt;/p&gt;
&lt;h3&gt;Clean Up&lt;/h3&gt;
&lt;p&gt;When you start managing your Windows Azure services through PowerShell Cmdlets, you have your Windows Azure account information and management certificate information at various places on your computer. Even if you uninstall your Windows Azure PowerShell Cmdlets from your machine, you are not basically cleaning up everything. Let's start by uninstalling the Cmdlets from your computer.&lt;/p&gt;
&lt;p&gt;Simply go to Control Panel &amp;gt; Programs &amp;gt; Programs and Features and find the installed program named as Windows Azure PowerShell and uninstall it. You will be done.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/3477395e1f4d_135A1/image_7.png"&gt;&lt;img height="401" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/3477395e1f4d_135A1/image_thumb_9.png" alt="image" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Next step is to go to "%appdata%\Windows Azure Powershell" directory and delete the folder completely. One more step to go now: delete your certificate. Find out what the thumbprint of your certificate is:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/3477395e1f4d_135A1/image97faf2c6-2bd0-4d7b-8132-e8acdc240dcc.png"&gt;&lt;img height="246" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/3477395e1f4d_135A1/image_thumb_10.png" alt="image" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Then, run the Remove-Item command to remove the certificate:&lt;/p&gt;
&lt;div class="code-wrapper border-shadow-1"&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;Remove&lt;span style="color: gray;"&gt;-&lt;/span&gt;Item Cert:\CurrentUser\My\507DAAF6F285C4A72A45909ACCEE552B4E2AE916 &amp;ndash;DeleteKey&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;You are all done uninstalling Windows Azure PowerShell Cmdlets. Remember, Windows Azure is powerful but it's more powerful when you manage it through PowerShell &lt;img src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/3477395e1f4d_135A1/wlEmoticon-smile.png" alt="Smile" style="border-style: none;" class="wlEmoticon wlEmoticon-smile" /&gt;&lt;/p&gt;
&lt;h3&gt;References&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windowsazure/jj156055.aspx"&gt;Windows Azure PowerShell (MSDN)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windowsazure/jj554332.aspx"&gt;Get Started with Windows Azure Cmdlets&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.windowsazure.com/en-us/develop/nodejs/how-to-guides/powershell-cmdlets"&gt;How to use Windows Azure PowerShell&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://michaelwasham.com/tag/windows-azure-powershell-cmdlets"&gt;Michael Washam&amp;rsquo;s Blog&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://michaelwasham.com/2013/04/16/windows-azure-powershell-updates-for-iaas-ga/"&gt;Windows Azure PowerShell Updates for IaaS GA&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://channel9.msdn.com/Shows/Cloud+Cover/Episode-105-General-Availability-of-Windows-Azure-Infrastructure-as-a-Service-IaaS"&gt;Cloud Cover Show - General Availability of Windows Azure Infrastructure as a Service (IaaS)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;img src="http://feeds.feedburner.com/~r/TugberkUgurlu/~4/gCy33cka8-0" height="1" width="1"/&gt;</description><pubDate>Fri, 26 Apr 2013 08:05:00 Z</pubDate><a10:updated>2013-04-26T08:05:00Z</a10:updated><a10:content type="text">&lt;p&gt;Managing your &lt;a href="http://www.windowsazure.com"&gt;Windows Azure&lt;/a&gt; services is super easy with the various management options and my favorite among these options is &lt;a href="http://msdn.microsoft.com/en-us/library/windowsazure/jj156055.aspx"&gt;Windows Azure PowerShell Cmdlets&lt;/a&gt;. It's very well-documented and if you know PowerShell enough, Windows Azure PowerShell Cmdlets are really easy to grasp. In this post I would like to give a few details about this management option and hopefully, it'll give you a head start.&lt;/p&gt;
&lt;h3&gt;Install it and get going&lt;/h3&gt;
&lt;p&gt;Installation of the Windows Azure PowerShell Cmdlets is very easy. &lt;a href="http://msdn.microsoft.com/en-us/library/windowsazure/jj554332.aspx"&gt;It's also well-documented&lt;/a&gt;. You can reach the download link from the &lt;a href="http://www.windowsazure.com/en-us/downloads/?fb=en-us"&gt;"Downloads" section on Windows Azure web site&lt;/a&gt;. From there, all you need to do is follow the instructions to install the Cmdlets through &lt;a href="http://www.microsoft.com/web/downloads/platform.aspx"&gt;Web Platform Installer&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;After the installation, we can view that we have the Windows Azure PowerShell Cmdlets installed on our system by running "Get-Module -ListAvailable" command:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/3477395e1f4d_135A1/image.png"&gt;&lt;img height="289" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/3477395e1f4d_135A1/image_thumb.png" alt="image" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;To get you started using Cmdlets, you can see the "&lt;a href="http://msdn.microsoft.com/en-us/library/windowsazure/jj554332.aspx"&gt;Get Started with Windows Azure Cmdlets&lt;/a&gt;" article which explains how you will set up the trust between your machine and your Windows Azure account. However, I will cover some steps here as well.&lt;/p&gt;
&lt;p&gt;First thing you need to do is download your publish settings file. There is a handy cmdlet to do this for you: Get-AzurePublishSettingsFile. By running this command, it will go to your account and create a management certificate for your account and download the necessary publish settings file.&lt;/p&gt;
&lt;p&gt;Next step is to import this publish settings file through another handy cmdlet: Import-AzurePublishSettingsFile &amp;lt;publishsettings-file-path&amp;gt;. This command is actually setting up lots of stuff on your machine.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Under "%appdata%\Windows Azure Powershell", it creates necessary configuration files for the cmdlets to get the authentication information.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/3477395e1f4d_135A1/image_3.png"&gt;&lt;img height="308" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/3477395e1f4d_135A1/image_thumb_3.png" alt="image" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;These configuration files don't actually contain certificate information on its own; they just hold the thumbprint of our management certificate and your subscription id.&lt;/li&gt;
&lt;li&gt;Actual certificate is imported inside your certificate store. You can view the installed certificate by running "dir Cert:\CurrentUser\My" command.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/3477395e1f4d_135A1/image_4.png"&gt;&lt;img height="272" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/3477395e1f4d_135A1/image_thumb_4.png" alt="image" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Now you are ready to go. Run "Get-AzureSubscription" command to see your subscription details and you will see that it's set as your default subscription. So, from now on, you don't need to do anything with your subscription. You can just run the commands without worrying about your credentials (of course, this maybe a good or bad thing; depends on your situation). For example, I ran the Get-AzureVM command to view my VMs:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/3477395e1f4d_135A1/image_5.png"&gt;&lt;img height="281" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/3477395e1f4d_135A1/image_thumb_5.png" alt="image" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;So, where is my stuff?&lt;/h3&gt;
&lt;p&gt;We installed the stuff and we just saw that it's working. So, where did all the stuff go and how does this thing even work? Well, if you know PowerShell, you also know that modules are stored under specific folders. You can view these folders by running the '&lt;em&gt;$env:PSModulePath.split(';')&lt;/em&gt;' command:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/3477395e1f4d_135A1/imageba8b64ba-dacb-48c8-b906-38e38283c022.png"&gt;&lt;img height="228" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/3477395e1f4d_135A1/image_thumb_6.png" alt="image" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Notice that there is a path for Windows Azure PowerShell Cmdlets, too. Without knowing this stuff, we could also view the module definition and get to its location from there:&lt;/p&gt;
&lt;div class="code-wrapper border-shadow-1"&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;Get&lt;span style="color: gray;"&gt;-&lt;/span&gt;Module &lt;span style="color: gray;"&gt;-&lt;/span&gt;ListAvailable &lt;span style="color: gray;"&gt;-&lt;/span&gt;Name Azure&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/3477395e1f4d_135A1/image_6.png"&gt;&lt;img height="228" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/3477395e1f4d_135A1/image_thumb_7.png" alt="image" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;"C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Azure" directory is where you will find the real meat:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/3477395e1f4d_135A1/image.png"&gt;&lt;img height="430" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/3477395e1f4d_135A1/image_thumb_8.png" alt="image" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;On the other hand, when we imported the publish settings, it puts a few stuff about my subscription under "%appdata%\Windows Azure Powershell". The certificate is also installed under my certificate store as mentioned before.&lt;/p&gt;
&lt;h3&gt;Clean Up&lt;/h3&gt;
&lt;p&gt;When you start managing your Windows Azure services through PowerShell Cmdlets, you have your Windows Azure account information and management certificate information at various places on your computer. Even if you uninstall your Windows Azure PowerShell Cmdlets from your machine, you are not basically cleaning up everything. Let's start by uninstalling the Cmdlets from your computer.&lt;/p&gt;
&lt;p&gt;Simply go to Control Panel &amp;gt; Programs &amp;gt; Programs and Features and find the installed program named as Windows Azure PowerShell and uninstall it. You will be done.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/3477395e1f4d_135A1/image_7.png"&gt;&lt;img height="401" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/3477395e1f4d_135A1/image_thumb_9.png" alt="image" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Next step is to go to "%appdata%\Windows Azure Powershell" directory and delete the folder completely. One more step to go now: delete your certificate. Find out what the thumbprint of your certificate is:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/3477395e1f4d_135A1/image97faf2c6-2bd0-4d7b-8132-e8acdc240dcc.png"&gt;&lt;img height="246" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/3477395e1f4d_135A1/image_thumb_10.png" alt="image" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Then, run the Remove-Item command to remove the certificate:&lt;/p&gt;
&lt;div class="code-wrapper border-shadow-1"&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;Remove&lt;span style="color: gray;"&gt;-&lt;/span&gt;Item Cert:\CurrentUser\My\507DAAF6F285C4A72A45909ACCEE552B4E2AE916 &amp;ndash;DeleteKey&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;You are all done uninstalling Windows Azure PowerShell Cmdlets. Remember, Windows Azure is powerful but it's more powerful when you manage it through PowerShell &lt;img src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/3477395e1f4d_135A1/wlEmoticon-smile.png" alt="Smile" style="border-style: none;" class="wlEmoticon wlEmoticon-smile" /&gt;&lt;/p&gt;
&lt;h3&gt;References&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windowsazure/jj156055.aspx"&gt;Windows Azure PowerShell (MSDN)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windowsazure/jj554332.aspx"&gt;Get Started with Windows Azure Cmdlets&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.windowsazure.com/en-us/develop/nodejs/how-to-guides/powershell-cmdlets"&gt;How to use Windows Azure PowerShell&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://michaelwasham.com/tag/windows-azure-powershell-cmdlets"&gt;Michael Washam&amp;rsquo;s Blog&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://michaelwasham.com/2013/04/16/windows-azure-powershell-updates-for-iaas-ga/"&gt;Windows Azure PowerShell Updates for IaaS GA&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://channel9.msdn.com/Shows/Cloud+Cover/Episode-105-General-Availability-of-Windows-Azure-Infrastructure-as-a-Service-IaaS"&gt;Cloud Cover Show - General Availability of Windows Azure Infrastructure as a Service (IaaS)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</a10:content><feedburner:origLink>http://tugberkugurlu.com/146</feedburner:origLink></item><item><guid isPermaLink="false">http://tugberkugurlu.com/145</guid><link>http://feedproxy.google.com/~r/TugberkUgurlu/~3/PzRBHfUQf1s/145</link><title>SignalR and Real-time Web Application Scenarios Webcast Recording (In Turkish) is Available</title><description>&lt;p&gt;A few days ago, I presented on a webcast about &lt;a href="http://asp.net/signalr"&gt;ASP.NET SignalR&lt;/a&gt; and real-time web application scenarios in Turkish and it went pretty great I think. I also managed to record the webcast successfully and put it on Vimeo.&lt;/p&gt;
&lt;p&gt;&lt;iframe width="500" frameborder="0" src="http://player.vimeo.com/video/64440243" height="281"&gt;&lt;/iframe&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://vimeo.com/64440243"&gt;SignalR ve Realtime Web Uygulama Senaryoları&lt;/a&gt; from &lt;a href="http://vimeo.com/user6670252"&gt;Tugberk Ugurlu&lt;/a&gt; on &lt;a href="http://vimeo.com"&gt;Vimeo&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Hope you'll like it &lt;img src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/f0b83f0129b5_7B23/wlEmoticon-smile.png" alt="Smile" style="border-style: none;" class="wlEmoticon wlEmoticon-smile" /&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TugberkUgurlu/~4/PzRBHfUQf1s" height="1" width="1"/&gt;</description><pubDate>Mon, 22 Apr 2013 05:52:00 Z</pubDate><a10:updated>2013-04-22T05:52:00Z</a10:updated><a10:content type="text">&lt;p&gt;A few days ago, I presented on a webcast about &lt;a href="http://asp.net/signalr"&gt;ASP.NET SignalR&lt;/a&gt; and real-time web application scenarios in Turkish and it went pretty great I think. I also managed to record the webcast successfully and put it on Vimeo.&lt;/p&gt;
&lt;p&gt;&lt;iframe width="500" frameborder="0" src="http://player.vimeo.com/video/64440243" height="281"&gt;&lt;/iframe&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://vimeo.com/64440243"&gt;SignalR ve Realtime Web Uygulama Senaryoları&lt;/a&gt; from &lt;a href="http://vimeo.com/user6670252"&gt;Tugberk Ugurlu&lt;/a&gt; on &lt;a href="http://vimeo.com"&gt;Vimeo&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Hope you'll like it &lt;img src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/f0b83f0129b5_7B23/wlEmoticon-smile.png" alt="Smile" style="border-style: none;" class="wlEmoticon wlEmoticon-smile" /&gt;&lt;/p&gt;</a10:content><feedburner:origLink>http://tugberkugurlu.com/145</feedburner:origLink></item><item><guid isPermaLink="false">http://tugberkugurlu.com/144</guid><link>http://feedproxy.google.com/~r/TugberkUgurlu/~3/9oRDohaOIeU/144</link><title>Istanbul Part of Global Windows Azure Bootcamp Events</title><description>&lt;p&gt;&lt;a href="http://globalwindowsazure.azurewebsites.net/"&gt;Global Windows Azure Bootcamp&lt;/a&gt; will be happening on the 27th of April, 2013 all over the World and Istanbul will be also hosting one of these events. Global Windows Azure Bootcamp Istanbul will be held at Microsoft Istanbul office and the registration is open. &lt;a href="http://azurebootcampturkiye-tugberk.eventbrite.com"&gt;You can register the event through Eventbrite&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://azurebootcampturkiye-tugberk.eventbrite.com"&gt;&lt;img title="azure" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" border="0" alt="azure" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/285601fd1107_12A53/azure.jpg" width="484" height="484" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://daron.yondem.com"&gt;Daron Yondem&lt;/a&gt;, &lt;a href="http://ilkayilknur.com"&gt;Ilkay Ilknur&lt;/a&gt; and myself will be presenting on several topics and you can view the list of sessions on the &lt;a href="http://azurebootcampturkiye-tugberk.eventbrite.com"&gt;event registration page&lt;/a&gt; as well. See you there &lt;img class="wlEmoticon wlEmoticon-smile" style="border-style: none;" alt="Smile" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/285601fd1107_12A53/wlEmoticon-smile.png" /&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TugberkUgurlu/~4/9oRDohaOIeU" height="1" width="1"/&gt;</description><pubDate>Fri, 19 Apr 2013 18:28:00 Z</pubDate><a10:updated>2013-04-19T18:28:00Z</a10:updated><a10:content type="text">&lt;p&gt;&lt;a href="http://globalwindowsazure.azurewebsites.net/"&gt;Global Windows Azure Bootcamp&lt;/a&gt; will be happening on the 27th of April, 2013 all over the World and Istanbul will be also hosting one of these events. Global Windows Azure Bootcamp Istanbul will be held at Microsoft Istanbul office and the registration is open. &lt;a href="http://azurebootcampturkiye-tugberk.eventbrite.com"&gt;You can register the event through Eventbrite&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://azurebootcampturkiye-tugberk.eventbrite.com"&gt;&lt;img title="azure" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" border="0" alt="azure" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/285601fd1107_12A53/azure.jpg" width="484" height="484" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://daron.yondem.com"&gt;Daron Yondem&lt;/a&gt;, &lt;a href="http://ilkayilknur.com"&gt;Ilkay Ilknur&lt;/a&gt; and myself will be presenting on several topics and you can view the list of sessions on the &lt;a href="http://azurebootcampturkiye-tugberk.eventbrite.com"&gt;event registration page&lt;/a&gt; as well. See you there &lt;img class="wlEmoticon wlEmoticon-smile" style="border-style: none;" alt="Smile" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/285601fd1107_12A53/wlEmoticon-smile.png" /&gt;&lt;/p&gt;</a10:content><feedburner:origLink>http://tugberkugurlu.com/144</feedburner:origLink></item><item><guid isPermaLink="false">http://tugberkugurlu.com/143</guid><link>http://feedproxy.google.com/~r/TugberkUgurlu/~3/ce-mXJdSup4/143</link><title>Links, Source Code and Slides From My Microsoft Web Camp Talks</title><description>&lt;p&gt;Within the &lt;a href="http://weblogs.asp.net/jgalloway/archive/2013/03/15/announcing-web-camps-spring-tour-2013.aspx"&gt;Microsoft Web Camps Spring 2013 Tour&lt;/a&gt;, &lt;a href="http://www.tugberkugurlu.com/archive/microsoft-web-camps-istanbul-on-the-6th-of-april"&gt;Web Camp Istanbul&lt;/a&gt; was held at Microsoft Istanbul office and we had such an incredible, enjoyable event. During the day, &lt;a href="http://weblogs.asp.net/jgalloway/"&gt;Jon Galloway&lt;/a&gt;, &lt;a href="http://blogs.msdn.com/b/umits/"&gt;Umit Sunar&lt;/a&gt; and &lt;span&gt;myself&amp;nbsp;&lt;/span&gt;presented several topics including &lt;a href="http://www.windowsazure.com"&gt;Windows Azure&lt;/a&gt;, &lt;a href="http://www.asp.net/mvc"&gt;ASP.NET MVC&lt;/a&gt;, &lt;a href="http://www.asp.net/web-api"&gt;ASP.NET Web API&lt;/a&gt; and &lt;a href="http://signalr.net"&gt;ASP.NET SignalR&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;During the day, I helped Jon by trying to be the dummy guy during his ASP.NET MVC presentation. I also presented on ASP.NET Web API and ASP.NET SignalR where I showed a few sample applications. You could find the source code for those samples on my GitHub repository: &lt;a href="https://github.com/tugberkugurlu/IstanbulWebCamps201304"&gt;https://github.com/tugberkugurlu/IstanbulWebCamps201304&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;You can also find the slides for the ASP.NET Web API session: &lt;a href="https://speakerdeck.com/tourismgeek/asp-dot-net-web-api-intro-microsoft-web-camp-istanbul-en"&gt;ASP.NET Web API Intro - Microsoft Web Camp, Istanbul&lt;/a&gt;. Here are also some links for the stuff that I have mentioned during the sessions.&lt;/p&gt;
&lt;h3&gt;ASP.NET SignalR&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://channel9.msdn.com/Events/Build/2012/3-034"&gt;Building Real-time Web Apps with ASP.NET SignalR&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/SignalR/SignalR/wiki"&gt;ASP.NET SignalR Wiki&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/tugberkugurlu/TweetMapR"&gt;TweetMapR Source Code (Including the Windows 8 Sample)&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/SignalR/Samples"&gt;SignalR Samples Repository&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/bradygaster/SignalR-Samples"&gt;Brady Gaster's SignalR Samples&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://jabbr.net/"&gt;JabbR: An IRC application built with SignalR&lt;/a&gt; (&lt;a href="https://github.com/davidfowl/JabbR"&gt;Source code is also available&lt;/a&gt;) &lt;/li&gt;
&lt;li&gt;&lt;a href="http://shootr.signalr.net/"&gt;ShootR: An awesome game built with SignalR + HTML5 features&lt;/a&gt; (&lt;a href="https://github.com/NTaylorMullen/ShootR"&gt;Source code is also available&lt;/a&gt;) &lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/SignalR/SignalR/wiki/Performance#maximum-concurrent-requests-per-cpu"&gt;IIS Configuration for High Number of Concurrent Requests for SignalR Applications&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;ASP.NET Web API&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://channel9.msdn.com/Events/Build/2012/3-036"&gt;Building Services for Any Client with ASP.NET Web API&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.asp.net/web-api"&gt;ASP.NET Web API Tutorials&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.asp.net/web-api/samples"&gt;ASP.NET Web API Samples&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://code.msdn.microsoft.com/Contact-Manager-Web-API-0e8e373d"&gt;Contact Manager - An ASP.NET Web API Sample Application (Including a Windows 8 Client)&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.amazon.com/gp/product/1430247258/ref=as_li_ss_tl?ie=UTF8&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=1430247258&amp;amp;linkCode=as2&amp;amp;tag=tugsblo0c-20"&gt;ASP.NET Web API Book&lt;/a&gt; (You can get the alpha version of &lt;a href="http://www.apress.com/9781430247258"&gt;Pro ASP.NET Web API book on Apress&lt;/a&gt; today) &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.fiddler2.com/fiddler2/"&gt;Fiddler&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I would like to thank Jon Galloway for coming to Istanbul for this event and allowing us to have such a fun day. I personally really enjoyed the whole event and also the small Istanbul tour I had with Jon &lt;img src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Links-Source-Code-and-Slides-From-My-Mic_12796/wlEmoticon-smile.png" alt="Smile" style="border-style: none;" class="wlEmoticon wlEmoticon-smile" /&gt; I also would like to thank &lt;a href="http://www.bradygaster.com/"&gt;Brady Gaster&lt;/a&gt; as he's one of the people who made this event happen. I'm hoping that we will keep seeing these types of web events in Istanbul more &lt;img src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Links-Source-Code-and-Slides-From-My-Mic_12796/wlEmoticon-smile.png" alt="Smile" style="border-style: none;" class="wlEmoticon wlEmoticon-smile" /&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TugberkUgurlu/~4/ce-mXJdSup4" height="1" width="1"/&gt;</description><pubDate>Sun, 07 Apr 2013 19:01:00 Z</pubDate><a10:updated>2013-04-07T19:01:00Z</a10:updated><a10:content type="text">&lt;p&gt;Within the &lt;a href="http://weblogs.asp.net/jgalloway/archive/2013/03/15/announcing-web-camps-spring-tour-2013.aspx"&gt;Microsoft Web Camps Spring 2013 Tour&lt;/a&gt;, &lt;a href="http://www.tugberkugurlu.com/archive/microsoft-web-camps-istanbul-on-the-6th-of-april"&gt;Web Camp Istanbul&lt;/a&gt; was held at Microsoft Istanbul office and we had such an incredible, enjoyable event. During the day, &lt;a href="http://weblogs.asp.net/jgalloway/"&gt;Jon Galloway&lt;/a&gt;, &lt;a href="http://blogs.msdn.com/b/umits/"&gt;Umit Sunar&lt;/a&gt; and &lt;span&gt;myself&amp;nbsp;&lt;/span&gt;presented several topics including &lt;a href="http://www.windowsazure.com"&gt;Windows Azure&lt;/a&gt;, &lt;a href="http://www.asp.net/mvc"&gt;ASP.NET MVC&lt;/a&gt;, &lt;a href="http://www.asp.net/web-api"&gt;ASP.NET Web API&lt;/a&gt; and &lt;a href="http://signalr.net"&gt;ASP.NET SignalR&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;During the day, I helped Jon by trying to be the dummy guy during his ASP.NET MVC presentation. I also presented on ASP.NET Web API and ASP.NET SignalR where I showed a few sample applications. You could find the source code for those samples on my GitHub repository: &lt;a href="https://github.com/tugberkugurlu/IstanbulWebCamps201304"&gt;https://github.com/tugberkugurlu/IstanbulWebCamps201304&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;You can also find the slides for the ASP.NET Web API session: &lt;a href="https://speakerdeck.com/tourismgeek/asp-dot-net-web-api-intro-microsoft-web-camp-istanbul-en"&gt;ASP.NET Web API Intro - Microsoft Web Camp, Istanbul&lt;/a&gt;. Here are also some links for the stuff that I have mentioned during the sessions.&lt;/p&gt;
&lt;h3&gt;ASP.NET SignalR&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://channel9.msdn.com/Events/Build/2012/3-034"&gt;Building Real-time Web Apps with ASP.NET SignalR&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/SignalR/SignalR/wiki"&gt;ASP.NET SignalR Wiki&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/tugberkugurlu/TweetMapR"&gt;TweetMapR Source Code (Including the Windows 8 Sample)&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/SignalR/Samples"&gt;SignalR Samples Repository&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/bradygaster/SignalR-Samples"&gt;Brady Gaster's SignalR Samples&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://jabbr.net/"&gt;JabbR: An IRC application built with SignalR&lt;/a&gt; (&lt;a href="https://github.com/davidfowl/JabbR"&gt;Source code is also available&lt;/a&gt;) &lt;/li&gt;
&lt;li&gt;&lt;a href="http://shootr.signalr.net/"&gt;ShootR: An awesome game built with SignalR + HTML5 features&lt;/a&gt; (&lt;a href="https://github.com/NTaylorMullen/ShootR"&gt;Source code is also available&lt;/a&gt;) &lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/SignalR/SignalR/wiki/Performance#maximum-concurrent-requests-per-cpu"&gt;IIS Configuration for High Number of Concurrent Requests for SignalR Applications&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;ASP.NET Web API&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://channel9.msdn.com/Events/Build/2012/3-036"&gt;Building Services for Any Client with ASP.NET Web API&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.asp.net/web-api"&gt;ASP.NET Web API Tutorials&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.asp.net/web-api/samples"&gt;ASP.NET Web API Samples&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://code.msdn.microsoft.com/Contact-Manager-Web-API-0e8e373d"&gt;Contact Manager - An ASP.NET Web API Sample Application (Including a Windows 8 Client)&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.amazon.com/gp/product/1430247258/ref=as_li_ss_tl?ie=UTF8&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=1430247258&amp;amp;linkCode=as2&amp;amp;tag=tugsblo0c-20"&gt;ASP.NET Web API Book&lt;/a&gt; (You can get the alpha version of &lt;a href="http://www.apress.com/9781430247258"&gt;Pro ASP.NET Web API book on Apress&lt;/a&gt; today) &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.fiddler2.com/fiddler2/"&gt;Fiddler&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I would like to thank Jon Galloway for coming to Istanbul for this event and allowing us to have such a fun day. I personally really enjoyed the whole event and also the small Istanbul tour I had with Jon &lt;img src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Links-Source-Code-and-Slides-From-My-Mic_12796/wlEmoticon-smile.png" alt="Smile" style="border-style: none;" class="wlEmoticon wlEmoticon-smile" /&gt; I also would like to thank &lt;a href="http://www.bradygaster.com/"&gt;Brady Gaster&lt;/a&gt; as he's one of the people who made this event happen. I'm hoping that we will keep seeing these types of web events in Istanbul more &lt;img src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Links-Source-Code-and-Slides-From-My-Mic_12796/wlEmoticon-smile.png" alt="Smile" style="border-style: none;" class="wlEmoticon wlEmoticon-smile" /&gt;&lt;/p&gt;</a10:content><feedburner:origLink>http://tugberkugurlu.com/143</feedburner:origLink></item><item><guid isPermaLink="false">http://tugberkugurlu.com/142</guid><link>http://feedproxy.google.com/~r/TugberkUgurlu/~3/cN4qOMXzJ9o/142</link><title>Basics of Git Rebase</title><description>&lt;p&gt;You may wonder why the title starts with "Basics". The answer is simple: I know only the basics of git rebase :) It's only one of the powerful features of git and it allows you to have a clean history in a highly branching workflow. "Rebase" is quite powerful as mentioned and what I'm about to show you is only one of the reasons why to use rebase. I highly recommend Keith &lt;a href="http://vimeo.com/43659036"&gt;Dahlby's NDC talk&lt;/a&gt; which he took some time to show the rebase feature.&lt;/p&gt;
&lt;p&gt;Let's see the easiest sample where rebase comes handy. We have the following history where we have two branches: master and feature-1.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Basics-of-Git-Rebase_11F73/image.png"&gt;&lt;img title="image" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" border="0" alt="image" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Basics-of-Git-Rebase_11F73/image_thumb.png" width="644" height="390" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Typically, what you would do here is to merge the feature-1 branch onto master which is fairly reasonable and it works. However, it creates you a unnecessary commit + a ridiculous graph which would be a mess if you think of hundreds of branches:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Basics-of-Git-Rebase_11F73/image_3.png"&gt;&lt;img title="image" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" border="0" alt="image" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Basics-of-Git-Rebase_11F73/image_thumb_3.png" width="644" height="345" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;What you can do with rebase is to patch the feature-1 branch onto master. Later then, you can merge from there. The following command is what you need to run:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Basics-of-Git-Rebase_11F73/image_4.png"&gt;&lt;img title="image" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" border="0" alt="image" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Basics-of-Git-Rebase_11F73/image_thumb_4.png" width="644" height="217" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;After running the rebase command, we can run "gitk &amp;ndash;all" to see the graph:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Basics-of-Git-Rebase_11F73/image_5.png"&gt;&lt;img title="image" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" border="0" alt="image" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Basics-of-Git-Rebase_11F73/image_thumb_5.png" width="644" height="345" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;It's now nice clean history. Notice that the master is still pointing where it was. It's because we haven't merge the feature-1 branch yet. Let's checkout to master branch and run "git merge feature-1" to merge feature-1 branch onto master branch:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Basics-of-Git-Rebase_11F73/image3e6a86da-a24a-497e-a74a-afc55251e34e.png"&gt;&lt;img title="image" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" border="0" alt="image" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Basics-of-Git-Rebase_11F73/image_thumb_6.png" width="644" height="296" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Nicely done! Open up the gitk one more time and see the clean history:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Basics-of-Git-Rebase_11F73/image_6.png"&gt;&lt;img title="image" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" border="0" alt="image" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Basics-of-Git-Rebase_11F73/image_thumb_7.png" width="644" height="349" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;After we remove the feature-1 branch by running "git branch &amp;ndash;D feature-1", we won't have any trace from feature-1 branch which is absolutely OK as feature branches are just the implementation details, that's all.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Basics-of-Git-Rebase_11F73/image.png"&gt;&lt;img title="image" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" border="0" alt="image" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Basics-of-Git-Rebase_11F73/image_thumb_8.png" width="644" height="349" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;Rebase can hurt&lt;/h3&gt;
&lt;p&gt;With git rebase, at the very basic level, you are messing with the history which can be dangerous depending on the case. On the other hand, when you have a collision, it's not a picnic to solve those collisions with interactive rebase without a deep firsthand knowledge but it's worth looking into even if it seems hard at the first glance &lt;img class="wlEmoticon wlEmoticon-smile" style="border-style: none;" alt="Smile" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Basics-of-Git-Rebase_11F73/wlEmoticon-smile.png" /&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TugberkUgurlu/~4/cN4qOMXzJ9o" height="1" width="1"/&gt;</description><pubDate>Sat, 30 Mar 2013 20:18:00 Z</pubDate><a10:updated>2013-03-30T20:18:00Z</a10:updated><a10:content type="text">&lt;p&gt;You may wonder why the title starts with "Basics". The answer is simple: I know only the basics of git rebase :) It's only one of the powerful features of git and it allows you to have a clean history in a highly branching workflow. "Rebase" is quite powerful as mentioned and what I'm about to show you is only one of the reasons why to use rebase. I highly recommend Keith &lt;a href="http://vimeo.com/43659036"&gt;Dahlby's NDC talk&lt;/a&gt; which he took some time to show the rebase feature.&lt;/p&gt;
&lt;p&gt;Let's see the easiest sample where rebase comes handy. We have the following history where we have two branches: master and feature-1.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Basics-of-Git-Rebase_11F73/image.png"&gt;&lt;img title="image" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" border="0" alt="image" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Basics-of-Git-Rebase_11F73/image_thumb.png" width="644" height="390" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Typically, what you would do here is to merge the feature-1 branch onto master which is fairly reasonable and it works. However, it creates you a unnecessary commit + a ridiculous graph which would be a mess if you think of hundreds of branches:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Basics-of-Git-Rebase_11F73/image_3.png"&gt;&lt;img title="image" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" border="0" alt="image" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Basics-of-Git-Rebase_11F73/image_thumb_3.png" width="644" height="345" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;What you can do with rebase is to patch the feature-1 branch onto master. Later then, you can merge from there. The following command is what you need to run:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Basics-of-Git-Rebase_11F73/image_4.png"&gt;&lt;img title="image" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" border="0" alt="image" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Basics-of-Git-Rebase_11F73/image_thumb_4.png" width="644" height="217" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;After running the rebase command, we can run "gitk &amp;ndash;all" to see the graph:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Basics-of-Git-Rebase_11F73/image_5.png"&gt;&lt;img title="image" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" border="0" alt="image" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Basics-of-Git-Rebase_11F73/image_thumb_5.png" width="644" height="345" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;It's now nice clean history. Notice that the master is still pointing where it was. It's because we haven't merge the feature-1 branch yet. Let's checkout to master branch and run "git merge feature-1" to merge feature-1 branch onto master branch:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Basics-of-Git-Rebase_11F73/image3e6a86da-a24a-497e-a74a-afc55251e34e.png"&gt;&lt;img title="image" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" border="0" alt="image" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Basics-of-Git-Rebase_11F73/image_thumb_6.png" width="644" height="296" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Nicely done! Open up the gitk one more time and see the clean history:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Basics-of-Git-Rebase_11F73/image_6.png"&gt;&lt;img title="image" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" border="0" alt="image" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Basics-of-Git-Rebase_11F73/image_thumb_7.png" width="644" height="349" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;After we remove the feature-1 branch by running "git branch &amp;ndash;D feature-1", we won't have any trace from feature-1 branch which is absolutely OK as feature branches are just the implementation details, that's all.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Basics-of-Git-Rebase_11F73/image.png"&gt;&lt;img title="image" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" border="0" alt="image" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Basics-of-Git-Rebase_11F73/image_thumb_8.png" width="644" height="349" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;Rebase can hurt&lt;/h3&gt;
&lt;p&gt;With git rebase, at the very basic level, you are messing with the history which can be dangerous depending on the case. On the other hand, when you have a collision, it's not a picnic to solve those collisions with interactive rebase without a deep firsthand knowledge but it's worth looking into even if it seems hard at the first glance &lt;img class="wlEmoticon wlEmoticon-smile" style="border-style: none;" alt="Smile" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Basics-of-Git-Rebase_11F73/wlEmoticon-smile.png" /&gt;&lt;/p&gt;</a10:content><feedburner:origLink>http://tugberkugurlu.com/142</feedburner:origLink></item><item><guid isPermaLink="false">http://tugberkugurlu.com/140</guid><link>http://feedproxy.google.com/~r/TugberkUgurlu/~3/V0qFJrIkq_I/140</link><title>Microsoft Web Camps Istanbul on the 6th of April</title><description>&lt;p&gt;&lt;a href="http://aka.ms/gotowebcamp"&gt;&lt;img height="211" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Web-Camps_118E2/WebCamps-Spring-2013.png" alt="WebCamps-Spring-2013" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="WebCamps-Spring-2013" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This is an awesome news that I am proud of to write about. I think it all started out with &lt;a href="https://twitter.com/tourismgeek/status/294364180318928896"&gt;my reply to Brady Gaster on twitter&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote class="twitter-tweet"&gt;
&lt;p&gt;@&lt;a href="https://twitter.com/bradygaster"&gt;bradygaster&lt;/a&gt; I would like to see a blog post from you titled as "Kicking off Web Camps Turkey".&lt;/p&gt;
&amp;mdash; Tugberk Ugurlu (@tourismgeek) &lt;a href="https://twitter.com/tourismgeek/status/294364180318928896"&gt;January 24, 2013&lt;/a&gt;&lt;/blockquote&gt;
&lt;script src="//platform.twitter.com/widgets.js"&gt;&lt;/script&gt;
&lt;p&gt;And it's now a real deal thanks to awesome Web Camps team! One leg of Microsoft Web Camps spring 2013 tour will be held in Microsoft Istanbul office on the 6th of April, 2013. It will be a full day event. &lt;a href="http://weblogs.asp.net/jgalloway/"&gt;Jon Galloway&lt;/a&gt;, &lt;a href="http://blogs.msdn.com/b/umits/"&gt;Umit Sunar&lt;/a&gt; and me will be giving talks on various latest Microsoft Web Stack technologies including&amp;nbsp;&lt;a href="http://www.windowsazure.com"&gt;Windows Azure&lt;/a&gt;, &lt;a href="http://www.asp.net/web-api"&gt;ASP.NET Web API&lt;/a&gt;, &lt;a href="http://signalr.net"&gt;ASP.NET SignalR&lt;/a&gt;, &lt;a href="http://www.asp.net/mvc"&gt;ASP.NET MVC&lt;/a&gt; and so on. You can see the typical agenda of Web Camps &lt;a href="http://www.devcamps.ms/web/agenda"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;You can also find more about Web Camps spring 2013 tour from Jon Galloway's and Brady Gaster's blog posts:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://weblogs.asp.net/jgalloway/archive/2013/03/15/announcing-web-camps-spring-tour-2013.aspx"&gt;Announcing Web Camps Spring Tour 2013&lt;/a&gt; by Jon Galloway&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.bradygaster.com/web-camps-dallas"&gt;Web Camps Dallas&lt;/a&gt; by Brady Gaster&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;There are finite number of seats available. So, register ASAP to participate this great event from the following link:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032548038&amp;amp;Culture=TR-TR&amp;amp;community=0" title="https://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032548038&amp;amp;Culture=TR-TR&amp;amp;community=0"&gt;https://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032548038&amp;amp;Culture=TR-TR&amp;amp;community=0&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;See you at Web Camps &lt;img src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Web-Camps_118E2/wlEmoticon-smile.png" alt="Smile" style="border-style: none;" class="wlEmoticon wlEmoticon-smile" /&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TugberkUgurlu/~4/V0qFJrIkq_I" height="1" width="1"/&gt;</description><pubDate>Sat, 23 Mar 2013 18:21:00 Z</pubDate><a10:updated>2013-03-23T18:21:00Z</a10:updated><a10:content type="text">&lt;p&gt;&lt;a href="http://aka.ms/gotowebcamp"&gt;&lt;img height="211" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Web-Camps_118E2/WebCamps-Spring-2013.png" alt="WebCamps-Spring-2013" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="WebCamps-Spring-2013" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This is an awesome news that I am proud of to write about. I think it all started out with &lt;a href="https://twitter.com/tourismgeek/status/294364180318928896"&gt;my reply to Brady Gaster on twitter&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote class="twitter-tweet"&gt;
&lt;p&gt;@&lt;a href="https://twitter.com/bradygaster"&gt;bradygaster&lt;/a&gt; I would like to see a blog post from you titled as "Kicking off Web Camps Turkey".&lt;/p&gt;
&amp;mdash; Tugberk Ugurlu (@tourismgeek) &lt;a href="https://twitter.com/tourismgeek/status/294364180318928896"&gt;January 24, 2013&lt;/a&gt;&lt;/blockquote&gt;
&lt;script src="//platform.twitter.com/widgets.js"&gt;&lt;/script&gt;
&lt;p&gt;And it's now a real deal thanks to awesome Web Camps team! One leg of Microsoft Web Camps spring 2013 tour will be held in Microsoft Istanbul office on the 6th of April, 2013. It will be a full day event. &lt;a href="http://weblogs.asp.net/jgalloway/"&gt;Jon Galloway&lt;/a&gt;, &lt;a href="http://blogs.msdn.com/b/umits/"&gt;Umit Sunar&lt;/a&gt; and me will be giving talks on various latest Microsoft Web Stack technologies including&amp;nbsp;&lt;a href="http://www.windowsazure.com"&gt;Windows Azure&lt;/a&gt;, &lt;a href="http://www.asp.net/web-api"&gt;ASP.NET Web API&lt;/a&gt;, &lt;a href="http://signalr.net"&gt;ASP.NET SignalR&lt;/a&gt;, &lt;a href="http://www.asp.net/mvc"&gt;ASP.NET MVC&lt;/a&gt; and so on. You can see the typical agenda of Web Camps &lt;a href="http://www.devcamps.ms/web/agenda"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;You can also find more about Web Camps spring 2013 tour from Jon Galloway's and Brady Gaster's blog posts:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://weblogs.asp.net/jgalloway/archive/2013/03/15/announcing-web-camps-spring-tour-2013.aspx"&gt;Announcing Web Camps Spring Tour 2013&lt;/a&gt; by Jon Galloway&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.bradygaster.com/web-camps-dallas"&gt;Web Camps Dallas&lt;/a&gt; by Brady Gaster&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;There are finite number of seats available. So, register ASAP to participate this great event from the following link:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032548038&amp;amp;Culture=TR-TR&amp;amp;community=0" title="https://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032548038&amp;amp;Culture=TR-TR&amp;amp;community=0"&gt;https://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032548038&amp;amp;Culture=TR-TR&amp;amp;community=0&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;See you at Web Camps &lt;img src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Web-Camps_118E2/wlEmoticon-smile.png" alt="Smile" style="border-style: none;" class="wlEmoticon wlEmoticon-smile" /&gt;&lt;/p&gt;</a10:content><feedburner:origLink>http://tugberkugurlu.com/140</feedburner:origLink></item><item><guid isPermaLink="false">http://tugberkugurlu.com/139</guid><link>http://feedproxy.google.com/~r/TugberkUgurlu/~3/ASPc5lJkN2A/139</link><title>MSP Turkey Kickoff Microsoft Web Stack Presentation Slides, Samples and Links</title><description>&lt;p&gt;I was at MSFT Istanbul office yesterday to give a presentation on Microsoft Web Stack for MSPs. It went pretty well I think. It was mostly focused on &lt;a href="http://asp.net/mvc"&gt;ASP.NET MVC 4&lt;/a&gt;, &lt;a href="http://signalr.net"&gt;SignalR&lt;/a&gt; and &lt;a href="http://www.asp.net/web-api"&gt;ASP.NET Web API&lt;/a&gt;. You can get the slides for the presentation from &lt;a href="https://speakerdeck.com/tourismgeek"&gt;my Speakerdeck account&lt;/a&gt;.&lt;/p&gt;
&lt;script class="speakerdeck-embed" data-id="3cf9ff4053e70130e3bd12313d091534" data-ratio="1.77777777777778" src="//speakerdeck.com/assets/embed.js"&gt;&lt;/script&gt;
&lt;p&gt;Source code for the sample applications I showed is available on GitHub:&amp;nbsp;&lt;a title="https://github.com/tugberkugurlu/MSPKickOff201302MSFTWebStack" href="https://github.com/tugberkugurlu/MSPKickOff201302MSFTWebStack"&gt;https://github.com/tugberkugurlu/MSPKickOff201302MSFTWebStack&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I also showed the Electric Plum's iPhone and iPad simulator and I used it right from VS. I followed through this awesome blog post from &lt;a href="http://twitter.com/shanselman"&gt;Scott Hanselman&lt;/a&gt; to set this up: &lt;a href="http://www.hanselman.com/blog/SimulatingAnIPhoneOrIPadBrowserForASPNETMobileWebDevelopmentWithWebMatrix2OrVisualStudio2012.aspx"&gt;Simulating an iPhone or iPad browser for ASP.NET Mobile Web Development with WebMatrix 2 or Visual Studio 2012&lt;/a&gt;. You can do the same. Here are a few other links which were touched upon during the presentation:&lt;/p&gt;
&lt;h3&gt;General Links&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://asp.net"&gt;Official ASP.NET Web Site&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.asp.net/mvc"&gt;ASP.NET MVC&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://asp.net/webforms"&gt;ASP.NET Web Forms&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://asp.net/web-pages"&gt;ASP.NET Web Pages&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.asp.net/web-api"&gt;ASP.NET Web API&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://asp.net/signalr"&gt;ASP.NET SignalR&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://aspnetwebstack.codeplex.com"&gt;ASP.NET Web Stack Open Source Repository&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://github.com/SignalR/SignalR"&gt;ASP.NET SignalR Open Source Repository&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="https://forums.asp.net"&gt;Official ASP.NET Forums&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;ASP.NET MVC&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.asp.net/mvc/tutorials"&gt;ASP.NET MVC Tutorials&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.asp.net/mvc/tutorials/mvc-4/aspnet-mvc-4-mobile-features"&gt;ASP.NET MVC and Mobile Features&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.hanselman.com/blog/SimulatingAnIPhoneOrIPadBrowserForASPNETMobileWebDevelopmentWithWebMatrix2OrVisualStudio2012.aspx"&gt;Scott Hanselman Blog Post for iPad and iPhone simulator&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;ASP.NET SignalR&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://channel9.msdn.com/Events/Build/2012/3-034"&gt;Building Real-time Web Apps with ASP.NET SignalR&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/SignalR/SignalR/wiki"&gt;ASP.NET SignalR Wiki&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/tugberkugurlu/TweetMapR"&gt;TweetMapR Source Code&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://jabbr.net/"&gt;JabbR: An IRC application built with SignalR&lt;/a&gt; (&lt;a href="https://github.com/davidfowl/JabbR"&gt;Source code is also available&lt;/a&gt;) &lt;/li&gt;
&lt;li&gt;&lt;a href="http://shootr.signalr.net/"&gt;ShootR: An awesome game built with SignalR + HTML5 features&lt;/a&gt; (&lt;a href="https://github.com/NTaylorMullen/ShootR"&gt;Source code is also available&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;ASP.NET Web API&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://channel9.msdn.com/Events/Build/2012/3-036"&gt;Building Services for Any Client with ASP.NET Web API&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.asp.net/web-api"&gt;ASP.NET Web API Tutorials&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.amazon.com/gp/product/1430247258/ref=as_li_ss_tl?ie=UTF8&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=1430247258&amp;amp;linkCode=as2&amp;amp;tag=tugsblo0c-20"&gt;ASP.NET Web API Book&lt;/a&gt; (You can get the alpha version of &lt;a href="http://www.apress.com/9781430247258"&gt;Pro ASP.NET Web API book on Apress&lt;/a&gt; today) &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.fiddler2.com/fiddler2/"&gt;Fiddler&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I would like to thank our MVP Lead &lt;a href="https://twitter.com/lhyfae"&gt;Sinem Eylem Arslan&lt;/a&gt; and &lt;a href="https://twitter.com/mustafakasap"&gt;Mustafa Kasap&lt;/a&gt; for the opportunity. Also, special thanks go to &lt;a href="http://www.xomni.com/"&gt;XOMNI&lt;/a&gt; team (&lt;a href="https://twitter.com/daronyondem"&gt;Daron Yondem&lt;/a&gt;, &lt;a href="https://twitter.com/gokhangulbiz"&gt;G&amp;ouml;khan G&amp;uuml;lbiz&lt;/a&gt;, &lt;a href="https://twitter.com/ilkayilknur"&gt;ilkay ilknur&lt;/a&gt;) for helping me to get though those 2 days in Istanbul. I have to say this: they seriously know how to live &lt;img class="wlEmoticon wlEmoticon-smile" style="border-style: none;" alt="Smile" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/2013-MSP-Turkey-Kick-off-Microsoft-Web-S_8C7E/wlEmoticon-smile.png" /&gt; Breakfast was amazing &lt;img class="wlEmoticon wlEmoticon-smile" style="border-style: none;" alt="Smile" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/2013-MSP-Turkey-Kick-off-Microsoft-Web-S_8C7E/wlEmoticon-smile.png" /&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TugberkUgurlu/~4/ASPc5lJkN2A" height="1" width="1"/&gt;</description><pubDate>Sat, 09 Feb 2013 14:22:00 Z</pubDate><a10:updated>2013-02-09T14:22:00Z</a10:updated><a10:content type="text">&lt;p&gt;I was at MSFT Istanbul office yesterday to give a presentation on Microsoft Web Stack for MSPs. It went pretty well I think. It was mostly focused on &lt;a href="http://asp.net/mvc"&gt;ASP.NET MVC 4&lt;/a&gt;, &lt;a href="http://signalr.net"&gt;SignalR&lt;/a&gt; and &lt;a href="http://www.asp.net/web-api"&gt;ASP.NET Web API&lt;/a&gt;. You can get the slides for the presentation from &lt;a href="https://speakerdeck.com/tourismgeek"&gt;my Speakerdeck account&lt;/a&gt;.&lt;/p&gt;
&lt;script class="speakerdeck-embed" data-id="3cf9ff4053e70130e3bd12313d091534" data-ratio="1.77777777777778" src="//speakerdeck.com/assets/embed.js"&gt;&lt;/script&gt;
&lt;p&gt;Source code for the sample applications I showed is available on GitHub:&amp;nbsp;&lt;a title="https://github.com/tugberkugurlu/MSPKickOff201302MSFTWebStack" href="https://github.com/tugberkugurlu/MSPKickOff201302MSFTWebStack"&gt;https://github.com/tugberkugurlu/MSPKickOff201302MSFTWebStack&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I also showed the Electric Plum's iPhone and iPad simulator and I used it right from VS. I followed through this awesome blog post from &lt;a href="http://twitter.com/shanselman"&gt;Scott Hanselman&lt;/a&gt; to set this up: &lt;a href="http://www.hanselman.com/blog/SimulatingAnIPhoneOrIPadBrowserForASPNETMobileWebDevelopmentWithWebMatrix2OrVisualStudio2012.aspx"&gt;Simulating an iPhone or iPad browser for ASP.NET Mobile Web Development with WebMatrix 2 or Visual Studio 2012&lt;/a&gt;. You can do the same. Here are a few other links which were touched upon during the presentation:&lt;/p&gt;
&lt;h3&gt;General Links&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://asp.net"&gt;Official ASP.NET Web Site&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.asp.net/mvc"&gt;ASP.NET MVC&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://asp.net/webforms"&gt;ASP.NET Web Forms&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://asp.net/web-pages"&gt;ASP.NET Web Pages&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.asp.net/web-api"&gt;ASP.NET Web API&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://asp.net/signalr"&gt;ASP.NET SignalR&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://aspnetwebstack.codeplex.com"&gt;ASP.NET Web Stack Open Source Repository&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://github.com/SignalR/SignalR"&gt;ASP.NET SignalR Open Source Repository&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="https://forums.asp.net"&gt;Official ASP.NET Forums&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;ASP.NET MVC&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.asp.net/mvc/tutorials"&gt;ASP.NET MVC Tutorials&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.asp.net/mvc/tutorials/mvc-4/aspnet-mvc-4-mobile-features"&gt;ASP.NET MVC and Mobile Features&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.hanselman.com/blog/SimulatingAnIPhoneOrIPadBrowserForASPNETMobileWebDevelopmentWithWebMatrix2OrVisualStudio2012.aspx"&gt;Scott Hanselman Blog Post for iPad and iPhone simulator&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;ASP.NET SignalR&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://channel9.msdn.com/Events/Build/2012/3-034"&gt;Building Real-time Web Apps with ASP.NET SignalR&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/SignalR/SignalR/wiki"&gt;ASP.NET SignalR Wiki&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/tugberkugurlu/TweetMapR"&gt;TweetMapR Source Code&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://jabbr.net/"&gt;JabbR: An IRC application built with SignalR&lt;/a&gt; (&lt;a href="https://github.com/davidfowl/JabbR"&gt;Source code is also available&lt;/a&gt;) &lt;/li&gt;
&lt;li&gt;&lt;a href="http://shootr.signalr.net/"&gt;ShootR: An awesome game built with SignalR + HTML5 features&lt;/a&gt; (&lt;a href="https://github.com/NTaylorMullen/ShootR"&gt;Source code is also available&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;ASP.NET Web API&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://channel9.msdn.com/Events/Build/2012/3-036"&gt;Building Services for Any Client with ASP.NET Web API&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.asp.net/web-api"&gt;ASP.NET Web API Tutorials&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.amazon.com/gp/product/1430247258/ref=as_li_ss_tl?ie=UTF8&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=1430247258&amp;amp;linkCode=as2&amp;amp;tag=tugsblo0c-20"&gt;ASP.NET Web API Book&lt;/a&gt; (You can get the alpha version of &lt;a href="http://www.apress.com/9781430247258"&gt;Pro ASP.NET Web API book on Apress&lt;/a&gt; today) &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.fiddler2.com/fiddler2/"&gt;Fiddler&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I would like to thank our MVP Lead &lt;a href="https://twitter.com/lhyfae"&gt;Sinem Eylem Arslan&lt;/a&gt; and &lt;a href="https://twitter.com/mustafakasap"&gt;Mustafa Kasap&lt;/a&gt; for the opportunity. Also, special thanks go to &lt;a href="http://www.xomni.com/"&gt;XOMNI&lt;/a&gt; team (&lt;a href="https://twitter.com/daronyondem"&gt;Daron Yondem&lt;/a&gt;, &lt;a href="https://twitter.com/gokhangulbiz"&gt;G&amp;ouml;khan G&amp;uuml;lbiz&lt;/a&gt;, &lt;a href="https://twitter.com/ilkayilknur"&gt;ilkay ilknur&lt;/a&gt;) for helping me to get though those 2 days in Istanbul. I have to say this: they seriously know how to live &lt;img class="wlEmoticon wlEmoticon-smile" style="border-style: none;" alt="Smile" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/2013-MSP-Turkey-Kick-off-Microsoft-Web-S_8C7E/wlEmoticon-smile.png" /&gt; Breakfast was amazing &lt;img class="wlEmoticon wlEmoticon-smile" style="border-style: none;" alt="Smile" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/2013-MSP-Turkey-Kick-off-Microsoft-Web-S_8C7E/wlEmoticon-smile.png" /&gt;&lt;/p&gt;</a10:content><feedburner:origLink>http://tugberkugurlu.com/139</feedburner:origLink></item><item><guid isPermaLink="false">http://tugberkugurlu.com/138</guid><link>http://feedproxy.google.com/~r/TugberkUgurlu/~3/5jC4MR91peI/138</link><title>Autofac Open Generics Feature to Register Generic Services</title><description>&lt;p&gt;This is going to be a quick and dirty blog post but hopefully, will take this giant stupidity out of me. &lt;a href="http://code.google.com/p/autofac/"&gt;Autofac&lt;/a&gt;, an awesome &lt;a href="http://martinfowler.com/articles/injection.html"&gt;IoC container&lt;/a&gt; for .NET platform, has an out of the box &lt;a href="http://code.google.com/p/autofac/wiki/OpenGenerics"&gt;generic service registration feature&lt;/a&gt; and I assume nearly all IoC containers have this today which makes me feel stupid because I have been knowing this for only a month or so &lt;img src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Autofac-Open-Generics_AE48/wlEmoticon-smile.png" alt="Smile" style="border-style: none;" class="wlEmoticon wlEmoticon-smile" /&gt; I was doing something like below before.&lt;/p&gt;
&lt;div class="code-wrapper border-shadow-1"&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;&lt;span style="color: blue;"&gt;private&lt;/span&gt; &lt;span style="color: blue;"&gt;static&lt;/span&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; RegisterRepositories(ContainerBuilder builder) {
 
    Type baseEntityType = &lt;span style="color: blue;"&gt;typeof&lt;/span&gt;(BaseEntity);
    Assembly assembly = baseEntityType.Assembly;
    IEnumerable&amp;lt;Type&amp;gt; entityTypes = assembly.GetTypes().Where(
        x =&amp;gt; x.IsSubclassOf(baseEntityType));
        
    &lt;span style="color: blue;"&gt;foreach&lt;/span&gt; (Type type &lt;span style="color: blue;"&gt;in&lt;/span&gt; entityTypes) {
 
        builder.RegisterType(&lt;span style="color: blue;"&gt;typeof&lt;/span&gt;(EntityRepository&amp;lt;&amp;gt;)
               .MakeGenericType(type))
               .As(&lt;span style="color: blue;"&gt;typeof&lt;/span&gt;(IEntityRepository&amp;lt;&amp;gt;).MakeGenericType(type))
               .InstancePerApiRequest();
    }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Then, &lt;a href="https://twitter.com/benfosterdev"&gt;Ben Foster&lt;/a&gt; pinged me on twitter:&lt;/p&gt;
&lt;blockquote class="twitter-tweet"&gt;
&lt;p&gt;@&lt;a href="https://twitter.com/tourismgeek"&gt;tourismgeek&lt;/a&gt; what, no For(type of(IFoo&amp;lt;&amp;gt;).Use(typeof(Foo&amp;lt;&amp;gt;)? Even Ninject supports that.&lt;/p&gt;
&amp;mdash; Ben Foster (@benfosterdev) &lt;a href="https://twitter.com/benfosterdev/status/281315791910080513"&gt;December 19, 2012&lt;/a&gt;&lt;/blockquote&gt;
&lt;script src="//platform.twitter.com/widgets.js"&gt;&lt;/script&gt;
&lt;p&gt;This tweet made me look for alternative approaches and I found out the Autofac's generic service registration feature. Here is how it looks like now:&lt;/p&gt;
&lt;div class="code-wrapper border-shadow-1"&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;&lt;span style="color: blue;"&gt;private&lt;/span&gt; &lt;span style="color: blue;"&gt;static&lt;/span&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; RegisterRepositories(ContainerBuilder builder) {
 
    builder.RegisterGeneric(&lt;span style="color: blue;"&gt;typeof&lt;/span&gt;(EntityRepository&amp;lt;&amp;gt;))
           .As(&lt;span style="color: blue;"&gt;typeof&lt;/span&gt;(IEntityRepository&amp;lt;&amp;gt;))
           .InstancePerApiRequest();
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Way better! Autofac also respects generic type constraints. Here is a quote from the &lt;a href="http://code.google.com/p/autofac/wiki/OpenGenerics"&gt;Autofac documentation&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Autofac respects generic type constraints. If a constraint on the implementation type makes it unable to provide a service the implementation type will be ignored.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;If you didn't know this feature before, you do know it now &lt;img src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Autofac-Open-Generics_AE48/wlEmoticon-smile.png" alt="Smile" style="border-style: none;" class="wlEmoticon wlEmoticon-smile" /&gt; Enjoy it!&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TugberkUgurlu/~4/5jC4MR91peI" height="1" width="1"/&gt;</description><pubDate>Tue, 05 Feb 2013 10:46:00 Z</pubDate><a10:updated>2013-02-05T10:46:00Z</a10:updated><a10:content type="text">&lt;p&gt;This is going to be a quick and dirty blog post but hopefully, will take this giant stupidity out of me. &lt;a href="http://code.google.com/p/autofac/"&gt;Autofac&lt;/a&gt;, an awesome &lt;a href="http://martinfowler.com/articles/injection.html"&gt;IoC container&lt;/a&gt; for .NET platform, has an out of the box &lt;a href="http://code.google.com/p/autofac/wiki/OpenGenerics"&gt;generic service registration feature&lt;/a&gt; and I assume nearly all IoC containers have this today which makes me feel stupid because I have been knowing this for only a month or so &lt;img src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Autofac-Open-Generics_AE48/wlEmoticon-smile.png" alt="Smile" style="border-style: none;" class="wlEmoticon wlEmoticon-smile" /&gt; I was doing something like below before.&lt;/p&gt;
&lt;div class="code-wrapper border-shadow-1"&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;&lt;span style="color: blue;"&gt;private&lt;/span&gt; &lt;span style="color: blue;"&gt;static&lt;/span&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; RegisterRepositories(ContainerBuilder builder) {
 
    Type baseEntityType = &lt;span style="color: blue;"&gt;typeof&lt;/span&gt;(BaseEntity);
    Assembly assembly = baseEntityType.Assembly;
    IEnumerable&amp;lt;Type&amp;gt; entityTypes = assembly.GetTypes().Where(
        x =&amp;gt; x.IsSubclassOf(baseEntityType));
        
    &lt;span style="color: blue;"&gt;foreach&lt;/span&gt; (Type type &lt;span style="color: blue;"&gt;in&lt;/span&gt; entityTypes) {
 
        builder.RegisterType(&lt;span style="color: blue;"&gt;typeof&lt;/span&gt;(EntityRepository&amp;lt;&amp;gt;)
               .MakeGenericType(type))
               .As(&lt;span style="color: blue;"&gt;typeof&lt;/span&gt;(IEntityRepository&amp;lt;&amp;gt;).MakeGenericType(type))
               .InstancePerApiRequest();
    }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Then, &lt;a href="https://twitter.com/benfosterdev"&gt;Ben Foster&lt;/a&gt; pinged me on twitter:&lt;/p&gt;
&lt;blockquote class="twitter-tweet"&gt;
&lt;p&gt;@&lt;a href="https://twitter.com/tourismgeek"&gt;tourismgeek&lt;/a&gt; what, no For(type of(IFoo&amp;lt;&amp;gt;).Use(typeof(Foo&amp;lt;&amp;gt;)? Even Ninject supports that.&lt;/p&gt;
&amp;mdash; Ben Foster (@benfosterdev) &lt;a href="https://twitter.com/benfosterdev/status/281315791910080513"&gt;December 19, 2012&lt;/a&gt;&lt;/blockquote&gt;
&lt;script src="//platform.twitter.com/widgets.js"&gt;&lt;/script&gt;
&lt;p&gt;This tweet made me look for alternative approaches and I found out the Autofac's generic service registration feature. Here is how it looks like now:&lt;/p&gt;
&lt;div class="code-wrapper border-shadow-1"&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;&lt;span style="color: blue;"&gt;private&lt;/span&gt; &lt;span style="color: blue;"&gt;static&lt;/span&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; RegisterRepositories(ContainerBuilder builder) {
 
    builder.RegisterGeneric(&lt;span style="color: blue;"&gt;typeof&lt;/span&gt;(EntityRepository&amp;lt;&amp;gt;))
           .As(&lt;span style="color: blue;"&gt;typeof&lt;/span&gt;(IEntityRepository&amp;lt;&amp;gt;))
           .InstancePerApiRequest();
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Way better! Autofac also respects generic type constraints. Here is a quote from the &lt;a href="http://code.google.com/p/autofac/wiki/OpenGenerics"&gt;Autofac documentation&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Autofac respects generic type constraints. If a constraint on the implementation type makes it unable to provide a service the implementation type will be ignored.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;If you didn't know this feature before, you do know it now &lt;img src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Autofac-Open-Generics_AE48/wlEmoticon-smile.png" alt="Smile" style="border-style: none;" class="wlEmoticon wlEmoticon-smile" /&gt; Enjoy it!&lt;/p&gt;</a10:content><feedburner:origLink>http://tugberkugurlu.com/138</feedburner:origLink></item><item><guid isPermaLink="false">http://tugberkugurlu.com/137</guid><link>http://feedproxy.google.com/~r/TugberkUgurlu/~3/GJ3r2AcXI_E/137</link><title>Hierarchical Resource Structure in ASP.NET Web API</title><description>&lt;p&gt;I came across a question on &lt;a href="http://stackoverflow.com"&gt;Stackoverflow&lt;/a&gt; today about the hierarchical resource structure in &lt;a href="http://www.asp.net/web-api"&gt;ASP.NET Web API&lt;/a&gt;: &lt;a title="http://stackoverflow.com/questions/14674255" href="http://stackoverflow.com/questions/14674255"&gt;http://stackoverflow.com/questions/14674255&lt;/a&gt;. The question is basically about the following issue:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;I have the following schema that I'd like to implement in ASP.NET Web API. What is the proper approach?&lt;/p&gt;
&lt;p&gt;http://mydomain/api/students&lt;br /&gt;http://mydomain/api/students/s123&lt;br /&gt;http://mydomain/api/students/s123/classes&lt;br /&gt;http://mydomain/api/students/s123/classes/c456&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;With this nice hierarchical approach, you have more concerns that routing here in terms of ASP.NET Web API. There is a good sample application which adopts the hierarchical resource structure: &lt;a href="https://github.com/tugberkugurlu/PingYourPackage"&gt;PingYourPackage&lt;/a&gt;. I definitely suggest you to check it out.&lt;/p&gt;
&lt;p&gt;Let me explain the concerns here in details by setting up a sample scenario. This may not be the desired approach for these types of situations but lays out the concerns very well and if you have a better way to eliminate these concerns, I'd be more that happy to hear those.&lt;/p&gt;
&lt;p&gt;Let's say you have the below two affiliates inside your database for a shipment company:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Affiliate1 (Id: 100) &lt;/li&gt;
&lt;li&gt;Affiliate2 (Id: 101)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;And then assume that these affiliates have some shipments attached to them:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Affiliate1 (Key: 100)   
&lt;ul&gt;
&lt;li&gt;Shipment1 (Key: 100) &lt;/li&gt;
&lt;li&gt;Shipment2 (Key: 102) &lt;/li&gt;
&lt;li&gt;Shipment4 (Key: 104)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Affiliate2 (Key: 101)   
&lt;ul&gt;
&lt;li&gt;Shipment3 (Key: 103) &lt;/li&gt;
&lt;li&gt;Shipment5 (Key: 105)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Finally, we want to have the following resource structure:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;GET api/affiliates/{key}/shipments &lt;/li&gt;
&lt;li&gt;GET api/affiliates/{key}/shipments/{shipmentKey} &lt;/li&gt;
&lt;li&gt;POST api/affiliates/{key}/shipments &lt;/li&gt;
&lt;li&gt;PUT api/affiliates/{key}/shipments/{shipmentKey} &lt;/li&gt;
&lt;li&gt;DELETE api/affiliates/{key}/shipments/{shipmentKey}&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In view of ASP.NET Web API, we have three obvious concerns here: routing, authorization and ownership. Let's go through this one by one.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The below code snippets have been taken from the &lt;a href="https://github.com/tugberkugurlu/PingYourPackage"&gt;PingYourPackage&lt;/a&gt; source code. They won't probably work if you copy and paste them but you will get the idea.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;Routing Concerns&lt;/h3&gt;
&lt;p&gt;Assume that we are sending a GET request against /api/affiliates/105/shipments/102 (considering our above scenario). Notice that the affiliate key is 105 here which doesn't exist. So, we would want to terminate the request here ASAP. We can achieve this with a per-route message handler as early as possible. The following AffiliateShipmentsDispatcher is responsible for checking the affiliate existence and acting on the result.&lt;/p&gt;
&lt;div class="code-wrapper border-shadow-1"&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;&lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;class&lt;/span&gt; AffiliateShipmentsDispatcher : DelegatingHandler {

  &lt;span style="color: blue;"&gt;protected&lt;/span&gt; &lt;span style="color: blue;"&gt;override&lt;/span&gt; Task&amp;lt;HttpResponseMessage&amp;gt; SendAsync(
      HttpRequestMessage request, 
      CancellationToken cancellationToken) {

      &lt;span style="color: green;"&gt;// We know at this point that the {key} route variable has &lt;/span&gt;
      &lt;span style="color: green;"&gt;// been supplied. Otherwise, we wouldn't be here. So, just get it.&lt;/span&gt;
      IHttpRouteData routeData = request.GetRouteData();
      Guid affiliateKey = Guid.ParseExact(routeData.Values[&lt;span style="color: #a31515;"&gt;"key"&lt;/span&gt;].ToString(), &lt;span style="color: #a31515;"&gt;"D"&lt;/span&gt;);

      IShipmentService shipmentService = request.GetShipmentService();
      &lt;span style="color: blue;"&gt;if&lt;/span&gt; (shipmentService.GetAffiliate(affiliateKey) == &lt;span style="color: blue;"&gt;null&lt;/span&gt;) {

          &lt;span style="color: blue;"&gt;return&lt;/span&gt; Task.FromResult(
              request.CreateResponse(HttpStatusCode.NotFound));
      }

      &lt;span style="color: blue;"&gt;return&lt;/span&gt; &lt;span style="color: blue;"&gt;base&lt;/span&gt;.SendAsync(request, cancellationToken);
  }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;I am here using a few internal extension methods which are used inside the project but the idea is simple: go to the database and check the existence of the affiliate. If it doesn't exist, terminate the request and return back the "404 Not Found" response. If it exists, continue executing by calling the base.SendAsync method which will invoke the next message handler inside the chain. Which message handler is the next here? Good question, you dear reader! It's going to be the &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.http.dispatcher.httpcontrollerdispatcher(v=vs.108).aspx"&gt;HttpControllerDispatcher&lt;/a&gt; which basically puts us inside the controller pipeline. To attach this handler to a route, we need to create a pipeline first to include the controller pipeline by chaining AffiliateShipmentsDispatcher and HttpControllerDispatcher together. The following code snippet shows the AffiliateShipmentsHttpRoute registration.&lt;/p&gt;
&lt;div class="code-wrapper border-shadow-1"&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;&lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;class&lt;/span&gt; RouteConfig {

    &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;static&lt;/span&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; RegisterRoutes(HttpConfiguration config) {

        &lt;span style="color: blue;"&gt;var&lt;/span&gt; routes = config.Routes;

        &lt;span style="color: green;"&gt;// Pipelines&lt;/span&gt;
        HttpMessageHandler affiliateShipmentsPipeline =
            HttpClientFactory.CreatePipeline(
                &lt;span style="color: blue;"&gt;new&lt;/span&gt; HttpControllerDispatcher(config),
                &lt;span style="color: blue;"&gt;new&lt;/span&gt;[] { &lt;span style="color: blue;"&gt;new&lt;/span&gt; AffiliateShipmentsDispatcher() });

        &lt;span style="color: green;"&gt;// Routes&lt;/span&gt;
        routes.MapHttpRoute(
            &lt;span style="color: #a31515;"&gt;"AffiliateShipmentsHttpRoute"&lt;/span&gt;,
            &lt;span style="color: #a31515;"&gt;"api/affiliates/{key}/shipments/{shipmentKey}"&lt;/span&gt;,
            defaults: &lt;span style="color: blue;"&gt;new&lt;/span&gt; { controller = &lt;span style="color: #a31515;"&gt;"AffiliateShipments"&lt;/span&gt;, shipmentKey = RouteParameter.Optional },
            constraints: &lt;span style="color: blue;"&gt;null&lt;/span&gt;,
            handler: affiliateShipmentsPipeline);

        routes.MapHttpRoute(
            &lt;span style="color: #a31515;"&gt;"DefaultHttpRoute"&lt;/span&gt;,
            &lt;span style="color: #a31515;"&gt;"api/{controller}/{key}"&lt;/span&gt;,
            defaults: &lt;span style="color: blue;"&gt;new&lt;/span&gt; { key = RouteParameter.Optional },
            constraints: &lt;span style="color: blue;"&gt;null&lt;/span&gt;);
    }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h3&gt;Authorization Concerns&lt;/h3&gt;
&lt;p&gt;If you have some type of authentication in place, you would want to make sure (in our scenario here) that the authenticated user and the requested affiliate resource is related. For example, assume that &lt;strong&gt;Affiliate1&lt;/strong&gt; is authenticated under the &lt;strong&gt;Affiliate role&lt;/strong&gt; and you have the &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.http.authorizeattribute(v=vs.108).aspx"&gt;AuthorizeAttribute&lt;/a&gt; registered to check the "Affiliate" role authorization. In this case, you will fail miserably because this means that Affiliate1 can get to the following resource: /api/affiliates/101/shipments which belongs to Affiliate2. We can eliminate this problem with a custom AuthorizeAttribute which is similar to below one:&lt;/p&gt;
&lt;div class="code-wrapper border-shadow-1"&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;[AttributeUsage(AttributeTargets.Class, AllowMultiple = &lt;span style="color: blue;"&gt;false&lt;/span&gt;)]
&lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;class&lt;/span&gt; AffiliateShipmentsAuthorizeAttribute : AuthorizeAttribute {

    &lt;span style="color: blue;"&gt;public&lt;/span&gt; AffiliateShipmentsAuthorizeAttribute() {

        &lt;span style="color: blue;"&gt;base&lt;/span&gt;.Roles = &lt;span style="color: #a31515;"&gt;"Affiliate"&lt;/span&gt;;
    }

    &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;override&lt;/span&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; OnAuthorization(HttpActionContext actionContext) {
        
        &lt;span style="color: blue;"&gt;base&lt;/span&gt;.OnAuthorization(actionContext);

        &lt;span style="color: green;"&gt;// If not authorized at all, don't bother checking for the &lt;/span&gt;
        &lt;span style="color: green;"&gt;// user - affiliate relation&lt;/span&gt;
        &lt;span style="color: blue;"&gt;if&lt;/span&gt; (actionContext.Response == &lt;span style="color: blue;"&gt;null&lt;/span&gt;) { 

            &lt;span style="color: green;"&gt;// We are here sure that the request has been authorized and &lt;/span&gt;
            &lt;span style="color: green;"&gt;// the user is in the Affiliate role. We also don't need &lt;/span&gt;
            &lt;span style="color: green;"&gt;// to check the existence of the affiliate as it has &lt;/span&gt;
            &lt;span style="color: green;"&gt;// been also already done by AffiliateShipmentsDispatcher.&lt;/span&gt;

            HttpRequestMessage request = actionContext.Request;
            Guid affiliateKey = GetAffiliateKey(request.GetRouteData());
            IPrincipal principal = Thread.CurrentPrincipal;
            IShipmentService shipmentService = request.GetShipmentService();
            &lt;span style="color: blue;"&gt;bool&lt;/span&gt; isAffiliateRelatedToUser =
                shipmentService.IsAffiliateRelatedToUser(
                    affiliateKey, principal.Identity.Name);

            &lt;span style="color: blue;"&gt;if&lt;/span&gt; (!isAffiliateRelatedToUser) {

                &lt;span style="color: green;"&gt;// Set Unauthorized response as the user and &lt;/span&gt;
                &lt;span style="color: green;"&gt;// affiliate isn't related to each other. You might&lt;/span&gt;
                &lt;span style="color: green;"&gt;// want to return "404 NotFound" response here if you don't&lt;/span&gt;
                &lt;span style="color: green;"&gt;// want to expose the existence of the affiliate.&lt;/span&gt;
                actionContext.Response = 
                    request.CreateResponse(HttpStatusCode.Unauthorized);
            }
        }
    }

    &lt;span style="color: blue;"&gt;private&lt;/span&gt; &lt;span style="color: blue;"&gt;static&lt;/span&gt; Guid GetAffiliateKey(IHttpRouteData routeData) {

        &lt;span style="color: blue;"&gt;var&lt;/span&gt; affiliateKey = routeData.Values[&lt;span style="color: #a31515;"&gt;"key"&lt;/span&gt;].ToString();
        &lt;span style="color: blue;"&gt;return&lt;/span&gt; Guid.ParseExact(affiliateKey, &lt;span style="color: #a31515;"&gt;"D"&lt;/span&gt;);
    }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This will be registered at the controller level for the AffiliateShipmentsController.&lt;/p&gt;
&lt;h3&gt;Ownership Concerns&lt;/h3&gt;
&lt;p&gt;Consider this URI for an HTTP GET request: /api/affiliates/100/shipments/102. This URI should get us the correct data. However, what would happen for the this URI: /api/affiliates/100/shipments/103? This should get you a "404 Not Found" HTTP response because the &lt;strong&gt;affiliate&lt;/strong&gt; whose Id is &lt;strong&gt;100&lt;/strong&gt; doesn't own the &lt;strong&gt;shipment&lt;/strong&gt; whose id is &lt;strong&gt;103&lt;/strong&gt;. Inside the PingYourPackage project, I ensured the ownership of the resource with the following authorization filter which will be applied to proper action methods.&lt;/p&gt;
&lt;div class="code-wrapper border-shadow-1"&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;[AttributeUsage(AttributeTargets.Method, AllowMultiple = &lt;span style="color: blue;"&gt;false&lt;/span&gt;)]
&lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;class&lt;/span&gt; EnsureShipmentOwnershipAttribute 
    : Attribute, IAuthorizationFilter {

    &lt;span style="color: blue;"&gt;private&lt;/span&gt; &lt;span style="color: blue;"&gt;const&lt;/span&gt; &lt;span style="color: blue;"&gt;string&lt;/span&gt; ShipmentDictionaryKey = 
        &lt;span style="color: #a31515;"&gt;"__AffiliateShipmentsController_Shipment"&lt;/span&gt;;
        
    &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;bool&lt;/span&gt; AllowMultiple { &lt;span style="color: blue;"&gt;get&lt;/span&gt; { &lt;span style="color: blue;"&gt;return&lt;/span&gt; &lt;span style="color: blue;"&gt;false&lt;/span&gt;; } }

    &lt;span style="color: blue;"&gt;public&lt;/span&gt; Task&amp;lt;HttpResponseMessage&amp;gt; ExecuteAuthorizationFilterAsync(
        HttpActionContext actionContext,
        CancellationToken cancellationToken,
        Func&amp;lt;Task&amp;lt;HttpResponseMessage&amp;gt;&amp;gt; continuation) {

        &lt;span style="color: green;"&gt;// We are here sure that the user is authanticated and request &lt;/span&gt;
        &lt;span style="color: green;"&gt;// can be kept executing because the AuthorizeAttribute has &lt;/span&gt;
        &lt;span style="color: green;"&gt;// been invoked before this filter's OnActionExecuting method.&lt;/span&gt;
        &lt;span style="color: green;"&gt;// Also, we are sure that the affiliate is associated with&lt;/span&gt;
        &lt;span style="color: green;"&gt;// the currently authanticated user as the previous action filter &lt;/span&gt;
        &lt;span style="color: green;"&gt;// has checked against this.&lt;/span&gt;
        IHttpRouteData routeData = actionContext.Request.GetRouteData();
        Uri requestUri = actionContext.Request.RequestUri;

        Guid affiliateKey = GetAffiliateKey(routeData);
        Guid shipmentKey = GetShipmentKey(routeData, requestUri);

        &lt;span style="color: green;"&gt;// Check if the affiliate really owns the shipment&lt;/span&gt;
        &lt;span style="color: green;"&gt;// whose key came from the request. We don't need to check the &lt;/span&gt;
        &lt;span style="color: green;"&gt;// existence of the affiliate as this check has been already &lt;/span&gt;
        &lt;span style="color: green;"&gt;// performed by the AffiliateShipmentsDispatcher.&lt;/span&gt;
        IShipmentService shipmentService = 
            actionContext.Request.GetShipmentService();
        Shipment shipment = shipmentService.GetShipment(shipmentKey);

        &lt;span style="color: green;"&gt;// Check the shipment existance&lt;/span&gt;
        &lt;span style="color: blue;"&gt;if&lt;/span&gt; (shipment == &lt;span style="color: blue;"&gt;null&lt;/span&gt;) {

            &lt;span style="color: blue;"&gt;return&lt;/span&gt; Task.FromResult(
                &lt;span style="color: blue;"&gt;new&lt;/span&gt; HttpResponseMessage(HttpStatusCode.NotFound));
        }

        &lt;span style="color: green;"&gt;// Check the shipment ownership&lt;/span&gt;
        &lt;span style="color: blue;"&gt;if&lt;/span&gt; (shipment.AffiliateKey != affiliateKey) {

            &lt;span style="color: green;"&gt;// You might want to return "404 NotFound" response here &lt;/span&gt;
            &lt;span style="color: green;"&gt;// if you don't want to expose the existence of the shipment.&lt;/span&gt;
            &lt;span style="color: blue;"&gt;return&lt;/span&gt; Task.FromResult(
                &lt;span style="color: blue;"&gt;new&lt;/span&gt; HttpResponseMessage(HttpStatusCode.Unauthorized));
        }

        &lt;span style="color: green;"&gt;// Stick the shipment inside the Properties dictionary so &lt;/span&gt;
        &lt;span style="color: green;"&gt;// that we won't need to have another trip to database.&lt;/span&gt;
        &lt;span style="color: green;"&gt;// The ShipmentParameterBinding will bind the Shipment param&lt;/span&gt;
        &lt;span style="color: green;"&gt;// if needed.&lt;/span&gt;
        actionContext.Request
            .Properties[ShipmentDictionaryKey] = shipment;

        &lt;span style="color: green;"&gt;// The request is legit, continue executing.&lt;/span&gt;
        &lt;span style="color: blue;"&gt;return&lt;/span&gt; continuation();
    }

    &lt;span style="color: blue;"&gt;private&lt;/span&gt; &lt;span style="color: blue;"&gt;static&lt;/span&gt; Guid GetAffiliateKey(IHttpRouteData routeData) {

        &lt;span style="color: blue;"&gt;var&lt;/span&gt; affiliateKey = routeData.Values[&lt;span style="color: #a31515;"&gt;"key"&lt;/span&gt;].ToString();
        &lt;span style="color: blue;"&gt;return&lt;/span&gt; Guid.ParseExact(affiliateKey, &lt;span style="color: #a31515;"&gt;"D"&lt;/span&gt;);
    }

    &lt;span style="color: blue;"&gt;private&lt;/span&gt; &lt;span style="color: blue;"&gt;static&lt;/span&gt; Guid GetShipmentKey(
        IHttpRouteData routeData, Uri requestUri) {

        &lt;span style="color: green;"&gt;// We are sure at this point that the shipmentKey value has been&lt;/span&gt;
        &lt;span style="color: green;"&gt;// supplied (either through route or quesry string) because it &lt;/span&gt;
        &lt;span style="color: green;"&gt;// wouldn't be possible for the request to arrive here if it wasn't.&lt;/span&gt;
        &lt;span style="color: blue;"&gt;object&lt;/span&gt; shipmentKeyString;
        &lt;span style="color: blue;"&gt;if&lt;/span&gt; (routeData.Values.TryGetValue(&lt;span style="color: #a31515;"&gt;"shipmentKey"&lt;/span&gt;, &lt;span style="color: blue;"&gt;out&lt;/span&gt; shipmentKeyString)) {

            &lt;span style="color: blue;"&gt;return&lt;/span&gt; Guid.ParseExact(shipmentKeyString.ToString(), &lt;span style="color: #a31515;"&gt;"D"&lt;/span&gt;);
        }

        &lt;span style="color: green;"&gt;// It's now sure that query string has the shipmentKey value&lt;/span&gt;
        &lt;span style="color: blue;"&gt;var&lt;/span&gt; quesryString = requestUri.ParseQueryString();
        &lt;span style="color: blue;"&gt;return&lt;/span&gt; Guid.ParseExact(quesryString[&lt;span style="color: #a31515;"&gt;"shipmentKey"&lt;/span&gt;], &lt;span style="color: #a31515;"&gt;"D"&lt;/span&gt;);
    }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Now, this filter can be applied to proper action methods to allow the proper authorization. At the very end, the AffiliateShipmentsController class looks clean and readable:&lt;/p&gt;
&lt;div class="code-wrapper border-shadow-1"&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;[AffiliateShipmentsAuthorize]
&lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;class&lt;/span&gt; AffiliateShipmentsController : ApiController {

    &lt;span style="color: green;"&gt;// We are OK inside this controller in terms of &lt;/span&gt;
    &lt;span style="color: green;"&gt;// Affiliate existance and its relation with the current &lt;/span&gt;
    &lt;span style="color: green;"&gt;// authed user has been checked by the handler &lt;/span&gt;
    &lt;span style="color: green;"&gt;// and AffiliateShipmentsAuthorizeAttribute.&lt;/span&gt;

    &lt;span style="color: green;"&gt;// The action method which requests the shipment instance:&lt;/span&gt;
    &lt;span style="color: green;"&gt;// We can just get the shipment as the shipment &lt;/span&gt;
    &lt;span style="color: green;"&gt;// existance and its ownership by the affiliate has been &lt;/span&gt;
    &lt;span style="color: green;"&gt;// approved by the EnsureShipmentOwnershipAttribute.&lt;/span&gt;
    &lt;span style="color: green;"&gt;// The BindShipmentAttribute can bind the shipment from the&lt;/span&gt;
    &lt;span style="color: green;"&gt;// Properties dictionarty of the HttpRequestMessage instance&lt;/span&gt;
    &lt;span style="color: green;"&gt;// as it has been put there by the EnsureShipmentOwnershipAttribute.&lt;/span&gt;

    &lt;span style="color: blue;"&gt;private&lt;/span&gt; &lt;span style="color: blue;"&gt;const&lt;/span&gt; &lt;span style="color: blue;"&gt;string&lt;/span&gt; RouteName = &lt;span style="color: #a31515;"&gt;"AffiliateShipmentsHttpRoute"&lt;/span&gt;;
    &lt;span style="color: blue;"&gt;private&lt;/span&gt; &lt;span style="color: blue;"&gt;readonly&lt;/span&gt; IShipmentService _shipmentService;

    &lt;span style="color: blue;"&gt;public&lt;/span&gt; AffiliateShipmentsController(IShipmentService shipmentService) {

        _shipmentService = shipmentService;
    }

    &lt;span style="color: blue;"&gt;public&lt;/span&gt; PaginatedDto&amp;lt;ShipmentDto&amp;gt; GetShipments(
        Guid key, 
        PaginatedRequestCommand cmd) {

        &lt;span style="color: blue;"&gt;var&lt;/span&gt; shipments = _shipmentService
            .GetShipments(cmd.Page, cmd.Take, affiliateKey: key);

        &lt;span style="color: blue;"&gt;return&lt;/span&gt; shipments.ToPaginatedDto(
            shipments.Select(sh =&amp;gt; sh.ToShipmentDto()));
    }

    [EnsureShipmentOwnership]
    &lt;span style="color: blue;"&gt;public&lt;/span&gt; ShipmentDto GetShipment(
        Guid key, 
        Guid shipmentKey, 
        [BindShipment]Shipment shipment) {

        &lt;span style="color: blue;"&gt;return&lt;/span&gt; shipment.ToShipmentDto();
    }

    [EmptyParameterFilter(&lt;span style="color: #a31515;"&gt;"requestModel"&lt;/span&gt;)]
    &lt;span style="color: blue;"&gt;public&lt;/span&gt; HttpResponseMessage PostShipment(
        Guid key, 
        ShipmentByAffiliateRequestModel requestModel) {

        &lt;span style="color: blue;"&gt;var&lt;/span&gt; createdShipmentResult =
            _shipmentService.AddShipment(requestModel.ToShipment(key));

        &lt;span style="color: blue;"&gt;if&lt;/span&gt; (!createdShipmentResult.IsSuccess) {

            &lt;span style="color: blue;"&gt;return&lt;/span&gt; &lt;span style="color: blue;"&gt;new&lt;/span&gt; HttpResponseMessage(HttpStatusCode.Conflict);
        }

        &lt;span style="color: blue;"&gt;var&lt;/span&gt; response = Request.CreateResponse(HttpStatusCode.Created,
            createdShipmentResult.Entity.ToShipmentDto());

        response.Headers.Location = &lt;span style="color: blue;"&gt;new&lt;/span&gt; Uri(
            Url.Link(RouteName, &lt;span style="color: blue;"&gt;new&lt;/span&gt; { 
                key = createdShipmentResult.Entity.AffiliateKey,
                shipmentKey = createdShipmentResult.Entity.Key
            })
        );

        &lt;span style="color: blue;"&gt;return&lt;/span&gt; response;
    }

    [EnsureShipmentOwnership]
    [EmptyParameterFilter(&lt;span style="color: #a31515;"&gt;"requestModel"&lt;/span&gt;)]
    &lt;span style="color: blue;"&gt;public&lt;/span&gt; ShipmentDto PutShipment(
        Guid key, 
        Guid shipmentKey,
        ShipmentByAffiliateUpdateRequestModel requestModel,
        [BindShipment]Shipment shipment) {

        &lt;span style="color: blue;"&gt;var&lt;/span&gt; updatedShipment = _shipmentService.UpdateShipment(
            requestModel.ToShipment(shipment));

        &lt;span style="color: blue;"&gt;return&lt;/span&gt; updatedShipment.ToShipmentDto();
    }

    [EnsureShipmentOwnership]
    &lt;span style="color: blue;"&gt;public&lt;/span&gt; HttpResponseMessage DeleteShipment(
        Guid key, 
        Guid shipmentKey,
        [BindShipment]Shipment shipment) {

        &lt;span style="color: blue;"&gt;var&lt;/span&gt; operationResult = _shipmentService.RemoveShipment(shipment);

        &lt;span style="color: blue;"&gt;if&lt;/span&gt; (!operationResult.IsSuccess) {

            &lt;span style="color: blue;"&gt;return&lt;/span&gt; &lt;span style="color: blue;"&gt;new&lt;/span&gt; HttpResponseMessage(HttpStatusCode.Conflict);
        }

        &lt;span style="color: blue;"&gt;return&lt;/span&gt; &lt;span style="color: blue;"&gt;new&lt;/span&gt; HttpResponseMessage(HttpStatusCode.NoContent);
    }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;As said, I'd love to know how you handle these types of situations in your applications.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TugberkUgurlu/~4/GJ3r2AcXI_E" height="1" width="1"/&gt;</description><pubDate>Mon, 04 Feb 2013 10:11:00 Z</pubDate><a10:updated>2013-02-04T10:11:00Z</a10:updated><a10:content type="text">&lt;p&gt;I came across a question on &lt;a href="http://stackoverflow.com"&gt;Stackoverflow&lt;/a&gt; today about the hierarchical resource structure in &lt;a href="http://www.asp.net/web-api"&gt;ASP.NET Web API&lt;/a&gt;: &lt;a title="http://stackoverflow.com/questions/14674255" href="http://stackoverflow.com/questions/14674255"&gt;http://stackoverflow.com/questions/14674255&lt;/a&gt;. The question is basically about the following issue:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;I have the following schema that I'd like to implement in ASP.NET Web API. What is the proper approach?&lt;/p&gt;
&lt;p&gt;http://mydomain/api/students&lt;br /&gt;http://mydomain/api/students/s123&lt;br /&gt;http://mydomain/api/students/s123/classes&lt;br /&gt;http://mydomain/api/students/s123/classes/c456&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;With this nice hierarchical approach, you have more concerns that routing here in terms of ASP.NET Web API. There is a good sample application which adopts the hierarchical resource structure: &lt;a href="https://github.com/tugberkugurlu/PingYourPackage"&gt;PingYourPackage&lt;/a&gt;. I definitely suggest you to check it out.&lt;/p&gt;
&lt;p&gt;Let me explain the concerns here in details by setting up a sample scenario. This may not be the desired approach for these types of situations but lays out the concerns very well and if you have a better way to eliminate these concerns, I'd be more that happy to hear those.&lt;/p&gt;
&lt;p&gt;Let's say you have the below two affiliates inside your database for a shipment company:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Affiliate1 (Id: 100) &lt;/li&gt;
&lt;li&gt;Affiliate2 (Id: 101)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;And then assume that these affiliates have some shipments attached to them:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Affiliate1 (Key: 100)   
&lt;ul&gt;
&lt;li&gt;Shipment1 (Key: 100) &lt;/li&gt;
&lt;li&gt;Shipment2 (Key: 102) &lt;/li&gt;
&lt;li&gt;Shipment4 (Key: 104)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Affiliate2 (Key: 101)   
&lt;ul&gt;
&lt;li&gt;Shipment3 (Key: 103) &lt;/li&gt;
&lt;li&gt;Shipment5 (Key: 105)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Finally, we want to have the following resource structure:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;GET api/affiliates/{key}/shipments &lt;/li&gt;
&lt;li&gt;GET api/affiliates/{key}/shipments/{shipmentKey} &lt;/li&gt;
&lt;li&gt;POST api/affiliates/{key}/shipments &lt;/li&gt;
&lt;li&gt;PUT api/affiliates/{key}/shipments/{shipmentKey} &lt;/li&gt;
&lt;li&gt;DELETE api/affiliates/{key}/shipments/{shipmentKey}&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In view of ASP.NET Web API, we have three obvious concerns here: routing, authorization and ownership. Let's go through this one by one.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The below code snippets have been taken from the &lt;a href="https://github.com/tugberkugurlu/PingYourPackage"&gt;PingYourPackage&lt;/a&gt; source code. They won't probably work if you copy and paste them but you will get the idea.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;Routing Concerns&lt;/h3&gt;
&lt;p&gt;Assume that we are sending a GET request against /api/affiliates/105/shipments/102 (considering our above scenario). Notice that the affiliate key is 105 here which doesn't exist. So, we would want to terminate the request here ASAP. We can achieve this with a per-route message handler as early as possible. The following AffiliateShipmentsDispatcher is responsible for checking the affiliate existence and acting on the result.&lt;/p&gt;
&lt;div class="code-wrapper border-shadow-1"&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;&lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;class&lt;/span&gt; AffiliateShipmentsDispatcher : DelegatingHandler {

  &lt;span style="color: blue;"&gt;protected&lt;/span&gt; &lt;span style="color: blue;"&gt;override&lt;/span&gt; Task&amp;lt;HttpResponseMessage&amp;gt; SendAsync(
      HttpRequestMessage request, 
      CancellationToken cancellationToken) {

      &lt;span style="color: green;"&gt;// We know at this point that the {key} route variable has &lt;/span&gt;
      &lt;span style="color: green;"&gt;// been supplied. Otherwise, we wouldn't be here. So, just get it.&lt;/span&gt;
      IHttpRouteData routeData = request.GetRouteData();
      Guid affiliateKey = Guid.ParseExact(routeData.Values[&lt;span style="color: #a31515;"&gt;"key"&lt;/span&gt;].ToString(), &lt;span style="color: #a31515;"&gt;"D"&lt;/span&gt;);

      IShipmentService shipmentService = request.GetShipmentService();
      &lt;span style="color: blue;"&gt;if&lt;/span&gt; (shipmentService.GetAffiliate(affiliateKey) == &lt;span style="color: blue;"&gt;null&lt;/span&gt;) {

          &lt;span style="color: blue;"&gt;return&lt;/span&gt; Task.FromResult(
              request.CreateResponse(HttpStatusCode.NotFound));
      }

      &lt;span style="color: blue;"&gt;return&lt;/span&gt; &lt;span style="color: blue;"&gt;base&lt;/span&gt;.SendAsync(request, cancellationToken);
  }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;I am here using a few internal extension methods which are used inside the project but the idea is simple: go to the database and check the existence of the affiliate. If it doesn't exist, terminate the request and return back the "404 Not Found" response. If it exists, continue executing by calling the base.SendAsync method which will invoke the next message handler inside the chain. Which message handler is the next here? Good question, you dear reader! It's going to be the &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.http.dispatcher.httpcontrollerdispatcher(v=vs.108).aspx"&gt;HttpControllerDispatcher&lt;/a&gt; which basically puts us inside the controller pipeline. To attach this handler to a route, we need to create a pipeline first to include the controller pipeline by chaining AffiliateShipmentsDispatcher and HttpControllerDispatcher together. The following code snippet shows the AffiliateShipmentsHttpRoute registration.&lt;/p&gt;
&lt;div class="code-wrapper border-shadow-1"&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;&lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;class&lt;/span&gt; RouteConfig {

    &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;static&lt;/span&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; RegisterRoutes(HttpConfiguration config) {

        &lt;span style="color: blue;"&gt;var&lt;/span&gt; routes = config.Routes;

        &lt;span style="color: green;"&gt;// Pipelines&lt;/span&gt;
        HttpMessageHandler affiliateShipmentsPipeline =
            HttpClientFactory.CreatePipeline(
                &lt;span style="color: blue;"&gt;new&lt;/span&gt; HttpControllerDispatcher(config),
                &lt;span style="color: blue;"&gt;new&lt;/span&gt;[] { &lt;span style="color: blue;"&gt;new&lt;/span&gt; AffiliateShipmentsDispatcher() });

        &lt;span style="color: green;"&gt;// Routes&lt;/span&gt;
        routes.MapHttpRoute(
            &lt;span style="color: #a31515;"&gt;"AffiliateShipmentsHttpRoute"&lt;/span&gt;,
            &lt;span style="color: #a31515;"&gt;"api/affiliates/{key}/shipments/{shipmentKey}"&lt;/span&gt;,
            defaults: &lt;span style="color: blue;"&gt;new&lt;/span&gt; { controller = &lt;span style="color: #a31515;"&gt;"AffiliateShipments"&lt;/span&gt;, shipmentKey = RouteParameter.Optional },
            constraints: &lt;span style="color: blue;"&gt;null&lt;/span&gt;,
            handler: affiliateShipmentsPipeline);

        routes.MapHttpRoute(
            &lt;span style="color: #a31515;"&gt;"DefaultHttpRoute"&lt;/span&gt;,
            &lt;span style="color: #a31515;"&gt;"api/{controller}/{key}"&lt;/span&gt;,
            defaults: &lt;span style="color: blue;"&gt;new&lt;/span&gt; { key = RouteParameter.Optional },
            constraints: &lt;span style="color: blue;"&gt;null&lt;/span&gt;);
    }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h3&gt;Authorization Concerns&lt;/h3&gt;
&lt;p&gt;If you have some type of authentication in place, you would want to make sure (in our scenario here) that the authenticated user and the requested affiliate resource is related. For example, assume that &lt;strong&gt;Affiliate1&lt;/strong&gt; is authenticated under the &lt;strong&gt;Affiliate role&lt;/strong&gt; and you have the &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.http.authorizeattribute(v=vs.108).aspx"&gt;AuthorizeAttribute&lt;/a&gt; registered to check the "Affiliate" role authorization. In this case, you will fail miserably because this means that Affiliate1 can get to the following resource: /api/affiliates/101/shipments which belongs to Affiliate2. We can eliminate this problem with a custom AuthorizeAttribute which is similar to below one:&lt;/p&gt;
&lt;div class="code-wrapper border-shadow-1"&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;[AttributeUsage(AttributeTargets.Class, AllowMultiple = &lt;span style="color: blue;"&gt;false&lt;/span&gt;)]
&lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;class&lt;/span&gt; AffiliateShipmentsAuthorizeAttribute : AuthorizeAttribute {

    &lt;span style="color: blue;"&gt;public&lt;/span&gt; AffiliateShipmentsAuthorizeAttribute() {

        &lt;span style="color: blue;"&gt;base&lt;/span&gt;.Roles = &lt;span style="color: #a31515;"&gt;"Affiliate"&lt;/span&gt;;
    }

    &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;override&lt;/span&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; OnAuthorization(HttpActionContext actionContext) {
        
        &lt;span style="color: blue;"&gt;base&lt;/span&gt;.OnAuthorization(actionContext);

        &lt;span style="color: green;"&gt;// If not authorized at all, don't bother checking for the &lt;/span&gt;
        &lt;span style="color: green;"&gt;// user - affiliate relation&lt;/span&gt;
        &lt;span style="color: blue;"&gt;if&lt;/span&gt; (actionContext.Response == &lt;span style="color: blue;"&gt;null&lt;/span&gt;) { 

            &lt;span style="color: green;"&gt;// We are here sure that the request has been authorized and &lt;/span&gt;
            &lt;span style="color: green;"&gt;// the user is in the Affiliate role. We also don't need &lt;/span&gt;
            &lt;span style="color: green;"&gt;// to check the existence of the affiliate as it has &lt;/span&gt;
            &lt;span style="color: green;"&gt;// been also already done by AffiliateShipmentsDispatcher.&lt;/span&gt;

            HttpRequestMessage request = actionContext.Request;
            Guid affiliateKey = GetAffiliateKey(request.GetRouteData());
            IPrincipal principal = Thread.CurrentPrincipal;
            IShipmentService shipmentService = request.GetShipmentService();
            &lt;span style="color: blue;"&gt;bool&lt;/span&gt; isAffiliateRelatedToUser =
                shipmentService.IsAffiliateRelatedToUser(
                    affiliateKey, principal.Identity.Name);

            &lt;span style="color: blue;"&gt;if&lt;/span&gt; (!isAffiliateRelatedToUser) {

                &lt;span style="color: green;"&gt;// Set Unauthorized response as the user and &lt;/span&gt;
                &lt;span style="color: green;"&gt;// affiliate isn't related to each other. You might&lt;/span&gt;
                &lt;span style="color: green;"&gt;// want to return "404 NotFound" response here if you don't&lt;/span&gt;
                &lt;span style="color: green;"&gt;// want to expose the existence of the affiliate.&lt;/span&gt;
                actionContext.Response = 
                    request.CreateResponse(HttpStatusCode.Unauthorized);
            }
        }
    }

    &lt;span style="color: blue;"&gt;private&lt;/span&gt; &lt;span style="color: blue;"&gt;static&lt;/span&gt; Guid GetAffiliateKey(IHttpRouteData routeData) {

        &lt;span style="color: blue;"&gt;var&lt;/span&gt; affiliateKey = routeData.Values[&lt;span style="color: #a31515;"&gt;"key"&lt;/span&gt;].ToString();
        &lt;span style="color: blue;"&gt;return&lt;/span&gt; Guid.ParseExact(affiliateKey, &lt;span style="color: #a31515;"&gt;"D"&lt;/span&gt;);
    }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This will be registered at the controller level for the AffiliateShipmentsController.&lt;/p&gt;
&lt;h3&gt;Ownership Concerns&lt;/h3&gt;
&lt;p&gt;Consider this URI for an HTTP GET request: /api/affiliates/100/shipments/102. This URI should get us the correct data. However, what would happen for the this URI: /api/affiliates/100/shipments/103? This should get you a "404 Not Found" HTTP response because the &lt;strong&gt;affiliate&lt;/strong&gt; whose Id is &lt;strong&gt;100&lt;/strong&gt; doesn't own the &lt;strong&gt;shipment&lt;/strong&gt; whose id is &lt;strong&gt;103&lt;/strong&gt;. Inside the PingYourPackage project, I ensured the ownership of the resource with the following authorization filter which will be applied to proper action methods.&lt;/p&gt;
&lt;div class="code-wrapper border-shadow-1"&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;[AttributeUsage(AttributeTargets.Method, AllowMultiple = &lt;span style="color: blue;"&gt;false&lt;/span&gt;)]
&lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;class&lt;/span&gt; EnsureShipmentOwnershipAttribute 
    : Attribute, IAuthorizationFilter {

    &lt;span style="color: blue;"&gt;private&lt;/span&gt; &lt;span style="color: blue;"&gt;const&lt;/span&gt; &lt;span style="color: blue;"&gt;string&lt;/span&gt; ShipmentDictionaryKey = 
        &lt;span style="color: #a31515;"&gt;"__AffiliateShipmentsController_Shipment"&lt;/span&gt;;
        
    &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;bool&lt;/span&gt; AllowMultiple { &lt;span style="color: blue;"&gt;get&lt;/span&gt; { &lt;span style="color: blue;"&gt;return&lt;/span&gt; &lt;span style="color: blue;"&gt;false&lt;/span&gt;; } }

    &lt;span style="color: blue;"&gt;public&lt;/span&gt; Task&amp;lt;HttpResponseMessage&amp;gt; ExecuteAuthorizationFilterAsync(
        HttpActionContext actionContext,
        CancellationToken cancellationToken,
        Func&amp;lt;Task&amp;lt;HttpResponseMessage&amp;gt;&amp;gt; continuation) {

        &lt;span style="color: green;"&gt;// We are here sure that the user is authanticated and request &lt;/span&gt;
        &lt;span style="color: green;"&gt;// can be kept executing because the AuthorizeAttribute has &lt;/span&gt;
        &lt;span style="color: green;"&gt;// been invoked before this filter's OnActionExecuting method.&lt;/span&gt;
        &lt;span style="color: green;"&gt;// Also, we are sure that the affiliate is associated with&lt;/span&gt;
        &lt;span style="color: green;"&gt;// the currently authanticated user as the previous action filter &lt;/span&gt;
        &lt;span style="color: green;"&gt;// has checked against this.&lt;/span&gt;
        IHttpRouteData routeData = actionContext.Request.GetRouteData();
        Uri requestUri = actionContext.Request.RequestUri;

        Guid affiliateKey = GetAffiliateKey(routeData);
        Guid shipmentKey = GetShipmentKey(routeData, requestUri);

        &lt;span style="color: green;"&gt;// Check if the affiliate really owns the shipment&lt;/span&gt;
        &lt;span style="color: green;"&gt;// whose key came from the request. We don't need to check the &lt;/span&gt;
        &lt;span style="color: green;"&gt;// existence of the affiliate as this check has been already &lt;/span&gt;
        &lt;span style="color: green;"&gt;// performed by the AffiliateShipmentsDispatcher.&lt;/span&gt;
        IShipmentService shipmentService = 
            actionContext.Request.GetShipmentService();
        Shipment shipment = shipmentService.GetShipment(shipmentKey);

        &lt;span style="color: green;"&gt;// Check the shipment existance&lt;/span&gt;
        &lt;span style="color: blue;"&gt;if&lt;/span&gt; (shipment == &lt;span style="color: blue;"&gt;null&lt;/span&gt;) {

            &lt;span style="color: blue;"&gt;return&lt;/span&gt; Task.FromResult(
                &lt;span style="color: blue;"&gt;new&lt;/span&gt; HttpResponseMessage(HttpStatusCode.NotFound));
        }

        &lt;span style="color: green;"&gt;// Check the shipment ownership&lt;/span&gt;
        &lt;span style="color: blue;"&gt;if&lt;/span&gt; (shipment.AffiliateKey != affiliateKey) {

            &lt;span style="color: green;"&gt;// You might want to return "404 NotFound" response here &lt;/span&gt;
            &lt;span style="color: green;"&gt;// if you don't want to expose the existence of the shipment.&lt;/span&gt;
            &lt;span style="color: blue;"&gt;return&lt;/span&gt; Task.FromResult(
                &lt;span style="color: blue;"&gt;new&lt;/span&gt; HttpResponseMessage(HttpStatusCode.Unauthorized));
        }

        &lt;span style="color: green;"&gt;// Stick the shipment inside the Properties dictionary so &lt;/span&gt;
        &lt;span style="color: green;"&gt;// that we won't need to have another trip to database.&lt;/span&gt;
        &lt;span style="color: green;"&gt;// The ShipmentParameterBinding will bind the Shipment param&lt;/span&gt;
        &lt;span style="color: green;"&gt;// if needed.&lt;/span&gt;
        actionContext.Request
            .Properties[ShipmentDictionaryKey] = shipment;

        &lt;span style="color: green;"&gt;// The request is legit, continue executing.&lt;/span&gt;
        &lt;span style="color: blue;"&gt;return&lt;/span&gt; continuation();
    }

    &lt;span style="color: blue;"&gt;private&lt;/span&gt; &lt;span style="color: blue;"&gt;static&lt;/span&gt; Guid GetAffiliateKey(IHttpRouteData routeData) {

        &lt;span style="color: blue;"&gt;var&lt;/span&gt; affiliateKey = routeData.Values[&lt;span style="color: #a31515;"&gt;"key"&lt;/span&gt;].ToString();
        &lt;span style="color: blue;"&gt;return&lt;/span&gt; Guid.ParseExact(affiliateKey, &lt;span style="color: #a31515;"&gt;"D"&lt;/span&gt;);
    }

    &lt;span style="color: blue;"&gt;private&lt;/span&gt; &lt;span style="color: blue;"&gt;static&lt;/span&gt; Guid GetShipmentKey(
        IHttpRouteData routeData, Uri requestUri) {

        &lt;span style="color: green;"&gt;// We are sure at this point that the shipmentKey value has been&lt;/span&gt;
        &lt;span style="color: green;"&gt;// supplied (either through route or quesry string) because it &lt;/span&gt;
        &lt;span style="color: green;"&gt;// wouldn't be possible for the request to arrive here if it wasn't.&lt;/span&gt;
        &lt;span style="color: blue;"&gt;object&lt;/span&gt; shipmentKeyString;
        &lt;span style="color: blue;"&gt;if&lt;/span&gt; (routeData.Values.TryGetValue(&lt;span style="color: #a31515;"&gt;"shipmentKey"&lt;/span&gt;, &lt;span style="color: blue;"&gt;out&lt;/span&gt; shipmentKeyString)) {

            &lt;span style="color: blue;"&gt;return&lt;/span&gt; Guid.ParseExact(shipmentKeyString.ToString(), &lt;span style="color: #a31515;"&gt;"D"&lt;/span&gt;);
        }

        &lt;span style="color: green;"&gt;// It's now sure that query string has the shipmentKey value&lt;/span&gt;
        &lt;span style="color: blue;"&gt;var&lt;/span&gt; quesryString = requestUri.ParseQueryString();
        &lt;span style="color: blue;"&gt;return&lt;/span&gt; Guid.ParseExact(quesryString[&lt;span style="color: #a31515;"&gt;"shipmentKey"&lt;/span&gt;], &lt;span style="color: #a31515;"&gt;"D"&lt;/span&gt;);
    }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Now, this filter can be applied to proper action methods to allow the proper authorization. At the very end, the AffiliateShipmentsController class looks clean and readable:&lt;/p&gt;
&lt;div class="code-wrapper border-shadow-1"&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;[AffiliateShipmentsAuthorize]
&lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;class&lt;/span&gt; AffiliateShipmentsController : ApiController {

    &lt;span style="color: green;"&gt;// We are OK inside this controller in terms of &lt;/span&gt;
    &lt;span style="color: green;"&gt;// Affiliate existance and its relation with the current &lt;/span&gt;
    &lt;span style="color: green;"&gt;// authed user has been checked by the handler &lt;/span&gt;
    &lt;span style="color: green;"&gt;// and AffiliateShipmentsAuthorizeAttribute.&lt;/span&gt;

    &lt;span style="color: green;"&gt;// The action method which requests the shipment instance:&lt;/span&gt;
    &lt;span style="color: green;"&gt;// We can just get the shipment as the shipment &lt;/span&gt;
    &lt;span style="color: green;"&gt;// existance and its ownership by the affiliate has been &lt;/span&gt;
    &lt;span style="color: green;"&gt;// approved by the EnsureShipmentOwnershipAttribute.&lt;/span&gt;
    &lt;span style="color: green;"&gt;// The BindShipmentAttribute can bind the shipment from the&lt;/span&gt;
    &lt;span style="color: green;"&gt;// Properties dictionarty of the HttpRequestMessage instance&lt;/span&gt;
    &lt;span style="color: green;"&gt;// as it has been put there by the EnsureShipmentOwnershipAttribute.&lt;/span&gt;

    &lt;span style="color: blue;"&gt;private&lt;/span&gt; &lt;span style="color: blue;"&gt;const&lt;/span&gt; &lt;span style="color: blue;"&gt;string&lt;/span&gt; RouteName = &lt;span style="color: #a31515;"&gt;"AffiliateShipmentsHttpRoute"&lt;/span&gt;;
    &lt;span style="color: blue;"&gt;private&lt;/span&gt; &lt;span style="color: blue;"&gt;readonly&lt;/span&gt; IShipmentService _shipmentService;

    &lt;span style="color: blue;"&gt;public&lt;/span&gt; AffiliateShipmentsController(IShipmentService shipmentService) {

        _shipmentService = shipmentService;
    }

    &lt;span style="color: blue;"&gt;public&lt;/span&gt; PaginatedDto&amp;lt;ShipmentDto&amp;gt; GetShipments(
        Guid key, 
        PaginatedRequestCommand cmd) {

        &lt;span style="color: blue;"&gt;var&lt;/span&gt; shipments = _shipmentService
            .GetShipments(cmd.Page, cmd.Take, affiliateKey: key);

        &lt;span style="color: blue;"&gt;return&lt;/span&gt; shipments.ToPaginatedDto(
            shipments.Select(sh =&amp;gt; sh.ToShipmentDto()));
    }

    [EnsureShipmentOwnership]
    &lt;span style="color: blue;"&gt;public&lt;/span&gt; ShipmentDto GetShipment(
        Guid key, 
        Guid shipmentKey, 
        [BindShipment]Shipment shipment) {

        &lt;span style="color: blue;"&gt;return&lt;/span&gt; shipment.ToShipmentDto();
    }

    [EmptyParameterFilter(&lt;span style="color: #a31515;"&gt;"requestModel"&lt;/span&gt;)]
    &lt;span style="color: blue;"&gt;public&lt;/span&gt; HttpResponseMessage PostShipment(
        Guid key, 
        ShipmentByAffiliateRequestModel requestModel) {

        &lt;span style="color: blue;"&gt;var&lt;/span&gt; createdShipmentResult =
            _shipmentService.AddShipment(requestModel.ToShipment(key));

        &lt;span style="color: blue;"&gt;if&lt;/span&gt; (!createdShipmentResult.IsSuccess) {

            &lt;span style="color: blue;"&gt;return&lt;/span&gt; &lt;span style="color: blue;"&gt;new&lt;/span&gt; HttpResponseMessage(HttpStatusCode.Conflict);
        }

        &lt;span style="color: blue;"&gt;var&lt;/span&gt; response = Request.CreateResponse(HttpStatusCode.Created,
            createdShipmentResult.Entity.ToShipmentDto());

        response.Headers.Location = &lt;span style="color: blue;"&gt;new&lt;/span&gt; Uri(
            Url.Link(RouteName, &lt;span style="color: blue;"&gt;new&lt;/span&gt; { 
                key = createdShipmentResult.Entity.AffiliateKey,
                shipmentKey = createdShipmentResult.Entity.Key
            })
        );

        &lt;span style="color: blue;"&gt;return&lt;/span&gt; response;
    }

    [EnsureShipmentOwnership]
    [EmptyParameterFilter(&lt;span style="color: #a31515;"&gt;"requestModel"&lt;/span&gt;)]
    &lt;span style="color: blue;"&gt;public&lt;/span&gt; ShipmentDto PutShipment(
        Guid key, 
        Guid shipmentKey,
        ShipmentByAffiliateUpdateRequestModel requestModel,
        [BindShipment]Shipment shipment) {

        &lt;span style="color: blue;"&gt;var&lt;/span&gt; updatedShipment = _shipmentService.UpdateShipment(
            requestModel.ToShipment(shipment));

        &lt;span style="color: blue;"&gt;return&lt;/span&gt; updatedShipment.ToShipmentDto();
    }

    [EnsureShipmentOwnership]
    &lt;span style="color: blue;"&gt;public&lt;/span&gt; HttpResponseMessage DeleteShipment(
        Guid key, 
        Guid shipmentKey,
        [BindShipment]Shipment shipment) {

        &lt;span style="color: blue;"&gt;var&lt;/span&gt; operationResult = _shipmentService.RemoveShipment(shipment);

        &lt;span style="color: blue;"&gt;if&lt;/span&gt; (!operationResult.IsSuccess) {

            &lt;span style="color: blue;"&gt;return&lt;/span&gt; &lt;span style="color: blue;"&gt;new&lt;/span&gt; HttpResponseMessage(HttpStatusCode.Conflict);
        }

        &lt;span style="color: blue;"&gt;return&lt;/span&gt; &lt;span style="color: blue;"&gt;new&lt;/span&gt; HttpResponseMessage(HttpStatusCode.NoContent);
    }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;As said, I'd love to know how you handle these types of situations in your applications.&lt;/p&gt;</a10:content><feedburner:origLink>http://tugberkugurlu.com/137</feedburner:origLink></item><item><guid isPermaLink="false">http://tugberkugurlu.com/136</guid><link>http://feedproxy.google.com/~r/TugberkUgurlu/~3/D0gyZmNegDM/136</link><title>Installing hub Extension for Git (by defunkt) on Windows to Work With GitHub More Efficiently</title><description>&lt;p&gt;We are all in love with &lt;a href="http://git-scm.com/"&gt;Git&lt;/a&gt; but without &lt;a href="https://github.com"&gt;GitHub&lt;/a&gt;, we love Git less. On GitHub, we can maintain our projects very efficiently. Pull Request&amp;rdquo; and "Issues" features of GitHub are the key factors for that IMO. You can even send yourself a pull request from one branch to another and discuss that particular change with your team. As your discussion flows, your code can flow accordingly, too. This is just one of the many coolest features of GitHub.&lt;/p&gt;
&lt;p&gt;There is a cool Git extension for GitHub which is maintained by one of the founders of GitHub: &lt;a href="https://github.com/defunkt"&gt;Chris Wanstrath&lt;/a&gt;. This cool extension named &lt;a href="https://github.com/defunkt/hub"&gt;hub&lt;/a&gt; lets us work with GitHub more efficiently from the command line and perform GitHub specific operations easily like sending pull requests, forking repositories, etc. It&amp;rsquo;s fairly easy to install it on other platforms as far as I can see but it&amp;rsquo;s not that straight forward for Windows.&lt;/p&gt;
&lt;p&gt;You should first go and install &lt;a href="http://msysgit.github.com/"&gt;msysgit&lt;/a&gt; on Windows and I am assuming most of us using this on Windows for Git. Secondly, we should install Ruby on windows. You can install Ruby on windows through &lt;a href="http://rubyinstaller.org/"&gt;RubyInstaller&lt;/a&gt; easily.&lt;/p&gt;
&lt;p&gt;After installing ruby on our machine successfully, we should add the bin path of Ruby to our system PATH variable. In order to do this, press Windows Key + PAUSE BREAK to open up the Windows System window and click "Advanced system settings" link on the left hand side of the window.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Installing_14478/SNAGHTML25551807.png"&gt;&lt;img height="384" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Installing_14478/SNAGHTML25551807_thumb.png" alt="SNAGHTML25551807" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="SNAGHTML25551807" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;A new window should appear. From there, click "Environment Variables..." button to open up the Environment Variables window.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Installing_14478/image.png"&gt;&lt;img height="244" width="219" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Installing_14478/image_thumb.png" alt="image" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;From there, you should see "System variables" section. Find the Path variable and concatenate the proper ruby bin path to that semicolon-separated list.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Installing_14478/image_3.png"&gt;&lt;img height="114" width="244" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Installing_14478/image_thumb_3.png" alt="image" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" /&gt;&lt;/a&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Installing_14478/SNAGHTML255c49a4.png"&gt;&lt;img height="108" width="244" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Installing_14478/SNAGHTML255c49a4_thumb.png" alt="SNAGHTML255c49a4" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px 0px 0px 10px; display: inline; padding-right: 0px; border: 0px;" title="SNAGHTML255c49a4" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Last step is actually installing the hub. You should grab &lt;a href="http://defunkt.io/hub/standalone"&gt;the standalone file&lt;/a&gt; and then rename it to "hub". Then, put it under the Git\bin folder. The full path of my Git\bin folder on my 64x machine is "C:\Program Files (x86)\Git\bin".&lt;/p&gt;
&lt;p&gt;Now you should be able to run hub command from Git Bash:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Installing_14478/image_4.png"&gt;&lt;img height="349" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Installing_14478/image_thumb_4.png" alt="image" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Special GitHub commands you get through hub extension is nicely documented on &lt;a href="https://github.com/defunkt/hub#readme"&gt;the "Readme" file of the project&lt;/a&gt;. I think the coolest feature of hub is the pull-request feature. On GitHub, You can send pull requests to another repository through GitHub web site or GitHub API and hub extension uses GitHub API under the covers to send pull requests. You can even attach your pull request to an existing issue. For example, the following command sends a pull request to master branch of the tugberkugurlu&amp;rsquo;s repository from the branch that I am currently on and attaches this to an existing issue #1.&lt;/p&gt;
&lt;div class="code-wrapper border-shadow-1"&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;hub pull-request -i 1 -b tugberkugurlu:master&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Have fun &lt;img src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Installing_14478/wlEmoticon-winkingsmile.png" alt="Winking smile" style="border-style: none;" class="wlEmoticon wlEmoticon-winkingsmile" /&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TugberkUgurlu/~4/D0gyZmNegDM" height="1" width="1"/&gt;</description><pubDate>Sat, 19 Jan 2013 22:10:00 Z</pubDate><a10:updated>2013-01-19T22:10:00Z</a10:updated><a10:content type="text">&lt;p&gt;We are all in love with &lt;a href="http://git-scm.com/"&gt;Git&lt;/a&gt; but without &lt;a href="https://github.com"&gt;GitHub&lt;/a&gt;, we love Git less. On GitHub, we can maintain our projects very efficiently. Pull Request&amp;rdquo; and "Issues" features of GitHub are the key factors for that IMO. You can even send yourself a pull request from one branch to another and discuss that particular change with your team. As your discussion flows, your code can flow accordingly, too. This is just one of the many coolest features of GitHub.&lt;/p&gt;
&lt;p&gt;There is a cool Git extension for GitHub which is maintained by one of the founders of GitHub: &lt;a href="https://github.com/defunkt"&gt;Chris Wanstrath&lt;/a&gt;. This cool extension named &lt;a href="https://github.com/defunkt/hub"&gt;hub&lt;/a&gt; lets us work with GitHub more efficiently from the command line and perform GitHub specific operations easily like sending pull requests, forking repositories, etc. It&amp;rsquo;s fairly easy to install it on other platforms as far as I can see but it&amp;rsquo;s not that straight forward for Windows.&lt;/p&gt;
&lt;p&gt;You should first go and install &lt;a href="http://msysgit.github.com/"&gt;msysgit&lt;/a&gt; on Windows and I am assuming most of us using this on Windows for Git. Secondly, we should install Ruby on windows. You can install Ruby on windows through &lt;a href="http://rubyinstaller.org/"&gt;RubyInstaller&lt;/a&gt; easily.&lt;/p&gt;
&lt;p&gt;After installing ruby on our machine successfully, we should add the bin path of Ruby to our system PATH variable. In order to do this, press Windows Key + PAUSE BREAK to open up the Windows System window and click "Advanced system settings" link on the left hand side of the window.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Installing_14478/SNAGHTML25551807.png"&gt;&lt;img height="384" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Installing_14478/SNAGHTML25551807_thumb.png" alt="SNAGHTML25551807" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="SNAGHTML25551807" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;A new window should appear. From there, click "Environment Variables..." button to open up the Environment Variables window.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Installing_14478/image.png"&gt;&lt;img height="244" width="219" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Installing_14478/image_thumb.png" alt="image" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;From there, you should see "System variables" section. Find the Path variable and concatenate the proper ruby bin path to that semicolon-separated list.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Installing_14478/image_3.png"&gt;&lt;img height="114" width="244" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Installing_14478/image_thumb_3.png" alt="image" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" /&gt;&lt;/a&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Installing_14478/SNAGHTML255c49a4.png"&gt;&lt;img height="108" width="244" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Installing_14478/SNAGHTML255c49a4_thumb.png" alt="SNAGHTML255c49a4" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px 0px 0px 10px; display: inline; padding-right: 0px; border: 0px;" title="SNAGHTML255c49a4" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Last step is actually installing the hub. You should grab &lt;a href="http://defunkt.io/hub/standalone"&gt;the standalone file&lt;/a&gt; and then rename it to "hub". Then, put it under the Git\bin folder. The full path of my Git\bin folder on my 64x machine is "C:\Program Files (x86)\Git\bin".&lt;/p&gt;
&lt;p&gt;Now you should be able to run hub command from Git Bash:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Installing_14478/image_4.png"&gt;&lt;img height="349" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Installing_14478/image_thumb_4.png" alt="image" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Special GitHub commands you get through hub extension is nicely documented on &lt;a href="https://github.com/defunkt/hub#readme"&gt;the "Readme" file of the project&lt;/a&gt;. I think the coolest feature of hub is the pull-request feature. On GitHub, You can send pull requests to another repository through GitHub web site or GitHub API and hub extension uses GitHub API under the covers to send pull requests. You can even attach your pull request to an existing issue. For example, the following command sends a pull request to master branch of the tugberkugurlu&amp;rsquo;s repository from the branch that I am currently on and attaches this to an existing issue #1.&lt;/p&gt;
&lt;div class="code-wrapper border-shadow-1"&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;hub pull-request -i 1 -b tugberkugurlu:master&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Have fun &lt;img src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Installing_14478/wlEmoticon-winkingsmile.png" alt="Winking smile" style="border-style: none;" class="wlEmoticon wlEmoticon-winkingsmile" /&gt;&lt;/p&gt;</a10:content><feedburner:origLink>http://tugberkugurlu.com/136</feedburner:origLink></item><item><guid isPermaLink="false">http://tugberkugurlu.com/135</guid><link>http://feedproxy.google.com/~r/TugberkUgurlu/~3/Hvdx2dDQJXI/135</link><title>ASP.NET Web API Tracing and IDependencyScope Dispose Issue</title><description>&lt;p&gt;&lt;a href="http://www.asp.net/web-api"&gt;ASP.NET Web API&lt;/a&gt; has a very cool built-in tracing mechanism. The coolest part about this feature is that none of the tracing code is being run if you don&amp;rsquo;t enable it. The mechanism makes use of well-known &lt;a href="http://en.wikipedia.org/wiki/Facade_pattern"&gt;Facade Pattern&lt;/a&gt; and if you enable tracing by providing your custom &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.http.tracing.itracewriter(v=vs.108).aspx"&gt;ITraceWriter&lt;/a&gt; implementation and don&amp;rsquo;t replace the default &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.http.tracing.itracemanager(v=vs.108).aspx"&gt;ITraceManager&lt;/a&gt; implementation, several ASP.NET Web API components (Message Handlers, Controllers, Filters, Formatters, etc.) will be wrapped up inside their tracer implementations (these are internal classes inside System.Web.Http assembly). You can learn more about tracing from &lt;a href="http://www.asp.net/web-api/overview/testing-and-debugging/tracing-in-aspnet-web-api"&gt;Tracing in ASP.NET Web API&lt;/a&gt; article.&lt;/p&gt;
&lt;p&gt;ASP.NET Web API also has this concept of carrying disposable objects inside the request properties bag and two objects are added to this disposable list by the framework as shown below (in the same order):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.http.dependencies.idependencyscope(v=vs.108).aspx"&gt;IDependencyScope&lt;/a&gt; implementation for the request.&lt;/li&gt;
&lt;li&gt;The selected &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.http.controllers.ihttpcontroller(v=vs.108).aspx"&gt;IHttpController&lt;/a&gt; implementation for the request.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The &lt;a href="http://msdn.microsoft.com/en-us/library/system.net.http.httprequestmessageextensions.disposerequestresources(v=vs.108).aspx"&gt;DisposeRequestResources&lt;/a&gt; extension method for the &lt;a href="http://msdn.microsoft.com/en-us/library/system.net.http.httprequestmessage.aspx"&gt;HttpRequestMessage&lt;/a&gt; object is invoked by the hosting layer at the end of each request to dispose the registered disposable objects. The invoker is the internal ConvertResponse method of &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.http.webhost.httpcontrollerhandler.aspx"&gt;HttpControllerHandler&lt;/a&gt; in case of ASP.NET host. The implementation of the DisposeRequestResources extension method is exactly as shown below:&lt;/p&gt;
&lt;div class="code-wrapper border-shadow-1"&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;&lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;static&lt;/span&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; DisposeRequestResources(&lt;span style="color: blue;"&gt;this&lt;/span&gt; HttpRequestMessage request) {

    &lt;span style="color: blue;"&gt;if&lt;/span&gt; (request == &lt;span style="color: blue;"&gt;null&lt;/span&gt;) {
        &lt;span style="color: blue;"&gt;throw&lt;/span&gt; Error.ArgumentNull(&lt;span style="color: #a31515;"&gt;"request"&lt;/span&gt;);
    }

    List&amp;lt;IDisposable&amp;gt; resourcesToDispose;
    &lt;span style="color: blue;"&gt;if&lt;/span&gt; (request.Properties.TryGetValue(HttpPropertyKeys.DisposableRequestResourcesKey, &lt;span style="color: blue;"&gt;out&lt;/span&gt; resourcesToDispose)) {
        &lt;span style="color: blue;"&gt;foreach&lt;/span&gt; (IDisposable resource &lt;span style="color: blue;"&gt;in&lt;/span&gt; resourcesToDispose) {
            &lt;span style="color: blue;"&gt;try&lt;/span&gt; {
                resource.Dispose();
            }
            &lt;span style="color: blue;"&gt;catch&lt;/span&gt; {
                &lt;span style="color: green;"&gt;// ignore exceptions&lt;/span&gt;
            }
        }
        resourcesToDispose.Clear();
    }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;It iterates through the list and disposes the registered objects one by one. So far so good. However, there is one slightly problem here depending on your ITraceWriter implementation. I&amp;rsquo;m not sure if it&amp;rsquo;s fair to call this a bug, but to me, it really is a bug. Let me explain what it is.&lt;/p&gt;
&lt;p&gt;As we know, the IDependencyScope implementation and the selected IHttpController implementation for the request are added to the disposables list in order to be disposed at the end of the request. As we also know, if we enable tracing in ASP.NET Web API, several ASP.NET Web API components wrapped inside their tracer implementations. In case of controllers, this is HttpControllerTracer. Since the IHttpController is also disposable, the HttpControllerTracer overrides the Dispose method to write a begin/end trace record for the dispose action. However, the disposable objects are disposed in order and when the controller&amp;rsquo;s dispose method is called, the dependency scope is already too far gone and if your custom ITraceWriter implementation tries to use the dependency scope, which is bound to that request, you will get an exception there. This doesn&amp;rsquo;t effect your application that much as this exception is swollen by the underlying infrastructure but this is not good. I wrote a little application to demonstrate this (actually, I went a little far and used a few more things for this *little* application &lt;img src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/ASP.NET-Web-API-Tracing-and_F529/wlEmoticon-smile.png" alt="Smile" style="border-style: none;" class="wlEmoticon wlEmoticon-smile" /&gt;) and show how to workaround it for now. &lt;a href="https://github.com/tugberkugurlu/ASPNETWebAPISamples/tree/master/DependencyScopeTracingDisposeBug"&gt;The code for this project is available on GitHub&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I created a custom tracer and registered through the global &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.http.httpconfiguration(v=vs.108).aspx"&gt;HttpConfiguration&lt;/a&gt; instance. This tracer tries to reach the ILoggerService implementation through the dependency scope. The code for my ITraceWriter implementation is as shown below:&lt;/p&gt;
&lt;div class="code-wrapper border-shadow-1"&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;&lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;class&lt;/span&gt; WebApiTracer : ITraceWriter {

    &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; Trace(
        HttpRequestMessage request, 
        &lt;span style="color: blue;"&gt;string&lt;/span&gt; category, 
        TraceLevel level, 
        Action&amp;lt;TraceRecord&amp;gt; traceAction) {

        &lt;span style="color: blue;"&gt;if&lt;/span&gt; (level != TraceLevel.Off) {

            TraceRecord record = &lt;span style="color: blue;"&gt;new&lt;/span&gt; TraceRecord(request, category, level);
            traceAction(record);
            Log(record);
        }
    }

    &lt;span style="color: blue;"&gt;private&lt;/span&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; Log(TraceRecord traceRecord) {

        IDependencyScope dependencyScope = 
            traceRecord.Request.GetDependencyScope();
            
        ILoggerService loggerService = 
            dependencyScope.GetService(&lt;span style="color: blue;"&gt;typeof&lt;/span&gt;(ILoggerService)) &lt;span style="color: blue;"&gt;as&lt;/span&gt; ILoggerService;
            
        &lt;span style="color: green;"&gt;// Log the trace data here using loggerService&lt;/span&gt;
        
        &lt;span style="color: green;"&gt;// Lines omitted for brevity&lt;/span&gt;
    }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;When we run this application in debug mode and send a request against a valid resource which will eventually go inside the controller pipeline (for this application /api/cars), we will see an exception as below:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/ASP.NET-Web-API-Tracing-and_F529/1-12-2013-4-41-30-PM.png"&gt;&lt;img height="229" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/ASP.NET-Web-API-Tracing-and_F529/1-12-2013-4-41-30-PM_thumb.png" alt="1-12-2013 4-41-30 PM" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="1-12-2013 4-41-30 PM" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;If we are curios enough and decide to dig a little deeper, we will actually see what is causing this exception.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/ASP.NET-Web-API-Tracing-and_F529/1-12-2013-4-42-58-PM_thumb.png"&gt;&lt;img height="338" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/ASP.NET-Web-API-Tracing-and_F529/1-12-2013-4-42-58-PM_thumb.png" alt="1-12-2013 4-42-58 PM" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="1-12-2013 4-42-58 PM" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;{"Instances cannot be resolved and nested lifetimes cannot be created from this LifetimeScope as it has already been disposed."}&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp; at Autofac.Core.Lifetime.LifetimeScope.CheckNotDisposed()&lt;br /&gt;&amp;nbsp;&amp;nbsp; at Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters)&lt;br /&gt;&amp;nbsp;&amp;nbsp; at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable`1 parameters, Object&amp;amp; instance)&lt;br /&gt;&amp;nbsp;&amp;nbsp; at Autofac.ResolutionExtensions.ResolveOptionalService(IComponentContext context, Service service, IEnumerable`1 parameters)&lt;br /&gt;&amp;nbsp;&amp;nbsp; at Autofac.ResolutionExtensions.ResolveOptional(IComponentContext context, Type serviceType, IEnumerable`1 parameters)&lt;br /&gt;&amp;nbsp;&amp;nbsp; at Autofac.ResolutionExtensions.ResolveOptional(IComponentContext context, Type serviceType)&lt;br /&gt;&amp;nbsp;&amp;nbsp; at Autofac.Integration.WebApi.AutofacWebApiDependencyScope.GetService(Type serviceType)&lt;br /&gt;&amp;nbsp;&amp;nbsp; at DependencyScopeTracingDisposeBug.Tracing.WebApiTracer.Log(TraceRecord traceRecord) in e:\Apps\DependencyScopeTracingDisposeBug\Tracing\WebApiTracer.cs:line 25&lt;br /&gt;&amp;nbsp;&amp;nbsp; at DependencyScopeTracingDisposeBug.Tracing.WebApiTracer.Trace(HttpRequestMessage request, String category, TraceLevel level, Action`1 traceAction) in e:\Apps\DependencyScopeTracingDisposeBug\Tracing\WebApiTracer.cs:line 18&lt;br /&gt;&amp;nbsp;&amp;nbsp; at System.Web.Http.Tracing.ITraceWriterExtensions.TraceBeginEnd(ITraceWriter traceWriter, HttpRequestMessage request, String category, TraceLevel level, String operatorName, String operationName, Action`1 beginTrace, Action execute, Action`1 endTrace, Action`1 errorTrace)&lt;br /&gt;&amp;nbsp;&amp;nbsp; at System.Web.Http.Tracing.Tracers.HttpControllerTracer.System.IDisposable.Dispose()&lt;br /&gt;&amp;nbsp;&amp;nbsp; at System.Net.Http.HttpRequestMessageExtensions.DisposeRequestResources(HttpRequestMessage request)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;It wasn&amp;rsquo;t hard to diagnose the problem and the question was how to workaround it for now as the issue is caused by a code which is deep inside the bowel of the hosting layer. There are several workarounds for this problem which I can come up with quickly such as replacing the HttpControllerTracer but the one I applied was very dirty: adding a message handler as the first message handler (so that it runs last (just in case)) and reordering the disposables on the way out. Here is the message handler which performs this operation:&lt;/p&gt;
&lt;div class="code-wrapper border-shadow-1"&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;&lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;class&lt;/span&gt; DisposableRequestResourcesReorderHandler : DelegatingHandler {

    &lt;span style="color: blue;"&gt;protected&lt;/span&gt; &lt;span style="color: blue;"&gt;override&lt;/span&gt; Task&amp;lt;HttpResponseMessage&amp;gt; SendAsync(
        HttpRequestMessage request, CancellationToken cancellationToken) {

        &lt;span style="color: blue;"&gt;return&lt;/span&gt; &lt;span style="color: blue;"&gt;base&lt;/span&gt;.SendAsync(request, cancellationToken).Finally(() =&amp;gt; {

            List&amp;lt;IDisposable&amp;gt; disposableResources = 
                request.Properties[HttpPropertyKeys.DisposableRequestResourcesKey] &lt;span style="color: blue;"&gt;as&lt;/span&gt; List&amp;lt;IDisposable&amp;gt;;
                
            &lt;span style="color: blue;"&gt;if&lt;/span&gt; (disposableResources != &lt;span style="color: blue;"&gt;null&lt;/span&gt; &amp;amp;&amp;amp; disposableResources.Count &amp;gt; 1) {

                &lt;span style="color: green;"&gt;// 1-) Get the first one (which I know is AutofacWebApiDependencyScope).&lt;/span&gt;
                &lt;span style="color: green;"&gt;// 2-) Remove it from the list.&lt;/span&gt;
                &lt;span style="color: green;"&gt;// 3-) Push it at the end of the list.&lt;/span&gt;

                IDisposable dependencyScope = disposableResources[0];
                disposableResources.RemoveAt(0);
                disposableResources.Add(dependencyScope);
            }
        }, runSynchronously: &lt;span style="color: blue;"&gt;true&lt;/span&gt;);
    }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Notice that I used an extension method for Task object called Finally. This is a method which you can get by installing the &lt;a href="http://nuget.org/packages/TaskHelpers.Sources"&gt;TaskHelpers NuGet package&lt;/a&gt;. This allows you to run the continuation no matter what the status of the completed Task. Finally method will also propagate the proper Task back to the caller, which is kind of nice and clean in our case here as we want to run this code no matter what the status of the Task is.&lt;/p&gt;
&lt;p&gt;When you run the application after registering this message handler, you will see the controller&amp;rsquo;s dispose trace record being logged successfully.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/ASP.NET-Web-API-Tracing-and_F529/1-12-2013-7-35-21-PM.png"&gt;&lt;img height="161" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/ASP.NET-Web-API-Tracing-and_F529/1-12-2013-7-35-21-PM_thumb.png" alt="1-12-2013 7-35-21 PM" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="1-12-2013 7-35-21 PM" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;If you believe this is a bug and should be fixed, please vote for this issue: &lt;a href="http://aspnetwebstack.codeplex.com/workitem/768" title="http://aspnetwebstack.codeplex.com/workitem/768"&gt;http://aspnetwebstack.codeplex.com/workitem/768&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TugberkUgurlu/~4/Hvdx2dDQJXI" height="1" width="1"/&gt;</description><pubDate>Sat, 12 Jan 2013 18:26:00 Z</pubDate><a10:updated>2013-01-12T18:26:00Z</a10:updated><a10:content type="text">&lt;p&gt;&lt;a href="http://www.asp.net/web-api"&gt;ASP.NET Web API&lt;/a&gt; has a very cool built-in tracing mechanism. The coolest part about this feature is that none of the tracing code is being run if you don&amp;rsquo;t enable it. The mechanism makes use of well-known &lt;a href="http://en.wikipedia.org/wiki/Facade_pattern"&gt;Facade Pattern&lt;/a&gt; and if you enable tracing by providing your custom &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.http.tracing.itracewriter(v=vs.108).aspx"&gt;ITraceWriter&lt;/a&gt; implementation and don&amp;rsquo;t replace the default &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.http.tracing.itracemanager(v=vs.108).aspx"&gt;ITraceManager&lt;/a&gt; implementation, several ASP.NET Web API components (Message Handlers, Controllers, Filters, Formatters, etc.) will be wrapped up inside their tracer implementations (these are internal classes inside System.Web.Http assembly). You can learn more about tracing from &lt;a href="http://www.asp.net/web-api/overview/testing-and-debugging/tracing-in-aspnet-web-api"&gt;Tracing in ASP.NET Web API&lt;/a&gt; article.&lt;/p&gt;
&lt;p&gt;ASP.NET Web API also has this concept of carrying disposable objects inside the request properties bag and two objects are added to this disposable list by the framework as shown below (in the same order):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.http.dependencies.idependencyscope(v=vs.108).aspx"&gt;IDependencyScope&lt;/a&gt; implementation for the request.&lt;/li&gt;
&lt;li&gt;The selected &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.http.controllers.ihttpcontroller(v=vs.108).aspx"&gt;IHttpController&lt;/a&gt; implementation for the request.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The &lt;a href="http://msdn.microsoft.com/en-us/library/system.net.http.httprequestmessageextensions.disposerequestresources(v=vs.108).aspx"&gt;DisposeRequestResources&lt;/a&gt; extension method for the &lt;a href="http://msdn.microsoft.com/en-us/library/system.net.http.httprequestmessage.aspx"&gt;HttpRequestMessage&lt;/a&gt; object is invoked by the hosting layer at the end of each request to dispose the registered disposable objects. The invoker is the internal ConvertResponse method of &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.http.webhost.httpcontrollerhandler.aspx"&gt;HttpControllerHandler&lt;/a&gt; in case of ASP.NET host. The implementation of the DisposeRequestResources extension method is exactly as shown below:&lt;/p&gt;
&lt;div class="code-wrapper border-shadow-1"&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;&lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;static&lt;/span&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; DisposeRequestResources(&lt;span style="color: blue;"&gt;this&lt;/span&gt; HttpRequestMessage request) {

    &lt;span style="color: blue;"&gt;if&lt;/span&gt; (request == &lt;span style="color: blue;"&gt;null&lt;/span&gt;) {
        &lt;span style="color: blue;"&gt;throw&lt;/span&gt; Error.ArgumentNull(&lt;span style="color: #a31515;"&gt;"request"&lt;/span&gt;);
    }

    List&amp;lt;IDisposable&amp;gt; resourcesToDispose;
    &lt;span style="color: blue;"&gt;if&lt;/span&gt; (request.Properties.TryGetValue(HttpPropertyKeys.DisposableRequestResourcesKey, &lt;span style="color: blue;"&gt;out&lt;/span&gt; resourcesToDispose)) {
        &lt;span style="color: blue;"&gt;foreach&lt;/span&gt; (IDisposable resource &lt;span style="color: blue;"&gt;in&lt;/span&gt; resourcesToDispose) {
            &lt;span style="color: blue;"&gt;try&lt;/span&gt; {
                resource.Dispose();
            }
            &lt;span style="color: blue;"&gt;catch&lt;/span&gt; {
                &lt;span style="color: green;"&gt;// ignore exceptions&lt;/span&gt;
            }
        }
        resourcesToDispose.Clear();
    }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;It iterates through the list and disposes the registered objects one by one. So far so good. However, there is one slightly problem here depending on your ITraceWriter implementation. I&amp;rsquo;m not sure if it&amp;rsquo;s fair to call this a bug, but to me, it really is a bug. Let me explain what it is.&lt;/p&gt;
&lt;p&gt;As we know, the IDependencyScope implementation and the selected IHttpController implementation for the request are added to the disposables list in order to be disposed at the end of the request. As we also know, if we enable tracing in ASP.NET Web API, several ASP.NET Web API components wrapped inside their tracer implementations. In case of controllers, this is HttpControllerTracer. Since the IHttpController is also disposable, the HttpControllerTracer overrides the Dispose method to write a begin/end trace record for the dispose action. However, the disposable objects are disposed in order and when the controller&amp;rsquo;s dispose method is called, the dependency scope is already too far gone and if your custom ITraceWriter implementation tries to use the dependency scope, which is bound to that request, you will get an exception there. This doesn&amp;rsquo;t effect your application that much as this exception is swollen by the underlying infrastructure but this is not good. I wrote a little application to demonstrate this (actually, I went a little far and used a few more things for this *little* application &lt;img src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/ASP.NET-Web-API-Tracing-and_F529/wlEmoticon-smile.png" alt="Smile" style="border-style: none;" class="wlEmoticon wlEmoticon-smile" /&gt;) and show how to workaround it for now. &lt;a href="https://github.com/tugberkugurlu/ASPNETWebAPISamples/tree/master/DependencyScopeTracingDisposeBug"&gt;The code for this project is available on GitHub&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I created a custom tracer and registered through the global &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.http.httpconfiguration(v=vs.108).aspx"&gt;HttpConfiguration&lt;/a&gt; instance. This tracer tries to reach the ILoggerService implementation through the dependency scope. The code for my ITraceWriter implementation is as shown below:&lt;/p&gt;
&lt;div class="code-wrapper border-shadow-1"&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;&lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;class&lt;/span&gt; WebApiTracer : ITraceWriter {

    &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; Trace(
        HttpRequestMessage request, 
        &lt;span style="color: blue;"&gt;string&lt;/span&gt; category, 
        TraceLevel level, 
        Action&amp;lt;TraceRecord&amp;gt; traceAction) {

        &lt;span style="color: blue;"&gt;if&lt;/span&gt; (level != TraceLevel.Off) {

            TraceRecord record = &lt;span style="color: blue;"&gt;new&lt;/span&gt; TraceRecord(request, category, level);
            traceAction(record);
            Log(record);
        }
    }

    &lt;span style="color: blue;"&gt;private&lt;/span&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; Log(TraceRecord traceRecord) {

        IDependencyScope dependencyScope = 
            traceRecord.Request.GetDependencyScope();
            
        ILoggerService loggerService = 
            dependencyScope.GetService(&lt;span style="color: blue;"&gt;typeof&lt;/span&gt;(ILoggerService)) &lt;span style="color: blue;"&gt;as&lt;/span&gt; ILoggerService;
            
        &lt;span style="color: green;"&gt;// Log the trace data here using loggerService&lt;/span&gt;
        
        &lt;span style="color: green;"&gt;// Lines omitted for brevity&lt;/span&gt;
    }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;When we run this application in debug mode and send a request against a valid resource which will eventually go inside the controller pipeline (for this application /api/cars), we will see an exception as below:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/ASP.NET-Web-API-Tracing-and_F529/1-12-2013-4-41-30-PM.png"&gt;&lt;img height="229" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/ASP.NET-Web-API-Tracing-and_F529/1-12-2013-4-41-30-PM_thumb.png" alt="1-12-2013 4-41-30 PM" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="1-12-2013 4-41-30 PM" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;If we are curios enough and decide to dig a little deeper, we will actually see what is causing this exception.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/ASP.NET-Web-API-Tracing-and_F529/1-12-2013-4-42-58-PM_thumb.png"&gt;&lt;img height="338" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/ASP.NET-Web-API-Tracing-and_F529/1-12-2013-4-42-58-PM_thumb.png" alt="1-12-2013 4-42-58 PM" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="1-12-2013 4-42-58 PM" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;{"Instances cannot be resolved and nested lifetimes cannot be created from this LifetimeScope as it has already been disposed."}&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp; at Autofac.Core.Lifetime.LifetimeScope.CheckNotDisposed()&lt;br /&gt;&amp;nbsp;&amp;nbsp; at Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters)&lt;br /&gt;&amp;nbsp;&amp;nbsp; at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable`1 parameters, Object&amp;amp; instance)&lt;br /&gt;&amp;nbsp;&amp;nbsp; at Autofac.ResolutionExtensions.ResolveOptionalService(IComponentContext context, Service service, IEnumerable`1 parameters)&lt;br /&gt;&amp;nbsp;&amp;nbsp; at Autofac.ResolutionExtensions.ResolveOptional(IComponentContext context, Type serviceType, IEnumerable`1 parameters)&lt;br /&gt;&amp;nbsp;&amp;nbsp; at Autofac.ResolutionExtensions.ResolveOptional(IComponentContext context, Type serviceType)&lt;br /&gt;&amp;nbsp;&amp;nbsp; at Autofac.Integration.WebApi.AutofacWebApiDependencyScope.GetService(Type serviceType)&lt;br /&gt;&amp;nbsp;&amp;nbsp; at DependencyScopeTracingDisposeBug.Tracing.WebApiTracer.Log(TraceRecord traceRecord) in e:\Apps\DependencyScopeTracingDisposeBug\Tracing\WebApiTracer.cs:line 25&lt;br /&gt;&amp;nbsp;&amp;nbsp; at DependencyScopeTracingDisposeBug.Tracing.WebApiTracer.Trace(HttpRequestMessage request, String category, TraceLevel level, Action`1 traceAction) in e:\Apps\DependencyScopeTracingDisposeBug\Tracing\WebApiTracer.cs:line 18&lt;br /&gt;&amp;nbsp;&amp;nbsp; at System.Web.Http.Tracing.ITraceWriterExtensions.TraceBeginEnd(ITraceWriter traceWriter, HttpRequestMessage request, String category, TraceLevel level, String operatorName, String operationName, Action`1 beginTrace, Action execute, Action`1 endTrace, Action`1 errorTrace)&lt;br /&gt;&amp;nbsp;&amp;nbsp; at System.Web.Http.Tracing.Tracers.HttpControllerTracer.System.IDisposable.Dispose()&lt;br /&gt;&amp;nbsp;&amp;nbsp; at System.Net.Http.HttpRequestMessageExtensions.DisposeRequestResources(HttpRequestMessage request)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;It wasn&amp;rsquo;t hard to diagnose the problem and the question was how to workaround it for now as the issue is caused by a code which is deep inside the bowel of the hosting layer. There are several workarounds for this problem which I can come up with quickly such as replacing the HttpControllerTracer but the one I applied was very dirty: adding a message handler as the first message handler (so that it runs last (just in case)) and reordering the disposables on the way out. Here is the message handler which performs this operation:&lt;/p&gt;
&lt;div class="code-wrapper border-shadow-1"&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;&lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;class&lt;/span&gt; DisposableRequestResourcesReorderHandler : DelegatingHandler {

    &lt;span style="color: blue;"&gt;protected&lt;/span&gt; &lt;span style="color: blue;"&gt;override&lt;/span&gt; Task&amp;lt;HttpResponseMessage&amp;gt; SendAsync(
        HttpRequestMessage request, CancellationToken cancellationToken) {

        &lt;span style="color: blue;"&gt;return&lt;/span&gt; &lt;span style="color: blue;"&gt;base&lt;/span&gt;.SendAsync(request, cancellationToken).Finally(() =&amp;gt; {

            List&amp;lt;IDisposable&amp;gt; disposableResources = 
                request.Properties[HttpPropertyKeys.DisposableRequestResourcesKey] &lt;span style="color: blue;"&gt;as&lt;/span&gt; List&amp;lt;IDisposable&amp;gt;;
                
            &lt;span style="color: blue;"&gt;if&lt;/span&gt; (disposableResources != &lt;span style="color: blue;"&gt;null&lt;/span&gt; &amp;amp;&amp;amp; disposableResources.Count &amp;gt; 1) {

                &lt;span style="color: green;"&gt;// 1-) Get the first one (which I know is AutofacWebApiDependencyScope).&lt;/span&gt;
                &lt;span style="color: green;"&gt;// 2-) Remove it from the list.&lt;/span&gt;
                &lt;span style="color: green;"&gt;// 3-) Push it at the end of the list.&lt;/span&gt;

                IDisposable dependencyScope = disposableResources[0];
                disposableResources.RemoveAt(0);
                disposableResources.Add(dependencyScope);
            }
        }, runSynchronously: &lt;span style="color: blue;"&gt;true&lt;/span&gt;);
    }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Notice that I used an extension method for Task object called Finally. This is a method which you can get by installing the &lt;a href="http://nuget.org/packages/TaskHelpers.Sources"&gt;TaskHelpers NuGet package&lt;/a&gt;. This allows you to run the continuation no matter what the status of the completed Task. Finally method will also propagate the proper Task back to the caller, which is kind of nice and clean in our case here as we want to run this code no matter what the status of the Task is.&lt;/p&gt;
&lt;p&gt;When you run the application after registering this message handler, you will see the controller&amp;rsquo;s dispose trace record being logged successfully.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/ASP.NET-Web-API-Tracing-and_F529/1-12-2013-7-35-21-PM.png"&gt;&lt;img height="161" width="644" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/ASP.NET-Web-API-Tracing-and_F529/1-12-2013-7-35-21-PM_thumb.png" alt="1-12-2013 7-35-21 PM" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="1-12-2013 7-35-21 PM" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;If you believe this is a bug and should be fixed, please vote for this issue: &lt;a href="http://aspnetwebstack.codeplex.com/workitem/768" title="http://aspnetwebstack.codeplex.com/workitem/768"&gt;http://aspnetwebstack.codeplex.com/workitem/768&lt;/a&gt;.&lt;/p&gt;</a10:content><feedburner:origLink>http://tugberkugurlu.com/135</feedburner:origLink></item><item><guid isPermaLink="false">http://tugberkugurlu.com/134</guid><link>http://feedproxy.google.com/~r/TugberkUgurlu/~3/oc2dRsXquxM/134</link><title>Clean, Better, and Sexier Generic Repository Implementation for Entity Framework</title><description>&lt;p&gt;I have written a few blog posts about my experience &lt;a href="http://www.tugberkugurlu.com/archive/generic-repository-pattern-entity-framework-asp-net-mvc-and-unit-testing-triangle"&gt;on applying the Generic Repository pattern to Entity Framework&lt;/a&gt; and I even made a &lt;a href="http://nuget.org/packages/GenericRepository.EF"&gt;NuGet package for my na&amp;iuml;ve implementation&lt;/a&gt;. Even if that looked OK at the time for me, I had troubles about my implementation for couple of reasons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The implementations inside the NuGet package didn&amp;rsquo;t allow the developer to share the DbContext instance between repositories (per-request for example). &lt;/li&gt;
&lt;li&gt;When the generic repository methods weren&amp;rsquo;t enough, I was creating new repository interfaces and classes based on the generic ones. This was the biggest failure for me and didn&amp;rsquo;t scale very well as you can imagine. &lt;/li&gt;
&lt;li&gt;There were no pagination support. &lt;/li&gt;
&lt;li&gt;As each repository take a direct dependency on DbContext and it is impossible to entirely fake the DbContext, generic repositories needed to be mocked so that we could test with them. However, it would be just very useful to pass a fake DbContext instance into the repository implementation itself and use it as fake.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;With the new release of the &lt;a href="http://nuget.org/packages/GenericRepository.EntityFramework"&gt;GenericRepository.EntityFramework&lt;/a&gt; package, the all of the above problems have their solutions. The source code for this release is available under the &lt;a href="https://github.com/tugberkugurlu/GenericRepository/tree/master"&gt;master branch of the repository&lt;/a&gt; and you can also see the ongoing work for the final release under the &lt;a href="https://github.com/tugberkugurlu/GenericRepository/tree/v0.3.0"&gt;v0.3.0 branch&lt;/a&gt;. The NuGet package is available as pre-release for now. So, you need to use the &amp;ndash;pre switch to install it.&lt;/p&gt;
&lt;div class="nuget-badge"&gt;
&lt;p&gt;&lt;code&gt;PM&amp;gt; Install-Package GenericRepository.EntityFramework -Pre &lt;/code&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;The old &lt;a href="http://nuget.org/packages/GenericRepository.EF"&gt;GenericRepository.EF&lt;/a&gt; package is still around and I will update it, too but it&amp;rsquo;s now unlisted and only thing it does is to install the GenericRepository.EntityFramework package.&lt;/p&gt;
&lt;p&gt;I also included &lt;a href="https://github.com/tugberkugurlu/GenericRepository/tree/master/samples"&gt;a sample application which shows the usage briefly&lt;/a&gt;. I will complete the sample and extend it further for a better view. Definitely check this out!&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s dive right in and see what is new and cool.&lt;/p&gt;
&lt;h3&gt;IEntity and IEntity&amp;lt;TId&amp;gt; Interfaces&lt;/h3&gt;
&lt;p&gt;I introduced two new interfaces: &lt;a href="https://github.com/tugberkugurlu/GenericRepository/blob/master/src/GenericRepository/IEntity.cs"&gt;IEntity&lt;/a&gt; and &lt;a href="https://github.com/tugberkugurlu/GenericRepository/blob/master/src/GenericRepository/IEntity'1.cs"&gt;IEntity&amp;lt;TId&amp;gt;&lt;/a&gt; and each of your entity classes needs to implement one of these. As you can see from the implementation, IEntity just implements the IEntity&amp;lt;int&amp;gt; and you can use IEntity if you are using integer based Ids. The reason why I added these is make the GetSingle method work.&lt;/p&gt;
&lt;h3&gt;Use EntitiesContext Instead of DbContext&lt;/h3&gt;
&lt;p&gt;Instead of deriving your context class from DbContext, you now need to take the &lt;a href="https://github.com/tugberkugurlu/GenericRepository/blob/master/src/GenericRepository.EntityFramework/EntitiesContext.cs"&gt;EntitiesContext&lt;/a&gt; as the base class for your context. If you have an existing context class based on DbContext, changing it to use EntitiesContext should not break it. The EntitiesContext class has all the same constructors as DbContext. So, you can also use those. Here is the sample:&lt;/p&gt;
&lt;div class="code-wrapper border-shadow-1"&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;&lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;class&lt;/span&gt; AccommodationEntities : EntitiesContext {

    &lt;span style="color: green;"&gt;// NOTE: You have the same constructors as the DbContext here. E.g:&lt;/span&gt;
    &lt;span style="color: green;"&gt;// public AccommodationEntities() : base("nameOrConnectionString") { }&lt;/span&gt;

    &lt;span style="color: blue;"&gt;public&lt;/span&gt; IDbSet&amp;lt;Country&amp;gt; Countries { &lt;span style="color: blue;"&gt;get&lt;/span&gt;; &lt;span style="color: blue;"&gt;set&lt;/span&gt;; }
    &lt;span style="color: blue;"&gt;public&lt;/span&gt; IDbSet&amp;lt;Resort&amp;gt; Resorts { &lt;span style="color: blue;"&gt;get&lt;/span&gt;; &lt;span style="color: blue;"&gt;set&lt;/span&gt;; }
    &lt;span style="color: blue;"&gt;public&lt;/span&gt; IDbSet&amp;lt;Hotel&amp;gt; Hotels { &lt;span style="color: blue;"&gt;get&lt;/span&gt;; &lt;span style="color: blue;"&gt;set&lt;/span&gt;; }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Then, through your IoC container, you can register your context as a new instance for &lt;a href="https://github.com/tugberkugurlu/GenericRepository/blob/master/src/GenericRepository.EntityFramework/IEntitiesContext.cs"&gt;IEntitiesContext&lt;/a&gt; per a particular scope. The below example uses Autofac to do that for an &lt;a href="http://www.asp.net/web-api"&gt;ASP.NET Web API&lt;/a&gt; application:&lt;/p&gt;
&lt;div class="code-wrapper border-shadow-1"&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;&lt;span style="color: blue;"&gt;private&lt;/span&gt; &lt;span style="color: blue;"&gt;static&lt;/span&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; RegisterDependencies(HttpConfiguration config) {

    &lt;span style="color: blue;"&gt;var&lt;/span&gt; builder = &lt;span style="color: blue;"&gt;new&lt;/span&gt; ContainerBuilder();
    builder.RegisterApiControllers(Assembly.GetExecutingAssembly());

    &lt;span style="color: green;"&gt;// Register IEntitiesContext&lt;/span&gt;
    builder.Register(_ =&amp;gt; &lt;span style="color: blue;"&gt;new&lt;/span&gt; AccommodationEntities())
           .As&amp;lt;IEntitiesContext&amp;gt;().InstancePerApiRequest();

    &lt;span style="color: green;"&gt;// TODO: Register repositories here&lt;/span&gt;

    config.DependencyResolver = 
        &lt;span style="color: blue;"&gt;new&lt;/span&gt; AutofacWebApiDependencyResolver(builder.Build());
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h3&gt;IEntityRepository&amp;lt;TEntity&amp;gt; and EntityRepository&amp;lt;TEntity&amp;gt;&lt;/h3&gt;
&lt;p&gt;Here is the real meat of the package: IEntityRepository and EntityRepository. Same as the IEntity and IEntity&amp;lt;TId&amp;gt;, we have two different IEntityRepository generic interfaces: &lt;a href="https://github.com/tugberkugurlu/GenericRepository/blob/master/src/GenericRepository.EntityFramework/IEntityRepository'1.cs"&gt;IEntityRepository&amp;lt;TEntity&amp;gt;&lt;/a&gt; and &lt;a href="https://github.com/tugberkugurlu/GenericRepository/blob/master/src/GenericRepository.EntityFramework/IEntityRepository'2.cs"&gt;IEntityRepository&amp;lt;TEntity, TId&amp;gt;&lt;/a&gt;. They have their implementations under the same generic signature: &lt;a href="https://github.com/tugberkugurlu/GenericRepository/blob/master/src/GenericRepository.EntityFramework/EntityRepository'1.cs"&gt;EntityRepository&amp;lt;TEntity&amp;gt;&lt;/a&gt; and &lt;a href="https://github.com/tugberkugurlu/GenericRepository/blob/master/src/GenericRepository.EntityFramework/EntityRepository'2.cs"&gt;EntityRepository&amp;lt;TEntity, TId&amp;gt;&lt;/a&gt;. The big improvement now is that EntityRepository generic repository implementation accepts an IEntitiesContext implementation through its constructor. This, for example, enables you to use the same DbContext (IEntitiesContext implementation in our case, which is EntitiesContext by default) instance per-request for your &lt;a href="http://www.asp.net/mvc"&gt;ASP.NET MVC&lt;/a&gt;, ASP.NET Web API application and share that across your repositories. Note: don&amp;rsquo;t ever use singleton DbContext instance throughout your AppDomain. &lt;a href="http://stackoverflow.com/questions/6126616/is-dbcontext-thread-safe"&gt;DbContext is not thread safe&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;As we have registered our EntitiesContext instance per request above, we can now register the repositories as well. As our repositories accepts an IEntitiesContext implementation through their constructor, our IoC container will use our previous registration for that automatically. Autofac has this ability as nearly all IoC containers do.&lt;/p&gt;
&lt;div class="code-wrapper border-shadow-1"&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;&lt;span style="color: blue;"&gt;private&lt;/span&gt; &lt;span style="color: blue;"&gt;static&lt;/span&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; RegisterDependencies(HttpConfiguration config) {

    &lt;span style="color: blue;"&gt;var&lt;/span&gt; builder = &lt;span style="color: blue;"&gt;new&lt;/span&gt; ContainerBuilder();
    builder.RegisterApiControllers(Assembly.GetExecutingAssembly());

    &lt;span style="color: green;"&gt;// Register IEntitiesContext&lt;/span&gt;
    builder.Register(_ =&amp;gt; &lt;span style="color: blue;"&gt;new&lt;/span&gt; AccommodationEntities())
           .As&amp;lt;IEntitiesContext&amp;gt;().InstancePerApiRequest();

    &lt;span style="color: green;"&gt;// TODO: Register repositories here&lt;/span&gt;
    builder.RegisterType&amp;lt;EntityRepository&amp;lt;Country&amp;gt;&amp;gt;()
           .As&amp;lt;IEntityRepository&amp;lt;Country&amp;gt;&amp;gt;().InstancePerApiRequest();
    builder.RegisterType&amp;lt;EntityRepository&amp;lt;Resort&amp;gt;&amp;gt;()
           .As&amp;lt;IEntityRepository&amp;lt;Resort&amp;gt;&amp;gt;().InstancePerApiRequest();
    builder.RegisterType&amp;lt;EntityRepository&amp;lt;Hotel&amp;gt;&amp;gt;()
           .As&amp;lt;IEntityRepository&amp;lt;Hotel&amp;gt;&amp;gt;().InstancePerApiRequest();

    config.DependencyResolver = 
        &lt;span style="color: blue;"&gt;new&lt;/span&gt; AutofacWebApiDependencyResolver(builder.Build());
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h3&gt;Out of the Box Pagination Support&lt;/h3&gt;
&lt;p&gt;Best feature with this release is out of the box pagination support with generic repository instances. It doesn&amp;rsquo;t perform the pagination in-memory; it queries the database accordingly and gets only the parts which are needed which is the whole point &lt;img class="wlEmoticon wlEmoticon-smile" style="border-style: none;" alt="Smile" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/8007d0fd3e72_107A4/wlEmoticon-smile.png" /&gt; Here is an ASP.NET Web API controller which uses the pagination support comes with the EntityRepository:&lt;/p&gt;
&lt;div class="code-wrapper border-shadow-1"&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;&lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;class&lt;/span&gt; CountriesController : ApiController {

    &lt;span style="color: blue;"&gt;private&lt;/span&gt; &lt;span style="color: blue;"&gt;readonly&lt;/span&gt; IEntityRepository&amp;lt;Country&amp;gt; _countryRepository;
    &lt;span style="color: blue;"&gt;private&lt;/span&gt; &lt;span style="color: blue;"&gt;readonly&lt;/span&gt; IMappingEngine _mapper;
    &lt;span style="color: blue;"&gt;public&lt;/span&gt; CountriesController(
        IEntityRepository&amp;lt;Country&amp;gt; countryRepository, 
        IMappingEngine mapper) {

        _countryRepository = countryRepository;
        _mapper = mapper;
    }

    &lt;span style="color: green;"&gt;// GET api/countries?pageindex=1&amp;amp;pagesize=5&lt;/span&gt;
    &lt;span style="color: blue;"&gt;public&lt;/span&gt; PaginatedDto&amp;lt;CountryDto&amp;gt; GetCountries(&lt;span style="color: blue;"&gt;int&lt;/span&gt; pageIndex, &lt;span style="color: blue;"&gt;int&lt;/span&gt; pageSize) {

        PaginatedList&amp;lt;Country&amp;gt; countries = 
             _countryRepository.Paginate(pageIndex, pageSize);

        PaginatedDto&amp;lt;CountryDto&amp;gt; countryPaginatedDto = 
           _mapper.Map&amp;lt;PaginatedList&amp;lt;Country&amp;gt;, PaginatedDto&amp;lt;CountryDto&amp;gt;&amp;gt;(countries);

        &lt;span style="color: blue;"&gt;return&lt;/span&gt; countryPaginatedDto;
    }
}

&lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;interface&lt;/span&gt; IPaginatedDto&amp;lt;&lt;span style="color: blue;"&gt;out&lt;/span&gt; TDto&amp;gt; &lt;span style="color: blue;"&gt;where&lt;/span&gt; TDto : IDto {

    &lt;span style="color: blue;"&gt;int&lt;/span&gt; PageIndex { &lt;span style="color: blue;"&gt;get&lt;/span&gt;; &lt;span style="color: blue;"&gt;set&lt;/span&gt;; }
    &lt;span style="color: blue;"&gt;int&lt;/span&gt; PageSize { &lt;span style="color: blue;"&gt;get&lt;/span&gt;; &lt;span style="color: blue;"&gt;set&lt;/span&gt;; }
    &lt;span style="color: blue;"&gt;int&lt;/span&gt; TotalCount { &lt;span style="color: blue;"&gt;get&lt;/span&gt;; &lt;span style="color: blue;"&gt;set&lt;/span&gt;; }
    &lt;span style="color: blue;"&gt;int&lt;/span&gt; TotalPageCount { &lt;span style="color: blue;"&gt;get&lt;/span&gt;; &lt;span style="color: blue;"&gt;set&lt;/span&gt;; }

    &lt;span style="color: blue;"&gt;bool&lt;/span&gt; HasNextPage { &lt;span style="color: blue;"&gt;get&lt;/span&gt;; &lt;span style="color: blue;"&gt;set&lt;/span&gt;; }
    &lt;span style="color: blue;"&gt;bool&lt;/span&gt; HasPreviousPage { &lt;span style="color: blue;"&gt;get&lt;/span&gt;; &lt;span style="color: blue;"&gt;set&lt;/span&gt;; }

    IEnumerable&amp;lt;TDto&amp;gt; Items { &lt;span style="color: blue;"&gt;get&lt;/span&gt;; }
}

&lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;class&lt;/span&gt; PaginatedDto&amp;lt;TDto&amp;gt; : IPaginatedDto&amp;lt;TDto&amp;gt; &lt;span style="color: blue;"&gt;where&lt;/span&gt; TDto : IDto {

    &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;int&lt;/span&gt; PageIndex { &lt;span style="color: blue;"&gt;get&lt;/span&gt;; &lt;span style="color: blue;"&gt;set&lt;/span&gt;; }
    &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;int&lt;/span&gt; PageSize { &lt;span style="color: blue;"&gt;get&lt;/span&gt;; &lt;span style="color: blue;"&gt;set&lt;/span&gt;; }
    &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;int&lt;/span&gt; TotalCount { &lt;span style="color: blue;"&gt;get&lt;/span&gt;; &lt;span style="color: blue;"&gt;set&lt;/span&gt;; }
    &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;int&lt;/span&gt; TotalPageCount { &lt;span style="color: blue;"&gt;get&lt;/span&gt;; &lt;span style="color: blue;"&gt;set&lt;/span&gt;; }

    &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;bool&lt;/span&gt; HasNextPage { &lt;span style="color: blue;"&gt;get&lt;/span&gt;; &lt;span style="color: blue;"&gt;set&lt;/span&gt;; }
    &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;bool&lt;/span&gt; HasPreviousPage { &lt;span style="color: blue;"&gt;get&lt;/span&gt;; &lt;span style="color: blue;"&gt;set&lt;/span&gt;; }

    &lt;span style="color: blue;"&gt;public&lt;/span&gt; IEnumerable&amp;lt;TDto&amp;gt; Items { &lt;span style="color: blue;"&gt;get&lt;/span&gt;; &lt;span style="color: blue;"&gt;set&lt;/span&gt;; }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Paginate method will return us the PaginatedList&amp;lt;TEntity&amp;gt; object back and we can project that into our own Dto object as you can see above. I used AutoMapper for that. If I send a request to this API endpoint and ask for response in JSON format, I get back the below result:&lt;/p&gt;
&lt;div class="code-wrapper border-shadow-1"&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;{
    &lt;span style="color: #a31515;"&gt;"PageIndex"&lt;/span&gt;:1,
    &lt;span style="color: #a31515;"&gt;"PageSize"&lt;/span&gt;:2,
    &lt;span style="color: #a31515;"&gt;"TotalCount"&lt;/span&gt;:6,
    &lt;span style="color: #a31515;"&gt;"TotalPageCount"&lt;/span&gt;:3,
    &lt;span style="color: #a31515;"&gt;"HasNextPage"&lt;/span&gt;:&lt;span style="color: blue;"&gt;true&lt;/span&gt;,
    &lt;span style="color: #a31515;"&gt;"HasPreviousPage"&lt;/span&gt;:&lt;span style="color: blue;"&gt;false&lt;/span&gt;,
    &lt;span style="color: #a31515;"&gt;"Items"&lt;/span&gt;:[
      {
        &lt;span style="color: #a31515;"&gt;"Id"&lt;/span&gt;:1,
        &lt;span style="color: #a31515;"&gt;"Name"&lt;/span&gt;:&lt;span style="color: #a31515;"&gt;"Turkey"&lt;/span&gt;,
        &lt;span style="color: #a31515;"&gt;"ISOCode"&lt;/span&gt;:&lt;span style="color: #a31515;"&gt;"TR"&lt;/span&gt;,
        &lt;span style="color: #a31515;"&gt;"CreatedOn"&lt;/span&gt;:&lt;span style="color: #a31515;"&gt;"2013-01-08T21:12:26.5854461+02:00"&lt;/span&gt;
      },
      {
        &lt;span style="color: #a31515;"&gt;"Id"&lt;/span&gt;:2,
        &lt;span style="color: #a31515;"&gt;"Name"&lt;/span&gt;:&lt;span style="color: #a31515;"&gt;"United Kingdom"&lt;/span&gt;,
        &lt;span style="color: #a31515;"&gt;"ISOCode"&lt;/span&gt;:&lt;span style="color: #a31515;"&gt;"UK"&lt;/span&gt;,
        &lt;span style="color: #a31515;"&gt;"CreatedOn"&lt;/span&gt;:&lt;span style="color: #a31515;"&gt;"2013-01-08T21:12:26.5864465+02:00"&lt;/span&gt;
      }
    ]
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Isn&amp;rsquo;t this perfect &lt;img class="wlEmoticon wlEmoticon-smile" style="border-style: none;" alt="Smile" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/8007d0fd3e72_107A4/wlEmoticon-smile.png" /&gt; There are other pagination method inside the EntityRepository implementation which supports &lt;a href="http://msdn.microsoft.com/en-us/library/gg671236%28v=vs.103%29.aspx"&gt;including child or parent entities&lt;/a&gt; and sorting. You also have the &lt;a href="https://github.com/tugberkugurlu/GenericRepository/blob/master/src/GenericRepository/QueryableExtensions.cs"&gt;ToPaginatedList&lt;/a&gt; extension method and you can build your query and call ToPaginatedList on that query to get PaginatedList&amp;lt;TEntity&amp;gt; object back.&lt;/p&gt;
&lt;h3&gt;Extending the IEntityRepository&amp;lt;TEntity&amp;gt;&lt;/h3&gt;
&lt;p&gt;In my previous blog posts, I kind of sucked at extending the generic repository. So, I wanted to show here the better approach that I have been taking for a while now. This is not a feature of my generic repository, this is the feature of .NET itself: extension methods! If you need extra methods for your specific repository, you can always extend the IEntityRepository&amp;lt;TEntity, TId&amp;gt; which gives you a better way to extend your repositories. Here is an example:&lt;/p&gt;
&lt;div class="code-wrapper border-shadow-1"&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;&lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;static&lt;/span&gt; &lt;span style="color: blue;"&gt;class&lt;/span&gt; HotelRepositoryExtensions {

    &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;static&lt;/span&gt; IQueryable&amp;lt;Hotel&amp;gt; GetAllByResortId(
        &lt;span style="color: blue;"&gt;this&lt;/span&gt; IEntityRepository&amp;lt;Hotel, &lt;span style="color: blue;"&gt;int&lt;/span&gt;&amp;gt; hotelRepository, &lt;span style="color: blue;"&gt;int&lt;/span&gt; resortId) {

        &lt;span style="color: blue;"&gt;return&lt;/span&gt; hotelRepository.FindBy(x =&amp;gt; x.ResortId == resortId);
    }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h3&gt;What is Next?&lt;/h3&gt;
&lt;p&gt;My first intention is finish writing all the tests for the whole project, fix bugs and inconsistencies for the v0.3.0 release. After that release, I will work on EF6 version for my generic repository implementation which will have sweet asynchronous support. I also plan to release a generic repository implementation for MongoDB.&lt;/p&gt;
&lt;p&gt;Stay tuned, &lt;a href="http://nuget.org/packages/GenericRepository.EntityFramework"&gt;install the package&lt;/a&gt;, play with it and &lt;a href="https://github.com/tugberkugurlu/GenericRepository/issues"&gt;give feedback&lt;/a&gt;&amp;nbsp;&lt;img class="wlEmoticon wlEmoticon-winkingsmile" style="border-style: none;" alt="Winking smile" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/8007d0fd3e72_107A4/wlEmoticon-winkingsmile.png" /&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TugberkUgurlu/~4/oc2dRsXquxM" height="1" width="1"/&gt;</description><pubDate>Thu, 10 Jan 2013 15:00:00 Z</pubDate><a10:updated>2013-01-10T15:00:00Z</a10:updated><a10:content type="text">&lt;p&gt;I have written a few blog posts about my experience &lt;a href="http://www.tugberkugurlu.com/archive/generic-repository-pattern-entity-framework-asp-net-mvc-and-unit-testing-triangle"&gt;on applying the Generic Repository pattern to Entity Framework&lt;/a&gt; and I even made a &lt;a href="http://nuget.org/packages/GenericRepository.EF"&gt;NuGet package for my na&amp;iuml;ve implementation&lt;/a&gt;. Even if that looked OK at the time for me, I had troubles about my implementation for couple of reasons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The implementations inside the NuGet package didn&amp;rsquo;t allow the developer to share the DbContext instance between repositories (per-request for example). &lt;/li&gt;
&lt;li&gt;When the generic repository methods weren&amp;rsquo;t enough, I was creating new repository interfaces and classes based on the generic ones. This was the biggest failure for me and didn&amp;rsquo;t scale very well as you can imagine. &lt;/li&gt;
&lt;li&gt;There were no pagination support. &lt;/li&gt;
&lt;li&gt;As each repository take a direct dependency on DbContext and it is impossible to entirely fake the DbContext, generic repositories needed to be mocked so that we could test with them. However, it would be just very useful to pass a fake DbContext instance into the repository implementation itself and use it as fake.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;With the new release of the &lt;a href="http://nuget.org/packages/GenericRepository.EntityFramework"&gt;GenericRepository.EntityFramework&lt;/a&gt; package, the all of the above problems have their solutions. The source code for this release is available under the &lt;a href="https://github.com/tugberkugurlu/GenericRepository/tree/master"&gt;master branch of the repository&lt;/a&gt; and you can also see the ongoing work for the final release under the &lt;a href="https://github.com/tugberkugurlu/GenericRepository/tree/v0.3.0"&gt;v0.3.0 branch&lt;/a&gt;. The NuGet package is available as pre-release for now. So, you need to use the &amp;ndash;pre switch to install it.&lt;/p&gt;
&lt;div class="nuget-badge"&gt;
&lt;p&gt;&lt;code&gt;PM&amp;gt; Install-Package GenericRepository.EntityFramework -Pre &lt;/code&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;The old &lt;a href="http://nuget.org/packages/GenericRepository.EF"&gt;GenericRepository.EF&lt;/a&gt; package is still around and I will update it, too but it&amp;rsquo;s now unlisted and only thing it does is to install the GenericRepository.EntityFramework package.&lt;/p&gt;
&lt;p&gt;I also included &lt;a href="https://github.com/tugberkugurlu/GenericRepository/tree/master/samples"&gt;a sample application which shows the usage briefly&lt;/a&gt;. I will complete the sample and extend it further for a better view. Definitely check this out!&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s dive right in and see what is new and cool.&lt;/p&gt;
&lt;h3&gt;IEntity and IEntity&amp;lt;TId&amp;gt; Interfaces&lt;/h3&gt;
&lt;p&gt;I introduced two new interfaces: &lt;a href="https://github.com/tugberkugurlu/GenericRepository/blob/master/src/GenericRepository/IEntity.cs"&gt;IEntity&lt;/a&gt; and &lt;a href="https://github.com/tugberkugurlu/GenericRepository/blob/master/src/GenericRepository/IEntity'1.cs"&gt;IEntity&amp;lt;TId&amp;gt;&lt;/a&gt; and each of your entity classes needs to implement one of these. As you can see from the implementation, IEntity just implements the IEntity&amp;lt;int&amp;gt; and you can use IEntity if you are using integer based Ids. The reason why I added these is make the GetSingle method work.&lt;/p&gt;
&lt;h3&gt;Use EntitiesContext Instead of DbContext&lt;/h3&gt;
&lt;p&gt;Instead of deriving your context class from DbContext, you now need to take the &lt;a href="https://github.com/tugberkugurlu/GenericRepository/blob/master/src/GenericRepository.EntityFramework/EntitiesContext.cs"&gt;EntitiesContext&lt;/a&gt; as the base class for your context. If you have an existing context class based on DbContext, changing it to use EntitiesContext should not break it. The EntitiesContext class has all the same constructors as DbContext. So, you can also use those. Here is the sample:&lt;/p&gt;
&lt;div class="code-wrapper border-shadow-1"&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;&lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;class&lt;/span&gt; AccommodationEntities : EntitiesContext {

    &lt;span style="color: green;"&gt;// NOTE: You have the same constructors as the DbContext here. E.g:&lt;/span&gt;
    &lt;span style="color: green;"&gt;// public AccommodationEntities() : base("nameOrConnectionString") { }&lt;/span&gt;

    &lt;span style="color: blue;"&gt;public&lt;/span&gt; IDbSet&amp;lt;Country&amp;gt; Countries { &lt;span style="color: blue;"&gt;get&lt;/span&gt;; &lt;span style="color: blue;"&gt;set&lt;/span&gt;; }
    &lt;span style="color: blue;"&gt;public&lt;/span&gt; IDbSet&amp;lt;Resort&amp;gt; Resorts { &lt;span style="color: blue;"&gt;get&lt;/span&gt;; &lt;span style="color: blue;"&gt;set&lt;/span&gt;; }
    &lt;span style="color: blue;"&gt;public&lt;/span&gt; IDbSet&amp;lt;Hotel&amp;gt; Hotels { &lt;span style="color: blue;"&gt;get&lt;/span&gt;; &lt;span style="color: blue;"&gt;set&lt;/span&gt;; }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Then, through your IoC container, you can register your context as a new instance for &lt;a href="https://github.com/tugberkugurlu/GenericRepository/blob/master/src/GenericRepository.EntityFramework/IEntitiesContext.cs"&gt;IEntitiesContext&lt;/a&gt; per a particular scope. The below example uses Autofac to do that for an &lt;a href="http://www.asp.net/web-api"&gt;ASP.NET Web API&lt;/a&gt; application:&lt;/p&gt;
&lt;div class="code-wrapper border-shadow-1"&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;&lt;span style="color: blue;"&gt;private&lt;/span&gt; &lt;span style="color: blue;"&gt;static&lt;/span&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; RegisterDependencies(HttpConfiguration config) {

    &lt;span style="color: blue;"&gt;var&lt;/span&gt; builder = &lt;span style="color: blue;"&gt;new&lt;/span&gt; ContainerBuilder();
    builder.RegisterApiControllers(Assembly.GetExecutingAssembly());

    &lt;span style="color: green;"&gt;// Register IEntitiesContext&lt;/span&gt;
    builder.Register(_ =&amp;gt; &lt;span style="color: blue;"&gt;new&lt;/span&gt; AccommodationEntities())
           .As&amp;lt;IEntitiesContext&amp;gt;().InstancePerApiRequest();

    &lt;span style="color: green;"&gt;// TODO: Register repositories here&lt;/span&gt;

    config.DependencyResolver = 
        &lt;span style="color: blue;"&gt;new&lt;/span&gt; AutofacWebApiDependencyResolver(builder.Build());
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h3&gt;IEntityRepository&amp;lt;TEntity&amp;gt; and EntityRepository&amp;lt;TEntity&amp;gt;&lt;/h3&gt;
&lt;p&gt;Here is the real meat of the package: IEntityRepository and EntityRepository. Same as the IEntity and IEntity&amp;lt;TId&amp;gt;, we have two different IEntityRepository generic interfaces: &lt;a href="https://github.com/tugberkugurlu/GenericRepository/blob/master/src/GenericRepository.EntityFramework/IEntityRepository'1.cs"&gt;IEntityRepository&amp;lt;TEntity&amp;gt;&lt;/a&gt; and &lt;a href="https://github.com/tugberkugurlu/GenericRepository/blob/master/src/GenericRepository.EntityFramework/IEntityRepository'2.cs"&gt;IEntityRepository&amp;lt;TEntity, TId&amp;gt;&lt;/a&gt;. They have their implementations under the same generic signature: &lt;a href="https://github.com/tugberkugurlu/GenericRepository/blob/master/src/GenericRepository.EntityFramework/EntityRepository'1.cs"&gt;EntityRepository&amp;lt;TEntity&amp;gt;&lt;/a&gt; and &lt;a href="https://github.com/tugberkugurlu/GenericRepository/blob/master/src/GenericRepository.EntityFramework/EntityRepository'2.cs"&gt;EntityRepository&amp;lt;TEntity, TId&amp;gt;&lt;/a&gt;. The big improvement now is that EntityRepository generic repository implementation accepts an IEntitiesContext implementation through its constructor. This, for example, enables you to use the same DbContext (IEntitiesContext implementation in our case, which is EntitiesContext by default) instance per-request for your &lt;a href="http://www.asp.net/mvc"&gt;ASP.NET MVC&lt;/a&gt;, ASP.NET Web API application and share that across your repositories. Note: don&amp;rsquo;t ever use singleton DbContext instance throughout your AppDomain. &lt;a href="http://stackoverflow.com/questions/6126616/is-dbcontext-thread-safe"&gt;DbContext is not thread safe&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;As we have registered our EntitiesContext instance per request above, we can now register the repositories as well. As our repositories accepts an IEntitiesContext implementation through their constructor, our IoC container will use our previous registration for that automatically. Autofac has this ability as nearly all IoC containers do.&lt;/p&gt;
&lt;div class="code-wrapper border-shadow-1"&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;&lt;span style="color: blue;"&gt;private&lt;/span&gt; &lt;span style="color: blue;"&gt;static&lt;/span&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; RegisterDependencies(HttpConfiguration config) {

    &lt;span style="color: blue;"&gt;var&lt;/span&gt; builder = &lt;span style="color: blue;"&gt;new&lt;/span&gt; ContainerBuilder();
    builder.RegisterApiControllers(Assembly.GetExecutingAssembly());

    &lt;span style="color: green;"&gt;// Register IEntitiesContext&lt;/span&gt;
    builder.Register(_ =&amp;gt; &lt;span style="color: blue;"&gt;new&lt;/span&gt; AccommodationEntities())
           .As&amp;lt;IEntitiesContext&amp;gt;().InstancePerApiRequest();

    &lt;span style="color: green;"&gt;// TODO: Register repositories here&lt;/span&gt;
    builder.RegisterType&amp;lt;EntityRepository&amp;lt;Country&amp;gt;&amp;gt;()
           .As&amp;lt;IEntityRepository&amp;lt;Country&amp;gt;&amp;gt;().InstancePerApiRequest();
    builder.RegisterType&amp;lt;EntityRepository&amp;lt;Resort&amp;gt;&amp;gt;()
           .As&amp;lt;IEntityRepository&amp;lt;Resort&amp;gt;&amp;gt;().InstancePerApiRequest();
    builder.RegisterType&amp;lt;EntityRepository&amp;lt;Hotel&amp;gt;&amp;gt;()
           .As&amp;lt;IEntityRepository&amp;lt;Hotel&amp;gt;&amp;gt;().InstancePerApiRequest();

    config.DependencyResolver = 
        &lt;span style="color: blue;"&gt;new&lt;/span&gt; AutofacWebApiDependencyResolver(builder.Build());
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h3&gt;Out of the Box Pagination Support&lt;/h3&gt;
&lt;p&gt;Best feature with this release is out of the box pagination support with generic repository instances. It doesn&amp;rsquo;t perform the pagination in-memory; it queries the database accordingly and gets only the parts which are needed which is the whole point &lt;img class="wlEmoticon wlEmoticon-smile" style="border-style: none;" alt="Smile" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/8007d0fd3e72_107A4/wlEmoticon-smile.png" /&gt; Here is an ASP.NET Web API controller which uses the pagination support comes with the EntityRepository:&lt;/p&gt;
&lt;div class="code-wrapper border-shadow-1"&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;&lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;class&lt;/span&gt; CountriesController : ApiController {

    &lt;span style="color: blue;"&gt;private&lt;/span&gt; &lt;span style="color: blue;"&gt;readonly&lt;/span&gt; IEntityRepository&amp;lt;Country&amp;gt; _countryRepository;
    &lt;span style="color: blue;"&gt;private&lt;/span&gt; &lt;span style="color: blue;"&gt;readonly&lt;/span&gt; IMappingEngine _mapper;
    &lt;span style="color: blue;"&gt;public&lt;/span&gt; CountriesController(
        IEntityRepository&amp;lt;Country&amp;gt; countryRepository, 
        IMappingEngine mapper) {

        _countryRepository = countryRepository;
        _mapper = mapper;
    }

    &lt;span style="color: green;"&gt;// GET api/countries?pageindex=1&amp;amp;pagesize=5&lt;/span&gt;
    &lt;span style="color: blue;"&gt;public&lt;/span&gt; PaginatedDto&amp;lt;CountryDto&amp;gt; GetCountries(&lt;span style="color: blue;"&gt;int&lt;/span&gt; pageIndex, &lt;span style="color: blue;"&gt;int&lt;/span&gt; pageSize) {

        PaginatedList&amp;lt;Country&amp;gt; countries = 
             _countryRepository.Paginate(pageIndex, pageSize);

        PaginatedDto&amp;lt;CountryDto&amp;gt; countryPaginatedDto = 
           _mapper.Map&amp;lt;PaginatedList&amp;lt;Country&amp;gt;, PaginatedDto&amp;lt;CountryDto&amp;gt;&amp;gt;(countries);

        &lt;span style="color: blue;"&gt;return&lt;/span&gt; countryPaginatedDto;
    }
}

&lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;interface&lt;/span&gt; IPaginatedDto&amp;lt;&lt;span style="color: blue;"&gt;out&lt;/span&gt; TDto&amp;gt; &lt;span style="color: blue;"&gt;where&lt;/span&gt; TDto : IDto {

    &lt;span style="color: blue;"&gt;int&lt;/span&gt; PageIndex { &lt;span style="color: blue;"&gt;get&lt;/span&gt;; &lt;span style="color: blue;"&gt;set&lt;/span&gt;; }
    &lt;span style="color: blue;"&gt;int&lt;/span&gt; PageSize { &lt;span style="color: blue;"&gt;get&lt;/span&gt;; &lt;span style="color: blue;"&gt;set&lt;/span&gt;; }
    &lt;span style="color: blue;"&gt;int&lt;/span&gt; TotalCount { &lt;span style="color: blue;"&gt;get&lt;/span&gt;; &lt;span style="color: blue;"&gt;set&lt;/span&gt;; }
    &lt;span style="color: blue;"&gt;int&lt;/span&gt; TotalPageCount { &lt;span style="color: blue;"&gt;get&lt;/span&gt;; &lt;span style="color: blue;"&gt;set&lt;/span&gt;; }

    &lt;span style="color: blue;"&gt;bool&lt;/span&gt; HasNextPage { &lt;span style="color: blue;"&gt;get&lt;/span&gt;; &lt;span style="color: blue;"&gt;set&lt;/span&gt;; }
    &lt;span style="color: blue;"&gt;bool&lt;/span&gt; HasPreviousPage { &lt;span style="color: blue;"&gt;get&lt;/span&gt;; &lt;span style="color: blue;"&gt;set&lt;/span&gt;; }

    IEnumerable&amp;lt;TDto&amp;gt; Items { &lt;span style="color: blue;"&gt;get&lt;/span&gt;; }
}

&lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;class&lt;/span&gt; PaginatedDto&amp;lt;TDto&amp;gt; : IPaginatedDto&amp;lt;TDto&amp;gt; &lt;span style="color: blue;"&gt;where&lt;/span&gt; TDto : IDto {

    &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;int&lt;/span&gt; PageIndex { &lt;span style="color: blue;"&gt;get&lt;/span&gt;; &lt;span style="color: blue;"&gt;set&lt;/span&gt;; }
    &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;int&lt;/span&gt; PageSize { &lt;span style="color: blue;"&gt;get&lt;/span&gt;; &lt;span style="color: blue;"&gt;set&lt;/span&gt;; }
    &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;int&lt;/span&gt; TotalCount { &lt;span style="color: blue;"&gt;get&lt;/span&gt;; &lt;span style="color: blue;"&gt;set&lt;/span&gt;; }
    &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;int&lt;/span&gt; TotalPageCount { &lt;span style="color: blue;"&gt;get&lt;/span&gt;; &lt;span style="color: blue;"&gt;set&lt;/span&gt;; }

    &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;bool&lt;/span&gt; HasNextPage { &lt;span style="color: blue;"&gt;get&lt;/span&gt;; &lt;span style="color: blue;"&gt;set&lt;/span&gt;; }
    &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;bool&lt;/span&gt; HasPreviousPage { &lt;span style="color: blue;"&gt;get&lt;/span&gt;; &lt;span style="color: blue;"&gt;set&lt;/span&gt;; }

    &lt;span style="color: blue;"&gt;public&lt;/span&gt; IEnumerable&amp;lt;TDto&amp;gt; Items { &lt;span style="color: blue;"&gt;get&lt;/span&gt;; &lt;span style="color: blue;"&gt;set&lt;/span&gt;; }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Paginate method will return us the PaginatedList&amp;lt;TEntity&amp;gt; object back and we can project that into our own Dto object as you can see above. I used AutoMapper for that. If I send a request to this API endpoint and ask for response in JSON format, I get back the below result:&lt;/p&gt;
&lt;div class="code-wrapper border-shadow-1"&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;{
    &lt;span style="color: #a31515;"&gt;"PageIndex"&lt;/span&gt;:1,
    &lt;span style="color: #a31515;"&gt;"PageSize"&lt;/span&gt;:2,
    &lt;span style="color: #a31515;"&gt;"TotalCount"&lt;/span&gt;:6,
    &lt;span style="color: #a31515;"&gt;"TotalPageCount"&lt;/span&gt;:3,
    &lt;span style="color: #a31515;"&gt;"HasNextPage"&lt;/span&gt;:&lt;span style="color: blue;"&gt;true&lt;/span&gt;,
    &lt;span style="color: #a31515;"&gt;"HasPreviousPage"&lt;/span&gt;:&lt;span style="color: blue;"&gt;false&lt;/span&gt;,
    &lt;span style="color: #a31515;"&gt;"Items"&lt;/span&gt;:[
      {
        &lt;span style="color: #a31515;"&gt;"Id"&lt;/span&gt;:1,
        &lt;span style="color: #a31515;"&gt;"Name"&lt;/span&gt;:&lt;span style="color: #a31515;"&gt;"Turkey"&lt;/span&gt;,
        &lt;span style="color: #a31515;"&gt;"ISOCode"&lt;/span&gt;:&lt;span style="color: #a31515;"&gt;"TR"&lt;/span&gt;,
        &lt;span style="color: #a31515;"&gt;"CreatedOn"&lt;/span&gt;:&lt;span style="color: #a31515;"&gt;"2013-01-08T21:12:26.5854461+02:00"&lt;/span&gt;
      },
      {
        &lt;span style="color: #a31515;"&gt;"Id"&lt;/span&gt;:2,
        &lt;span style="color: #a31515;"&gt;"Name"&lt;/span&gt;:&lt;span style="color: #a31515;"&gt;"United Kingdom"&lt;/span&gt;,
        &lt;span style="color: #a31515;"&gt;"ISOCode"&lt;/span&gt;:&lt;span style="color: #a31515;"&gt;"UK"&lt;/span&gt;,
        &lt;span style="color: #a31515;"&gt;"CreatedOn"&lt;/span&gt;:&lt;span style="color: #a31515;"&gt;"2013-01-08T21:12:26.5864465+02:00"&lt;/span&gt;
      }
    ]
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Isn&amp;rsquo;t this perfect &lt;img class="wlEmoticon wlEmoticon-smile" style="border-style: none;" alt="Smile" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/8007d0fd3e72_107A4/wlEmoticon-smile.png" /&gt; There are other pagination method inside the EntityRepository implementation which supports &lt;a href="http://msdn.microsoft.com/en-us/library/gg671236%28v=vs.103%29.aspx"&gt;including child or parent entities&lt;/a&gt; and sorting. You also have the &lt;a href="https://github.com/tugberkugurlu/GenericRepository/blob/master/src/GenericRepository/QueryableExtensions.cs"&gt;ToPaginatedList&lt;/a&gt; extension method and you can build your query and call ToPaginatedList on that query to get PaginatedList&amp;lt;TEntity&amp;gt; object back.&lt;/p&gt;
&lt;h3&gt;Extending the IEntityRepository&amp;lt;TEntity&amp;gt;&lt;/h3&gt;
&lt;p&gt;In my previous blog posts, I kind of sucked at extending the generic repository. So, I wanted to show here the better approach that I have been taking for a while now. This is not a feature of my generic repository, this is the feature of .NET itself: extension methods! If you need extra methods for your specific repository, you can always extend the IEntityRepository&amp;lt;TEntity, TId&amp;gt; which gives you a better way to extend your repositories. Here is an example:&lt;/p&gt;
&lt;div class="code-wrapper border-shadow-1"&gt;
&lt;div style="color: black; background-color: white;"&gt;
&lt;pre&gt;&lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;static&lt;/span&gt; &lt;span style="color: blue;"&gt;class&lt;/span&gt; HotelRepositoryExtensions {

    &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;static&lt;/span&gt; IQueryable&amp;lt;Hotel&amp;gt; GetAllByResortId(
        &lt;span style="color: blue;"&gt;this&lt;/span&gt; IEntityRepository&amp;lt;Hotel, &lt;span style="color: blue;"&gt;int&lt;/span&gt;&amp;gt; hotelRepository, &lt;span style="color: blue;"&gt;int&lt;/span&gt; resortId) {

        &lt;span style="color: blue;"&gt;return&lt;/span&gt; hotelRepository.FindBy(x =&amp;gt; x.ResortId == resortId);
    }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h3&gt;What is Next?&lt;/h3&gt;
&lt;p&gt;My first intention is finish writing all the tests for the whole project, fix bugs and inconsistencies for the v0.3.0 release. After that release, I will work on EF6 version for my generic repository implementation which will have sweet asynchronous support. I also plan to release a generic repository implementation for MongoDB.&lt;/p&gt;
&lt;p&gt;Stay tuned, &lt;a href="http://nuget.org/packages/GenericRepository.EntityFramework"&gt;install the package&lt;/a&gt;, play with it and &lt;a href="https://github.com/tugberkugurlu/GenericRepository/issues"&gt;give feedback&lt;/a&gt;&amp;nbsp;&lt;img class="wlEmoticon wlEmoticon-winkingsmile" style="border-style: none;" alt="Winking smile" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/8007d0fd3e72_107A4/wlEmoticon-winkingsmile.png" /&gt;&lt;/p&gt;</a10:content><feedburner:origLink>http://tugberkugurlu.com/134</feedburner:origLink></item><item><guid isPermaLink="false">http://tugberkugurlu.com/133</guid><link>http://feedproxy.google.com/~r/TugberkUgurlu/~3/W7Iy7t20weI/133</link><title>Sides and Source Code for DEU Bilgisayar Topluluğu Izmir 2. Teknoloji Zirvesi</title><description>&lt;p&gt;This weekend, &lt;a href="http://www.tugberkugurlu.com/archive/deu-bilgisayar-toplulugu-izmir-2-teknoloji-zirvesi"&gt;I participated in an event as a speaker in Izmir&lt;/a&gt;. I also had the chance to meet &lt;a href="http://www.enterprisecoding.com/"&gt;Fatih Boy&lt;/a&gt;, &lt;a href="http://www.ilkayilknur.com/"&gt;İkay İlknur&lt;/a&gt;, &lt;a href="http://www.uerkal.com/"&gt;Umut Erkal&lt;/a&gt; and &lt;a href="http://www.oguzhan.info/"&gt;Oğuzhan Yılmaz&lt;/a&gt; at the event. There were great sessions throughout the first and second day.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Sides-and-Source-Code.-Teknoloji-Zirvesi_7474/A_2F067CMAA2b2F.jpg"&gt;&lt;img height="244" width="184" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Sides-and-Source-Code.-Teknoloji-Zirvesi_7474/A_2F067CMAA2b2F_thumb.jpg" alt="A_2F067CMAA2b2F" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" title="A_2F067CMAA2b2F" /&gt;&lt;/a&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Sides-and-Source-Code.-Teknoloji-Zirvesi_7474/A_2Gty6CIAAOKnf.jpg"&gt;&lt;img height="184" width="244" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Sides-and-Source-Code.-Teknoloji-Zirvesi_7474/A_2Gty6CIAAOKnf_thumb.jpg" alt="A_2Gty6CIAAOKnf" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" title="A_2Gty6CIAAOKnf" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Sides-and-Source-Code.-Teknoloji-Zirvesi_7474/A_2oQg4CcAERiYO.jpg"&gt;&lt;img height="184" width="244" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Sides-and-Source-Code.-Teknoloji-Zirvesi_7474/A_2oQg4CcAERiYO_thumb.jpg" alt="A_2oQg4CcAERiYO" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" title="A_2oQg4CcAERiYO" /&gt;&lt;/a&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Sides-and-Source-Code.-Teknoloji-Zirvesi_7474/A_2XVl7CUAEjVF9.jpg"&gt;&lt;img height="184" width="244" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Sides-and-Source-Code.-Teknoloji-Zirvesi_7474/A_2XVl7CUAEjVF9_thumb.jpg" alt="A_2XVl7CUAEjVF9" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" title="A_2XVl7CUAEjVF9" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I gave two talks during the event and one of them was on Git and GitHub. You can see the slides for that session below:&lt;/p&gt;
&lt;script class="speakerdeck-embed" data-id="4b01657038f101304ab322000a8f8805" data-ratio="1.77777777777778" src="//speakerdeck.com/assets/embed.js"&gt;&lt;/script&gt;
&lt;p&gt;At the second day, I talked about asynchronous programming for .NET server applications. Slides for that session is also available on my SpeakerDeck page. You can also get the source code for the demos: &lt;a href="https://github.com/tugberkugurlu/IzmirDEU201301ServerSideAsync" title="https://github.com/tugberkugurlu/IzmirDEU201301ServerSideAsync"&gt;https://github.com/tugberkugurlu/IzmirDEU201301ServerSideAsync&lt;/a&gt;.&lt;/p&gt;
&lt;script class="speakerdeck-embed" data-id="ca07fd403ae70130309812313d162ab5" data-ratio="1.77777777777778" src="//speakerdeck.com/assets/embed.js"&gt;&lt;/script&gt;&lt;img src="http://feeds.feedburner.com/~r/TugberkUgurlu/~4/W7Iy7t20weI" height="1" width="1"/&gt;</description><pubDate>Tue, 08 Jan 2013 06:34:00 Z</pubDate><a10:updated>2013-01-08T06:34:00Z</a10:updated><a10:content type="text">&lt;p&gt;This weekend, &lt;a href="http://www.tugberkugurlu.com/archive/deu-bilgisayar-toplulugu-izmir-2-teknoloji-zirvesi"&gt;I participated in an event as a speaker in Izmir&lt;/a&gt;. I also had the chance to meet &lt;a href="http://www.enterprisecoding.com/"&gt;Fatih Boy&lt;/a&gt;, &lt;a href="http://www.ilkayilknur.com/"&gt;İkay İlknur&lt;/a&gt;, &lt;a href="http://www.uerkal.com/"&gt;Umut Erkal&lt;/a&gt; and &lt;a href="http://www.oguzhan.info/"&gt;Oğuzhan Yılmaz&lt;/a&gt; at the event. There were great sessions throughout the first and second day.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Sides-and-Source-Code.-Teknoloji-Zirvesi_7474/A_2F067CMAA2b2F.jpg"&gt;&lt;img height="244" width="184" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Sides-and-Source-Code.-Teknoloji-Zirvesi_7474/A_2F067CMAA2b2F_thumb.jpg" alt="A_2F067CMAA2b2F" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" title="A_2F067CMAA2b2F" /&gt;&lt;/a&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Sides-and-Source-Code.-Teknoloji-Zirvesi_7474/A_2Gty6CIAAOKnf.jpg"&gt;&lt;img height="184" width="244" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Sides-and-Source-Code.-Teknoloji-Zirvesi_7474/A_2Gty6CIAAOKnf_thumb.jpg" alt="A_2Gty6CIAAOKnf" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" title="A_2Gty6CIAAOKnf" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Sides-and-Source-Code.-Teknoloji-Zirvesi_7474/A_2oQg4CcAERiYO.jpg"&gt;&lt;img height="184" width="244" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Sides-and-Source-Code.-Teknoloji-Zirvesi_7474/A_2oQg4CcAERiYO_thumb.jpg" alt="A_2oQg4CcAERiYO" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" title="A_2oQg4CcAERiYO" /&gt;&lt;/a&gt;&lt;a href="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Sides-and-Source-Code.-Teknoloji-Zirvesi_7474/A_2XVl7CUAEjVF9.jpg"&gt;&lt;img height="184" width="244" src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Sides-and-Source-Code.-Teknoloji-Zirvesi_7474/A_2XVl7CUAEjVF9_thumb.jpg" alt="A_2XVl7CUAEjVF9" border="0" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" title="A_2XVl7CUAEjVF9" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I gave two talks during the event and one of them was on Git and GitHub. You can see the slides for that session below:&lt;/p&gt;
&lt;script class="speakerdeck-embed" data-id="4b01657038f101304ab322000a8f8805" data-ratio="1.77777777777778" src="//speakerdeck.com/assets/embed.js"&gt;&lt;/script&gt;
&lt;p&gt;At the second day, I talked about asynchronous programming for .NET server applications. Slides for that session is also available on my SpeakerDeck page. You can also get the source code for the demos: &lt;a href="https://github.com/tugberkugurlu/IzmirDEU201301ServerSideAsync" title="https://github.com/tugberkugurlu/IzmirDEU201301ServerSideAsync"&gt;https://github.com/tugberkugurlu/IzmirDEU201301ServerSideAsync&lt;/a&gt;.&lt;/p&gt;
&lt;script class="speakerdeck-embed" data-id="ca07fd403ae70130309812313d162ab5" data-ratio="1.77777777777778" src="//speakerdeck.com/assets/embed.js"&gt;&lt;/script&gt;</a10:content><feedburner:origLink>http://tugberkugurlu.com/133</feedburner:origLink></item><item><guid isPermaLink="false">http://tugberkugurlu.com/132</guid><link>http://feedproxy.google.com/~r/TugberkUgurlu/~3/iqfiuSYmRSI/132</link><title>JavaScript-Heavy, Maintainable Web Applications by a n00b: 101 - Leveraging Existing Libraries</title><description>&lt;p&gt;Nearly every software developer dedicates a part of its time to improve him/herself on a particular area of expertise. Well, I dedicate this part of my life to JavaScript for a while. I have been writing JavaScript for approx. 3 years now but if anybody asks me if I know JavaScript, I tell them that I know JavaScript and I *don&amp;rsquo;t* know JavaScript at the same time. It&amp;rsquo;s probably because of the fact that I don&amp;rsquo;t get to work with it that much. One of the places I struggle most is the idea of maintaining big-ass JavaScript heavy web applications. That idea has been causing me to carry a psychic weight but now, at this very moment, I am committed to throw it away like a piece of garbage! And yes, it starts with a blog post &lt;img src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Writing_1BAF/wlEmoticon-smile.png" alt="Smile" style="border-style: none;" class="wlEmoticon wlEmoticon-smile" /&gt;&lt;/p&gt;
&lt;p&gt;A few months ago I talked to a brilliant developer about &lt;a href="http://nodejs.org/"&gt;node.js&lt;/a&gt;, the platform built on &lt;a href="http://code.google.com/p/v8/"&gt;Chrome's JavaScript runtime&lt;/a&gt; (V8) for easily building fast, scalable network applications, and asked his opinion about it. He was uncertain at the time but apparently he had more information about node.js than me. So, I expressed that I didn&amp;rsquo;t understand the need of JavaScript at the server side because it&amp;rsquo;s hard to maintain such a huge JS codebase. Then, he slapped me in the face with a follow-up sentence: "Well, the node community thinks that a big application codebase needs to be separated into small modules, components to be more maintainable". That was the nudge I needed to believe that the JavaScript codebase can be maintained.&lt;/p&gt;
&lt;p&gt;Not long time later from that moment, I then started watching &lt;a href="http://www.johnpapa.net/"&gt;John Papa&lt;/a&gt;&amp;rsquo;s &lt;a href="http://www.pluralsight.com/training/Courses/TableOfContents/spa"&gt;Single Page Apps with HTML5, Web API, Knockout and jQuery&lt;/a&gt; and I learnt lots of mind blowing stuff about JavaScript: new (at least new to me) libraries, well-known JavaScript patterns, which I had been aware of but didn&amp;rsquo;t know how to apply them most of the time, and many more. This was the start of my commitment to learn JavaScript (I mean really learning, going beyond the for loops and if statements) and I pulled out my &lt;a href="http://www.amazon.com/gp/product/0596517742/ref=as_li_ss_tl?ie=UTF8&amp;amp;tag=tugsblo0c-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596517742"&gt;JavaScript: The Good Parts&lt;/a&gt; book which I have bought in last June, but I thought that the best way to learn this stuff is to blog about it. So, here I am &lt;img src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Writing_1BAF/wlEmoticon-winkingsmile.png" alt="Winking smile" style="border-style: none;" class="wlEmoticon wlEmoticon-winkingsmile" /&gt; In this post I am listing a few JavaScript libraries which make a lot of sense to be used in nearly every web applications. I have been working with some of this libraries for a while now and I am going to be working with some of those.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://jquery.com/"&gt;JQuery&lt;/a&gt;: The JavaScript framework we all know and fell in love at the time that we have noticed it. JQuery is especially helpful for DOM manipulation and Ajax interactions. If you don&amp;rsquo;t want to install JQuery, don&amp;rsquo;t worry; you eventually will have to because I am sure that at least of the libraries you are going to use will have a dependency on it.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://knockoutjs.com/"&gt;KnockoutJS&lt;/a&gt;: KnockoutJS is one of the best things that can happen to a web developer. Starting to learn KnockoutJS gives you the equivalent feeling which you would feel at the very moment when you find a cup of hot chocolate in a freezing cold day. It enables your to have two way data-binding between your DOM elements and your view model which means when your data model's state changes, your UI updates automatically and vice versa. Check out &lt;a href="http://knockoutjs.com/documentation/introduction.html"&gt;its well-arranged documents&lt;/a&gt; and &lt;a href="http://learn.knockoutjs.com/"&gt;live tutorials&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://underscorejs.org/"&gt;Underscore.js&lt;/a&gt;: Underscore.js provides a utility suite which covers lots of useful functions. From the its official page: "&lt;em&gt;Underscore provides 80-odd functions that support both the usual functional suspects:&lt;b&gt;map&lt;/b&gt;, &lt;b&gt;select&lt;/b&gt;, &lt;b&gt;invoke&lt;/b&gt; &amp;mdash; as well as more specialized helpers: function binding, javascript templating, deep equality testing, and so on. It delegates to built-in functions, if present, so modern browsers will use the native implementations of &lt;b&gt;forEach&lt;/b&gt;, &lt;b&gt;map&lt;/b&gt;,&lt;b&gt;reduce&lt;/b&gt;, &lt;b&gt;filter&lt;/b&gt;, &lt;b&gt;every&lt;/b&gt;, &lt;b&gt;some&lt;/b&gt; and &lt;b&gt;indexOf&lt;/b&gt;&lt;/em&gt;". Don&amp;rsquo;t forget to watch &lt;a href="http://www.youtube.com/watch?v=tbt36MvV6qQ"&gt;this awesome presentation&lt;/a&gt; from &lt;a href="https://twitter.com/elijahmanor"&gt;Elijah Manor&lt;/a&gt; on Underscore.js.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://requirejs.org/"&gt;RequireJS&lt;/a&gt;: I think RequireJS is the essential piece of library which makes it possible to have maintainable, well-designed JavaScript codebase. It&amp;rsquo;s a modular script loader which enables you to write small pieces of code in separate files and handle their dependencies and load order correctly. &lt;a href="http://requirejs.org/docs/start.html"&gt;RequireJS also has a very nice documentation&lt;/a&gt; in its web site; definitely check that out.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://sammyjs.org"&gt;Sammy.js&lt;/a&gt;: Last library I am considering for my every web application is Sammy.js. It gives us a nice way to handle page navigations without refreshing the page at all by providing a nice routing mechanism. Especially, if you are writing a Single Page Applications (SPA), this is the library that you want inside your suite. Don&amp;rsquo;t skip to check out its &lt;a href="http://sammyjs.org/docs/tutorials/json_store_1"&gt;intro sample&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;There are for sure other great libraries out there (e.g. &lt;a href="http://momentjs.com/"&gt;Moment.js&lt;/a&gt;, &lt;a href="http://amplifyjs.com/"&gt;AmplifyJS&lt;/a&gt;, &lt;a href="http://jqueryui.com/"&gt;JQuery UI&lt;/a&gt;, &lt;a href="http://www.breezejs.com/"&gt;Breeze&lt;/a&gt;) but these are the ones I am in love at the moment. Go check them out and start exploring &lt;img src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Writing_1BAF/wlEmoticon-winkingsmile.png" alt="Winking smile" style="border-style: none;" class="wlEmoticon wlEmoticon-winkingsmile" /&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TugberkUgurlu/~4/iqfiuSYmRSI" height="1" width="1"/&gt;</description><pubDate>Tue, 08 Jan 2013 02:07:00 Z</pubDate><a10:updated>2013-01-08T02:07:00Z</a10:updated><a10:content type="text">&lt;p&gt;Nearly every software developer dedicates a part of its time to improve him/herself on a particular area of expertise. Well, I dedicate this part of my life to JavaScript for a while. I have been writing JavaScript for approx. 3 years now but if anybody asks me if I know JavaScript, I tell them that I know JavaScript and I *don&amp;rsquo;t* know JavaScript at the same time. It&amp;rsquo;s probably because of the fact that I don&amp;rsquo;t get to work with it that much. One of the places I struggle most is the idea of maintaining big-ass JavaScript heavy web applications. That idea has been causing me to carry a psychic weight but now, at this very moment, I am committed to throw it away like a piece of garbage! And yes, it starts with a blog post &lt;img src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Writing_1BAF/wlEmoticon-smile.png" alt="Smile" style="border-style: none;" class="wlEmoticon wlEmoticon-smile" /&gt;&lt;/p&gt;
&lt;p&gt;A few months ago I talked to a brilliant developer about &lt;a href="http://nodejs.org/"&gt;node.js&lt;/a&gt;, the platform built on &lt;a href="http://code.google.com/p/v8/"&gt;Chrome's JavaScript runtime&lt;/a&gt; (V8) for easily building fast, scalable network applications, and asked his opinion about it. He was uncertain at the time but apparently he had more information about node.js than me. So, I expressed that I didn&amp;rsquo;t understand the need of JavaScript at the server side because it&amp;rsquo;s hard to maintain such a huge JS codebase. Then, he slapped me in the face with a follow-up sentence: "Well, the node community thinks that a big application codebase needs to be separated into small modules, components to be more maintainable". That was the nudge I needed to believe that the JavaScript codebase can be maintained.&lt;/p&gt;
&lt;p&gt;Not long time later from that moment, I then started watching &lt;a href="http://www.johnpapa.net/"&gt;John Papa&lt;/a&gt;&amp;rsquo;s &lt;a href="http://www.pluralsight.com/training/Courses/TableOfContents/spa"&gt;Single Page Apps with HTML5, Web API, Knockout and jQuery&lt;/a&gt; and I learnt lots of mind blowing stuff about JavaScript: new (at least new to me) libraries, well-known JavaScript patterns, which I had been aware of but didn&amp;rsquo;t know how to apply them most of the time, and many more. This was the start of my commitment to learn JavaScript (I mean really learning, going beyond the for loops and if statements) and I pulled out my &lt;a href="http://www.amazon.com/gp/product/0596517742/ref=as_li_ss_tl?ie=UTF8&amp;amp;tag=tugsblo0c-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596517742"&gt;JavaScript: The Good Parts&lt;/a&gt; book which I have bought in last June, but I thought that the best way to learn this stuff is to blog about it. So, here I am &lt;img src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Writing_1BAF/wlEmoticon-winkingsmile.png" alt="Winking smile" style="border-style: none;" class="wlEmoticon wlEmoticon-winkingsmile" /&gt; In this post I am listing a few JavaScript libraries which make a lot of sense to be used in nearly every web applications. I have been working with some of this libraries for a while now and I am going to be working with some of those.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://jquery.com/"&gt;JQuery&lt;/a&gt;: The JavaScript framework we all know and fell in love at the time that we have noticed it. JQuery is especially helpful for DOM manipulation and Ajax interactions. If you don&amp;rsquo;t want to install JQuery, don&amp;rsquo;t worry; you eventually will have to because I am sure that at least of the libraries you are going to use will have a dependency on it.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://knockoutjs.com/"&gt;KnockoutJS&lt;/a&gt;: KnockoutJS is one of the best things that can happen to a web developer. Starting to learn KnockoutJS gives you the equivalent feeling which you would feel at the very moment when you find a cup of hot chocolate in a freezing cold day. It enables your to have two way data-binding between your DOM elements and your view model which means when your data model's state changes, your UI updates automatically and vice versa. Check out &lt;a href="http://knockoutjs.com/documentation/introduction.html"&gt;its well-arranged documents&lt;/a&gt; and &lt;a href="http://learn.knockoutjs.com/"&gt;live tutorials&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://underscorejs.org/"&gt;Underscore.js&lt;/a&gt;: Underscore.js provides a utility suite which covers lots of useful functions. From the its official page: "&lt;em&gt;Underscore provides 80-odd functions that support both the usual functional suspects:&lt;b&gt;map&lt;/b&gt;, &lt;b&gt;select&lt;/b&gt;, &lt;b&gt;invoke&lt;/b&gt; &amp;mdash; as well as more specialized helpers: function binding, javascript templating, deep equality testing, and so on. It delegates to built-in functions, if present, so modern browsers will use the native implementations of &lt;b&gt;forEach&lt;/b&gt;, &lt;b&gt;map&lt;/b&gt;,&lt;b&gt;reduce&lt;/b&gt;, &lt;b&gt;filter&lt;/b&gt;, &lt;b&gt;every&lt;/b&gt;, &lt;b&gt;some&lt;/b&gt; and &lt;b&gt;indexOf&lt;/b&gt;&lt;/em&gt;". Don&amp;rsquo;t forget to watch &lt;a href="http://www.youtube.com/watch?v=tbt36MvV6qQ"&gt;this awesome presentation&lt;/a&gt; from &lt;a href="https://twitter.com/elijahmanor"&gt;Elijah Manor&lt;/a&gt; on Underscore.js.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://requirejs.org/"&gt;RequireJS&lt;/a&gt;: I think RequireJS is the essential piece of library which makes it possible to have maintainable, well-designed JavaScript codebase. It&amp;rsquo;s a modular script loader which enables you to write small pieces of code in separate files and handle their dependencies and load order correctly. &lt;a href="http://requirejs.org/docs/start.html"&gt;RequireJS also has a very nice documentation&lt;/a&gt; in its web site; definitely check that out.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://sammyjs.org"&gt;Sammy.js&lt;/a&gt;: Last library I am considering for my every web application is Sammy.js. It gives us a nice way to handle page navigations without refreshing the page at all by providing a nice routing mechanism. Especially, if you are writing a Single Page Applications (SPA), this is the library that you want inside your suite. Don&amp;rsquo;t skip to check out its &lt;a href="http://sammyjs.org/docs/tutorials/json_store_1"&gt;intro sample&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;There are for sure other great libraries out there (e.g. &lt;a href="http://momentjs.com/"&gt;Moment.js&lt;/a&gt;, &lt;a href="http://amplifyjs.com/"&gt;AmplifyJS&lt;/a&gt;, &lt;a href="http://jqueryui.com/"&gt;JQuery UI&lt;/a&gt;, &lt;a href="http://www.breezejs.com/"&gt;Breeze&lt;/a&gt;) but these are the ones I am in love at the moment. Go check them out and start exploring &lt;img src="http://www.tugberkugurlu.com/Content/images/Uploadedbyauthors/wlw/Writing_1BAF/wlEmoticon-winkingsmile.png" alt="Winking smile" style="border-style: none;" class="wlEmoticon wlEmoticon-winkingsmile" /&gt;&lt;/p&gt;</a10:content><feedburner:origLink>http://tugberkugurlu.com/132</feedburner:origLink></item></channel></rss>
