<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ivan Porto Carrero &#187; .NET 3.5</title>
	<atom:link href="http://flanders.co.nz/category/net35/feed/" rel="self" type="application/rss+xml" />
	<link>http://flanders.co.nz</link>
	<description>thoughts.each { &#38;:propagandise }</description>
	<lastBuildDate>Fri, 12 Mar 2010 12:24:55 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Ruby </title>
		<link>http://flanders.co.nz/2009/02/05/ruby/</link>
		<comments>http://flanders.co.nz/2009/02/05/ruby/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 07:00:19 +0000</pubDate>
		<dc:creator>Ivan Porto Carrero</dc:creator>
				<category><![CDATA[.NET 3.5]]></category>
		<category><![CDATA[IronRuby]]></category>
		<category><![CDATA[Presentations]]></category>

		<guid isPermaLink="false">http://flanders.co.nz/2009/02/05/ruby/</guid>
		<description><![CDATA[2 weeks ago I had the chance to [talk to the Italian Alt.NET community about IronRuby](http://flanders.co.nz/2009/01/25/participating-in-the-italian-altnet-user-group/). I&#8217;m pretty excited about the Ruby language and I try to convey that enthusiasm onto my victims. From the talks I had afterwards it looks like I was able to infect at least one or two enough to make [...]]]></description>
			<content:encoded><![CDATA[<p>2 weeks ago I had the chance to [talk to the Italian Alt.NET community about IronRuby](http://flanders.co.nz/2009/01/25/participating-in-the-italian-altnet-user-group/). I&#8217;m pretty excited about the Ruby language and I try to convey that enthusiasm onto my victims. From the talks I had afterwards it looks like I was able to infect at least one or two enough to make them go home and download IronRuby to have a play. It is the very first time that I get to see one of my presentations myself because this one got taped and put online.</p>
<p><span id="more-299"></span><br />
If there is one thing that watching this video has taught me then it will probably be that I need more practice and to prepare a lot better. Since I&#8217;m a kid I have the habit of walking into things hugely underprepared. I take the big bullet points of what I&#8217;m supposed to say and make a story around it when I start talking.  It was my belief that those things feel more natural. After having watched this presentation I may have to come back on my point of view and probably prepare better. I don&#8217;t believe that learning everything you&#8217;re going to say by heart is a good solution either because if you then forget one thing you&#8217;re completely lost in your storyline and you may freeze.</p>
<p>I guess it would probably be a good idea for me to get a video camera and tape a few practice runs of presentations so that I can improve and look way more professional next time I get on a stage.  That being said I really enjoy doing those things. The good thing about doing those sessions is that I get to talk to many interesting people about subjects close and dear to me. </p>
<p>Anyway you&#8217;re probably not waiting for me to completely dissect my performance so instead I&#8217;ll leave you with the [link to the video](http://vimeo.com/3059773)</p>
]]></content:encoded>
			<wfw:commentRss>http://flanders.co.nz/2009/02/05/ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Created a basic integration for IronRuby and Asp.NET MVC</title>
		<link>http://flanders.co.nz/2009/01/25/created-a-basic-integration-for-ironruby-and-aspnet-mvc/</link>
		<comments>http://flanders.co.nz/2009/01/25/created-a-basic-integration-for-ironruby-and-aspnet-mvc/#comments</comments>
		<pubDate>Sun, 25 Jan 2009 12:42:13 +0000</pubDate>
		<dc:creator>Ivan Porto Carrero</dc:creator>
				<category><![CDATA[.NET 3.5]]></category>
		<category><![CDATA[IronRuby]]></category>

		<guid isPermaLink="false">http://flanders.co.nz/2009/01/25/created-a-basic-integration-for-ironruby-and-aspnet-mvc/</guid>
		<description><![CDATA[As I can see the end of the chapter on Rails and I&#8217;m looking ahead to see what will be next. I decided to start working on the chapter that talks about using IronRuby with Asp.NET MVC next.  [Jimmy Schementi](http://blog.jimmy.schementi.com/) and [Phil Haack](http://haacked.com/) created a proof of concept implementation a couple of months ago [...]]]></description>
			<content:encoded><![CDATA[<p>As I can see the end of the chapter on Rails and I&#8217;m looking ahead to see what will be next. I decided to start working on the chapter that talks about using IronRuby with Asp.NET MVC next.  [Jimmy Schementi](http://blog.jimmy.schementi.com/) and [Phil Haack](http://haacked.com/) created a proof of concept implementation a couple of months ago that actually did work.<br />
The past weekend I&#8217;ve been looking to build on the excellent work they did and to build a more complete integration. In this post I&#8217;ll try to explain what I did to make it work.  The integration work is far from complete, so if you&#8217;ve got some free time on your hands and you happen to be looking for an Open Source project to help with then this could be a candidate for you <img src='http://flanders.co.nz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p><span id="more-297"></span><br />
### Finding a place to start<br />
Let me start off by saying that I&#8217;m pretty happy with the internals of the asp.net mvc framework. The code was easy to read given that you start in the correct file and work your way through much in the same way a request would be executed. In my case I started at the MVC handler and immediately you see one of the classes that we&#8217;ll definitely need to customize. The _RubyControllerFactory_ is the class in question and it needs to be customized because we&#8217;re going to use a _RubyController_.<br />
ASP.NET MVC internally uses reflection to do its magic. In the futures project they have a couple of other implementations like async with reflection and so on. I decided to use the classes prefixed as Reflected as my guide for creating my own integration they were probably the simplest implementation of the class.<br />
I kept the view engine Jimmy and Phil created and focussed on the controllers. Working with the DLR API&#8217;s requires a bunch of classes and </p>
<p>### Sweet now what does this mean in terms of IronRuby integration?<br />
To limit some of the work I needed to be doing I decided that Ruby controller actions don&#8217;t take any parameters we can bind to instead you will have to rely on the data that&#8217;s available in the params hash to get to the input delivered by the request. Actually I made a decision to keep that from the POC implementation before.<br />
In ASP.NET MVC there is a _ReflectedControllerDescriptor_ and a _ReflectedActionDescriptor_. They are used to cache the information we need so it only has to perform the costly operations once, which is a good strategy IMHO.<br />
For IronRuby that means we&#8217;ll need to create a _RubyControllerDescriptor_ and _RubyActionDescriptor_. The last class we&#8217;ll going to need to customize in this exercise is the _ControllerActionInvoker_ which as the name hints at: invokes actions on your controller <img src='http://flanders.co.nz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
For people that have been doing rails applications, you&#8217;re not limited to Rails now. You could use Ruby but leverage the ASP.NET MVC infrastructure for implementing a mvc web app. When somebody would create the adapters for activerecord to leverage ADO.NET to talk to data sources you should be able to just use active record that comes with the rails framework in your app as models. The view engine in ironrubymvc is also erb based so I&#8217;d imagine you would be able to just copy your view code in and making sure that you have replacement helpers if you&#8217;ve used helpers.<br />
Working on this code also opens up the question if it isn&#8217;t possible to actually run rails via a similar mechanism&#8230; mmm must investigate </p>
<p>### Where can I find it?<br />
I forked the git repository from [Jimmy Schementi](http://github.com/jschementi/ironrubymvc). And I do send him pull requests when I&#8217;ve pushed some changes. So you could potentially pick that repository to work out of. The disadvantage is that you won&#8217;t pick up changes I make immediately. The good thing is that Jimmy&#8217;s repo is probably a good place to follow because he can also take work that Phil did and add it to the repo. I will then have to sync my version with his.<br />
Or you could use [my repo](http://github.com/casualjim/ironrubymvc) and pick up the changes I make immediately but you&#8217;ll have to wait to merge it with the changes that have been applied into Jimmy&#8217;s repo until I get around to merging that into mine.<br />
I&#8217;d say that over time it would probably be a better idea to get the repo from Jimmy while mine will be very active but just for a short period of time, when I&#8217;m happy with it I&#8217;ll move on. </p>
<p>### What&#8217;s left to do?</p>
<ul>
<li>Implement action filters (before/after)</li>
<li>Implement authorization filters</li>
<li>Implement an HttpApplicationBase class that will create the script runtime</li>
<li>Implement a HttpModule that will take care of creating a RubyEngine object</li>
<li>&#8230;</li>
</ul>
<p>For today I&#8217;d say **_go\_to(&#8220;http://github.com/casualjim/ironrubymvc&#8221;).play.create.have\_fun_**</p>
<p>When my work stabilizes a little bit more I&#8217;ll write a blog post explaining how I went about using the DLR hosting API&#8217;s to host IronRuby in an ASP.NET application and how the implemenation of IronRubyMvc was put together.</p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fflanders.co.nz%2f2009%2f01%2f25%2fcreated-a-basic-integration-for-ironruby-and-aspnet-mvc%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fflanders.co.nz%2f2009%2f01%2f25%2fcreated-a-basic-integration-for-ironruby-and-aspnet-mvc%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://flanders.co.nz/2009/01/25/created-a-basic-integration-for-ironruby-and-aspnet-mvc/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Participating in the Italian Alt.NET user group</title>
		<link>http://flanders.co.nz/2009/01/25/participating-in-the-italian-altnet-user-group/</link>
		<comments>http://flanders.co.nz/2009/01/25/participating-in-the-italian-altnet-user-group/#comments</comments>
		<pubDate>Sun, 25 Jan 2009 10:42:13 +0000</pubDate>
		<dc:creator>Ivan Porto Carrero</dc:creator>
				<category><![CDATA[.NET 3.5]]></category>
		<category><![CDATA[IronRuby]]></category>
		<category><![CDATA[Presentations]]></category>
		<category><![CDATA[User group]]></category>
		<category><![CDATA[Alt.NET]]></category>
		<category><![CDATA[Presentation]]></category>

		<guid isPermaLink="false">http://flanders.co.nz/2009/01/25/participating-in-the-italian-altnet-user-group-2/</guid>
		<description><![CDATA[I just finished my talk at the Italian [Alt.NET conference](http://ugialt.net).
There were the following topics of discussion:

Domain Driven Design
User stories &#38; planning game
Advanced Unit Testing in the real world
Acceptance testing (Fitness)

And of course my topic was [IronRuby](http://ironruby.net)

Because of the level of my italian or better yet the lack thereof I couldn&#8217;t participate in many of the [...]]]></description>
			<content:encoded><![CDATA[<p>I just finished my talk at the Italian [Alt.NET conference](http://ugialt.net).<br />
There were the following topics of discussion:</p>
<ul>
<li>Domain Driven Design</li>
<li>User stories &amp; planning game</li>
<li>Advanced Unit Testing in the real world</li>
<li>Acceptance testing (Fitness)</li>
</ul>
<p>And of course my topic was [IronRuby](http://ironruby.net)</p>
<p><span id="more-294"></span><br />
Because of the level of my italian or better yet the lack thereof I couldn&#8217;t participate in many of the discussions. IMHO that was a pitty because I actually do like having discussions about programming and designing applications.</p>
<p>My talk went alright judging by the reactions of the people that listened to my talk. [Simone](http://codeclimber.net.nz) filmed the whole day and told me he would put up the videos on vimeo for all to see.<br />
What I thought was particularly good for IronRuby is that there definitely interest in for using IronRuby. The most obvious places for people to start using ruby are RSpec (when it works OTB) and rake as a replacement for nant or msbuild scripts.  Of course if you ask me then there are plenty of other reasons to use IronRuby like Silverlight and WPF.</p>
<p>For the people that are interested in my presentation you can download it from [google code](http://ugialtnet3.googlecode.com/svn/trunk/ironruby/Ruby_loves_dotNet.pptx). Most of the code that I&#8217;ve showed is included in the presentation as notes.<br />
All in all I had a great time and I hope the italian community will invite me again some time <img src='http://flanders.co.nz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . Italy has the benefit that they have great food and wine and that makes it very easy to convince me to take the plane <img src='http://flanders.co.nz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I couldn&#8217;t show everything because I got carried away at one point and lost track of time. So I had to drop my demo&#8217;s about using bacon (as a replacement for RSpec) to start writing specs for your .NET code today. I also wanted to show some of the stuff [Jimmy Schementi](http://blog.jimmy.schementi.com/) did with [Silverlight](http://silverlight.net) and [IronRuby](http://ironruby.net). Like [agdlr](http://github.com/jschementi/agdlr) and the integration for [Ruby on Rails](http://rubyonrails.org) he created with the [silverline plugin](http://github.com/jschementi/silverline).  But unfortunately I ran out of time before I could show off some of those things.</p>
<p>I had the opportunity to talk to the Italian member of the Mono team, [Massimiliano Mantione](http://primates.ximian.com/~massi/blog/). And this is what I love about conferences, they are full of interesting people with all kind of ideas. When I go to an event like TechEd or something I generally don&#8217;t actually attend many sessions because most of that content is available online anyway. Instead I will roam the hallways etc in search of good conversations and intersting people.  Meeting the member of the mono team made me slightly envious because he&#8217;s doing what I would love to be doing too <img src='http://flanders.co.nz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  He&#8217;s working from home and getting paid to work on FOSS. He mentioned some intersting stuff the mono guys are doing and explained from a high level how they got the C# eval to work.</p>
<p>Some other notable facts about how they did the conference, which I liked a lot. The conference is free to attend, but they did have the possibility to accept donations. It were those donations that paid for my flight over here <img src='http://flanders.co.nz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . The way they organized the conference was in an Open Spaces format which is very open for discussion and they were completely transparent as to how the money had been spent. They still had some money left and donated that to an open source project. The open source project was chosen through voting.</p>
<p>The open source projects on the list of possibilities were:</p>
<ul>
<li>[Castle/Monorail](http://castleproject.org)</li>
<li>[Rhino.Mocks](http://ayende.com/projects/rhino-mocks.aspx)</li>
<li>[Ninject](http://ninject.org)</li>
<li>[Spark View Engine](http://dev.dejardin.org/)</li>
<li>[MbUnit/Gallio](http://www.gallio.org/)</li>
</ul>
<p>In the end it was Rhino.Mocks that won the vote and they have received the donation.</p>
<p>I would like to thank the organizers of the conference for having me and the people that followed my talk for not falling asleep.</p>
]]></content:encoded>
			<wfw:commentRss>http://flanders.co.nz/2009/01/25/participating-in-the-italian-altnet-user-group/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Beating a dead horse: Stored Procedures</title>
		<link>http://flanders.co.nz/2008/10/23/beating-a-dead-horse-stored-procedures/</link>
		<comments>http://flanders.co.nz/2008/10/23/beating-a-dead-horse-stored-procedures/#comments</comments>
		<pubDate>Thu, 23 Oct 2008 18:37:23 +0000</pubDate>
		<dc:creator>Ivan Porto Carrero</dc:creator>
				<category><![CDATA[.NET 2.0]]></category>
		<category><![CDATA[.NET 3.0]]></category>
		<category><![CDATA[.NET 3.5]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[stored procedure]]></category>

		<guid isPermaLink="false">http://flanders.co.nz/2008/10/23/beating-a-dead-horse-stored-procedures/</guid>
		<description><![CDATA[I seem to be having the same conversations with the dev teams whenever I switch clients. The topic of this post is one that many people have written about before. I&#8217;m just going to put my opinion on my blog so I can refer people to it in the future instead of having to repeat [...]]]></description>
			<content:encoded><![CDATA[<p>I seem to be having the same conversations with the dev teams whenever I switch clients. The topic of this post is one that many people have written about before. I&#8217;m just going to put my opinion on my blog so I can refer people to it in the future instead of having to repeat myself every time.<br />
What prompted this post is that since I&#8217;ve moved to Belgium I&#8217;ve had to take a step back from living on the bleeding edge and using open source projects. Most of the work is concentrated in Brussels and is at big corporates or banks not exactly what you&#8217;d see as the progressive thinkers (with reason).<br />
I guess it would be safe to say that I&#8217;ve been immersed in &#8220;enterprise&#8221; development. In short I still haven&#8217;t seen anything that is more complicated than a web app like [Xero](http://www.xero.com). But perhaps more about that in another post. This one is about stored procedures and their valid uses.</p>
<p><span id="more-260"></span><br />
My current client is pretty interested in the newer technologies (anything that is out of beta) and how to put them into production.  As such they use LINQ as their data layer. They follow the classic MS guidance of data logic, business logic and &#8211; the trigger for this post &#8211; stored procedures to encapsulate all the data access.<br />
People that have worked with me in the past will be able to vouch for the fact that I feel strongly against stored procedures. But before we get to why I don&#8217;t want to use them, let&#8217;s look at some of the reasons people have given me in the past why they were using them.</p>
<p>* Performance. Because stored procedures are (pre)compiled<br />
* Security. They can lock down tables from being accessed by users directly but they can get to the database through the stored procedures layer<br />
* Maintenance. You can change a stored procedure more easily than deploying a new build of your application because no compilation is needed.<br />
* Less data to send over the wire because stored procedures can execute more sql statements at once.</p>
<p>All of that stuff sounds pretty great right? As I&#8217;ve said before my current client has developed their data layer in their framework using Linq2Sql. I think Linq2Sql is not too bad, at least it gets the corporates into an ORM mindset because it comes from MS which makes it a vastly easier technology to sell than NHibernate for example.<br />
But when you&#8217;re going to use Linq in conjunction with stored procedures for basic CRUD operations I think you&#8217;re kind of missing the whole point of Linq2Sql or ORM&#8217;s altogether for that matter. So there you have it, this is why I cannot resist posting about this subject although many people have said pretty much the same as I&#8217;m going to say in this post.</p>
<p>###Credit where credit is due<br />
The list of people below have helped me in forming my opinion on this subject. I&#8217;ve had the pleasure of having lengthy discussion on this topic with the first 3 people on the list. I consider the people on this list to be authorities in .NET development and 4 of them have written their own ORM in the past. Alex James and Andrew Peters now both work on the Entity Framework team.<br />
* [Alex James](http://blogs.msdn.com/alexj)<br />
* [Andrew Peters](http://andrewpeters.net)<br />
* [Jeremy Boyd](http://turtle.net.nz)<br />
* [Frans Bouma](http://weblogs.asp.net/fbouma)<br />
* [Ayende (Oren Eini)](http://ayende.com/Blog)<br />
* [Jeremy D. Miller](http://codebetter.com/jmiller)<br />
* [Jeff Atwood](http://codinghorror.com)</p>
<p>Let&#8217;s look at the reasons mentioned above and work our way through them seeing how they pan out in the end and you can draw your own conclusions on the matter.</p>
<p>###Performance<br />
####Stored procedures are precompiled<br />
The fact that stored procedures are precompiled and dynamic queries aren&#8217;t is a complete myth. Ever since Sql Server 7.0 the query plans are cached for both of them. If you change a parameter in a stored procedure it has to be recompiled too.You can check the Sql documentation to verify that.<br />
IMHO this also falls in the category premature optimizations. It could be that you have a query that is so complex or that is a real bottleneck for your application then it might be worth it to invest the time and write a stored procedure for it that queries the database differently and as such get rid of the bottle neck but take on a higher maintenance cost.<br />
####Batching of queries and returning multiple result sets<br />
Another argument people often bring to the table is that in a stored procedure I can issue many sql statements on the same database connection. I hate to break the news to you but you get the same benefits when you&#8217;re using dynamic sql (preferably the parameterized kind). You could issue one command that returns multiple result sets just like the body of your stored procedure. Or you could issue more than one command on the same connection and still get a very similar result.</p>
<p>###Security<br />
####Sql Injection attacks<br />
Another argument I keep hearing is the fact that when you build dynamic sql statements you open yourself up for sql injection attacks which isn&#8217;t that case for stored procedures.<br />
There is some truth in that but it definitely isn&#8217;t the whole truth. What they mean by that is that if you&#8217;re going to build your dynamic query by concatenating strings then you could indeed open yourself up to a sql injection attack but I&#8217;ve seen this happen in stored procedures too it&#8217;s just a little bit harder to do it there.<br />
However if you build your sql statement by using a parameterized query you get the same security benefits as a stored procedure would give you.</p>
<p>####Different permissions on tables and stored procedures<br />
This isn&#8217;t such a big problem. I&#8217;ve mostly seen people use one dedicated user to access the database. Lots of times there is a SOA like architecture that allows the client application to not even know what type of database it&#8217;s connecting too.  I haven&#8217;t seen many places yet where they actually implement security that is that strict.<br />
So the reasoning goes if you secure your application properly then this shouldn&#8217;t be a big problem.<br />
Ayende has a more elaborate post on the subject: [Stored Procedures for Security](http://ayende.com/Blog/archive/2006/04/05/StoredProceduresForSecurity.aspx)</p>
<p>###Maintenance<br />
This is probably a very ambiguous problem. From a development point of view this might probably be the worst argument in favor for stored procedures. However if you look at it from the POV of the enterprise it might actually hold some value.<br />
At my current client all the applications have to be distributed by a separate team, and that makes the deployment a costly scenario.<br />
That is because once your application goes into production and something small needs to change the deployment team has to go around and deploy that application again on every workstation in the company. I know about click-once but nobody has any rights to install anything on their pc which makes that pretty hard to do.<br />
Now from my POV this is the most invalid argument of all of them because of the maintenance overhead it adds.<br />
When you give stored procs to a developer they see shiny quick shortcuts to quickly get some data out and perhaps already transform some of that data in their query. That is all good the first time you have to deploy the application. But the next person needs to add a column to a table and suddenly he will have to go through all the stored procedures (at least 3 of them for the C,R and D of CRUD) to add the column. Then he has to go in the data layer of your n-tiered application and modify the entity and perhaps the methods that map to the stored procedures.  Then comes time to deploy and you forgot to modify your update script with that one column you added to a stored proc. Of course this stored proc is the one that saves one of the core entities of your application and suddenly the new release is throwing errors all over the place.<br />
I skipped the part of transforming some data. As [my previous post](http://flanders.co.nz) suggests: that stuff is business logic and doesn&#8217;t belong in a stored procedure.</p>
<p>###Some more reading on the subject<br />
* Jeff Atwood claiming that T-SQL is the assembly language of contemporary development.</p>
<p>[Who Needs Stored Procedures, Anyways?](http://www.codinghorror.com/blog/archives/000117.html)<br />
* Frans Bouma explaining his point of view:</p>
<p>[Stored procedures are bad, m'kay?](http://weblogs.asp.net/fbouma/archive/2003/11/18/38178.aspx)<br />
* Jeremy Miller swearing this is really going to be his last post on stored procedures:</p>
<p>[Why I do not use Stored Procedures](http://codebetter.com/blogs/jeremy.miller/archive/2006/05/25/145450.aspx)</p>
]]></content:encoded>
			<wfw:commentRss>http://flanders.co.nz/2008/10/23/beating-a-dead-horse-stored-procedures/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Common mistakes in software development (part 2): Mixing up the tiers</title>
		<link>http://flanders.co.nz/2008/10/01/common-mistakes-in-software-development-part-2-mixing-up-the-tiers/</link>
		<comments>http://flanders.co.nz/2008/10/01/common-mistakes-in-software-development-part-2-mixing-up-the-tiers/#comments</comments>
		<pubDate>Wed, 01 Oct 2008 04:10:54 +0000</pubDate>
		<dc:creator>Ivan Porto Carrero</dc:creator>
				<category><![CDATA[.NET 2.0]]></category>
		<category><![CDATA[.NET 3.0]]></category>
		<category><![CDATA[.NET 3.5]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[n-tier]]></category>

		<guid isPermaLink="false">http://flanders.co.nz/2008/10/01/common-mistakes-in-software-development-part-2-mixing-up-the-tiers/</guid>
		<description><![CDATA[In my [previous post](http://flanders.co.nz/2008/09/24/common-mistakes-in-software-development/) I explained some very quick wins to make your code a little bit cleaner. As I&#8217;ve been appointed an [asp.net](http://www.asp.net) project at work at the moment I have the chance to get more ammunition for blogging  .
This time I&#8217;d like to talk about properly separating your tiers so that the [...]]]></description>
			<content:encoded><![CDATA[<p>In my [previous post](http://flanders.co.nz/2008/09/24/common-mistakes-in-software-development/) I explained some very quick wins to make your code a little bit cleaner. As I&#8217;ve been appointed an [asp.net](http://www.asp.net) project at work at the moment I have the chance to get more ammunition for blogging <img src='http://flanders.co.nz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .<br />
This time I&#8217;d like to talk about properly separating your tiers so that the next person doesn&#8217;t have to go through the complete application and make changes everywhere just to make a minor change to the application.</p>
<p>One  of the problems; one of the most time consuming that is; I&#8217;ve seen is that people are confused on what they have to put in the data logic layer and what is business logic. In my case this is fairly extreme because there isn&#8217;t an ORM tool but rather every entity gets populated by calling a stored procedure and then in the code the graph objects get set. Whether this is a good approach for fetching your data or not is not within the scope of this blog post, but I&#8217;m guessing there are more people who are facing this type of situation.</p>
<p>Anyway let&#8217;s start with the beginning and explain the typical [n-tier architecture](http://en.wikipedia.org/wiki/N-tier) people seem to follow. This is not a particular pattern like [MVC](http://en.wikipedia.org/wiki/Model-view-controller) or [MVP](http://en.wikipedia.org/wiki/Model-view-presenter) that people are talking about so much lately. This goes back to the guidance that can be found on the [msdn website](http://msdn.microsoft.com).  This type of architecture is often used in combination with data sets but not in my example for this post. This architecture is generally divided in 3 parts that can, but don&#8217;t have to, run on different machines if needs be.  When talking about this type of architecture people mostly talk about an n-tier application.</p>
<p>##The first part is the data layer (tier).<br />
The golden rule for this one: this is the gateway between the rest of your application and the database. **NONE** of the other layers should be talking directly to the database but instead should be doing their talking through this layer.  That means if you have stored procedures you provide wrappers for them in this layer. You populate your entities in this layer too.<br />
Other functions you can perform in this layer is setting the graph members (populating relationships). IMHO if you&#8217;re talking to the database (open/close connection) you&#8217;re doing stuff that belongs in the data layer which includes populating relationships.</p>
<p>Encapsulating this logic in it&#8217;s own layer, which could potentially be walled off through only exposing it with remoting or WCF, allows you to reuse the code in different places of your applications or sharing this data access assembly with multiple applications.</p>
<p>##The second part is the business logic layer (tier).<br />
This layer encapsulates all the operations you do on entities to express the business rules. That means you would probably do most of your work in this layer. Basically **all** of the programming you will be doing for the business rules should be done here. Business logic doesn&#8217;t live in stored procedures, it doesn&#8217;t live in the UI or the data layer. Nope this layer is where it lives and nowhere else.  This statement may raise some eyebrows but only and only when you find that a certain routine is a bottleneck and it is really data intensive you can put it in a stored procedure but more on that subject in another blog post.<br />
If you find yourself transforming data so you can display it in your GUI then you&#8217;re probably expressing business rules that aren&#8217;t explicitly stated as a business rule.<br />
When you find yourself to be concatenating strings or writing logic to translate your pages in your GUI layer then you&#8217;re probably expressing business logic (business logic doesn&#8217;t have to come from business <img src='http://flanders.co.nz/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  in case that wasn&#8217;t clear).<br />
Another common find in business logic is validation for example because this generally expresses some kind of strict rule that comes from the business domain your application deals with. Validation is a tricky one but the rule is you should do **all** validation in your business logic. To provide a better user experience you can maybe reuse that validation on the client side. In the case of web development you probably will have to duplicate that validation in javascript if you really need it.</p>
<p>Separating these rules into their own layer allows you to reuse the methods and classes you create in the business logic layer, in different parts of your UI or even reuse it in different applications.<br />
By separating this logic it should be easier for you to do some automated testing like unit testing and/or integration testing of that code.</p>
<p>##The third and last layer (tier)<br />
This is typically the UI layer but you could easily use web/WCF services as an interface to your logic. The UI doesn&#8217;t have to be a GUI it can also be a CLI (Command-Line Interface) or something. But that is how you interact with the user or external application. The idea is that in this layer you have virtually no logic except for what&#8217;s on the screen **everything** else should be handled by your business logic. To clarify this statement: you can show/hide UI elements or add/remove elements to the UI and respond to events triggered by user actions but the data of that response and the processing really belongs in the business logic layer.</p>
<p>The UI layer can talk to both the business logic and data logic layers. If for example you&#8217;re getting a category list with just an id and name from the database chances are you won&#8217;t need to transform that data so your UI can bind directly to the entities returned by your data layer. But more complex items like an invoice for example will probably need some processing and then it should probably pass through the business logic layer.</p>
<p>This is typically a somewhat harder part of your application to provide tests for although there are some libraries out there that make it easier but still there are easier parts to test in your application.</p>
<p>So that was a quick refresher on what the classic n-tier architecture is about an how it should be structured. I hope you will agree with me into stating that its not that hard and pretty straight-forward to implement, but what I find in the &#8220;enterprise&#8221; is far from the points mentioned above.<br />
It is a bloody mix of everything everywhere, leaving me thinking -come on guys it&#8217;s not that hard-:<br />
*talking to the database =&gt; datalayer*<br />
*showing windows/adding UI elements,&#8230; =&gt; UI layer*<br />
*everything else =&gt; business logic*</p>
<p>Failing to abide by the previous simple rules will result in hell freezing over, entire plagues will be released upon the world; to cut a long story short: the world as you know it will seize to exist and turn into complete chaos.<br />
Following the rules should result in less code duplication, an instantaneously easier to maintain codebase and probably more happy successors for when you move on to the next project.  It should also give you a higher degree of code reuse.<br />
If there is one thing you should take away from this article then it should be:<br />
**Don&#8217;t mix your tiers**</p>
<p>Of course there are a couple of situations when you can diverge from the ideas presented in this post but you should always be able to justify why you break the rule. So you need a good reason to break the proposed architecture and that would probably also warrant a comment so the next guy also knows what&#8217;s going on.<br />
The most important part is to separate all non-UI logic out from the UI layer and put it in one of the lower layers.</p>
<p>Thanks for reading<br />
Ivan &#8211; writing for more maintainable software -</p>
]]></content:encoded>
			<wfw:commentRss>http://flanders.co.nz/2008/10/01/common-mistakes-in-software-development-part-2-mixing-up-the-tiers/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Common mistakes in software development</title>
		<link>http://flanders.co.nz/2008/09/24/common-mistakes-in-software-development/</link>
		<comments>http://flanders.co.nz/2008/09/24/common-mistakes-in-software-development/#comments</comments>
		<pubDate>Wed, 24 Sep 2008 10:31:44 +0000</pubDate>
		<dc:creator>Ivan Porto Carrero</dc:creator>
				<category><![CDATA[.NET 2.0]]></category>
		<category><![CDATA[.NET 3.0]]></category>
		<category><![CDATA[.NET 3.5]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://flanders.co.nz/?p=247</guid>
		<description><![CDATA[***** Rant Alert ******
&#60;rant&#62;
At my current client I&#8217;ve got to do mainly maintenance on existing applications. This gives me the chance to look into codebases that have been created by other people and that don&#8217;t really reflect how I would write things. That is all good though it gives me a chance to learn new [...]]]></description>
			<content:encoded><![CDATA[<p>***** Rant Alert ******</p>
<p>&lt;rant&gt;</p>
<p>At my current client I&#8217;ve got to do mainly maintenance on existing applications. This gives me the chance to look into codebases that have been created by other people and that don&#8217;t really reflect how I would write things. That is all good though it gives me a chance to learn new ways of doing things and when I think their way is better I&#8217;ll surely adopt.</p>
<p>Anyway when I&#8217;m browsing these codebases I do find a lot of things that could have been done better or more correctly and that&#8217;s what I&#8217;ll be writing about a little today.</p>
<p>The first one is returning bools:</p>
<p>I&#8217;ve found this in just about every project I&#8217;ve been in:</p>
<pre class="csharp" name="code">public bool IsNull(){
  if(obj == null)
    return true;
  else
    return false;
}</pre>
<p>The snippet above is a very long winded way of writing. IMHO this hurts readability and you&#8217;re saying the same thing twice. obj == null already returns a bool it makes no sense writing it again.</p>
<pre class="csharp" name="code">public bool IsNull() { return obj == null; }</pre>
<p>Another thing I keep seeing is very liberal use of try..catch blocks that catch all exceptions. Admittedly try..catch is cool but it should be used at times you are actually interested in the exception that is thrown. But it shouldn&#8217;t be used as a safeguard to swallow exceptions you don&#8217;t want to fix at this moment.  I keep seeing this code in projects:</p>
<pre class="csharp" name="code">try{
  myBLObject.FindSomething(someId).SomeMethod();
}
catch(Exception){
// Nothing to be done but error stops
}</pre>
<p>Now that can be easily written so that it won&#8217;t throw an exeption and then the try catch isn&#8217;t necessary anymore at all. Try..catch blocks most certainly have their use but throwing and catching exceptions definitely hurts performance because the system has to generate a complete stack trace etc. for every exception that is being thrown.</p>
<pre class="csharp" name="code">var result = myBLObject.FindSomething(someId);
if(result != null) result.SomeMethod();</pre>
<p>The code becomes a lot more readable, not to mention faster. I&#8217;ve seen this being used in OnRowDataBound events etc on grids with 500+ rows, removing the try catch blocks more than doubles the speed of that page.</p>
<p>The next one on the list is using if,else and switch statements. They are sometimes a cause of code bloat. To put it in the words of <a href="http://www.hanselman.com/blog/BackToBasicsLifeAfterIfForAndSwitchLikeADataStructuresReminder.aspx" target="_blank">Scott Hanselman</a>:</p>
<blockquote><p><strong>I think that using only <em>if</em>, <em>for </em>and <em>switch </em>is the Computer Programmer equivalent of using &#8220;like&#8221; in every sentence.</strong></p></blockquote>
<p>Scott does a great job explaining why they can be pretty evil so I&#8217;ll just leave you with a <a href="http://www.hanselman.com/blog/BackToBasicsLifeAfterIfForAndSwitchLikeADataStructuresReminder.aspx" target="_blank">link</a> to his post</p>
<p>I have another couple of posts in the making on this subject but I had to get this out of my system. These are also very quick wins the other things I&#8217;m going to talk about are application architecture and stored procs&#8230;.<br />
&lt;/rant&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://flanders.co.nz/2008/09/24/common-mistakes-in-software-development/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>IronNails : Rails like development for IronRuby with WPF/Silverlight</title>
		<link>http://flanders.co.nz/2008/08/07/ironnails-introduction/</link>
		<comments>http://flanders.co.nz/2008/08/07/ironnails-introduction/#comments</comments>
		<pubDate>Thu, 07 Aug 2008 14:23:43 +0000</pubDate>
		<dc:creator>Ivan Porto Carrero</dc:creator>
				<category><![CDATA[.NET 3.0]]></category>
		<category><![CDATA[.NET 3.5]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[IronRuby]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[ironnails]]></category>
		<category><![CDATA[silverlight]]></category>
		<category><![CDATA[dlr]]></category>

		<guid isPermaLink="false">http://flanders.co.nz/2008/08/07/ironnails-introduction/</guid>
		<description><![CDATA[For my book IronRuby I'm working on chapter 4. That chapter is about doing WPF development with IronRuby. I started out with a straight port of Witty to IronRuby. As I was doing that the cogs started turning and I came up with a way to bring the rails style of development to WPF.   I decided to investigate that route a little bit further and now I have a small framework that enables you to write WPF applications with the MVC paradigm. I decided to open that code up as open source and host it on github.]]></description>
			<content:encoded><![CDATA[<p>For my book IronRuby I&#8217;m working on chapter 4. That chapter is about doing WPF development with IronRuby. I started out with a straight port of <a href="http://code.google.com/p/wittytwitter" target="_blank">Witty</a> to IronRuby. As I was doing that the cogs started turning and I came up with a way to bring the rails style of development to WPF.&#160;&#160; I decided to investigate that route a little bit further and now I have a small framework that enables you to write WPF applications with the MVC paradigm. I decided to open that code up as open source and host it on github.&#160; </p>
<p>At first I used the name Sails for my framework but it turns out there is java clone of rails that is called opensails. So to avoid confusion David M. Peterson proposed the name IronNails.</p>
<blockquote><p>On Sat, 02 Aug 2008 08:00:44 -0600, Charles Oliver Nutter wrote: </p>
<p>&#160;&#160;&#160; FYI, there&#8217;s already a framework named &quot;Sails&quot; for Java:      <br /><a href="http://www.opensails.org/">http://www.opensails.org/</a></p>
<p>For the sake of sticking to the &quot;Iron&quot; theme, why not replace the &#8216;S&#8217; with an &#8216;N&#8217; and go with IronNails. <img src='http://flanders.co.nz/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> &#160; Maybed it&#8217;s just me, but if given the choice, I&#8217;d much rather nail it than sail it any day of the week. <img src='http://flanders.co.nz/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  </p>
<p>&#8211;      <br />/M:D </p>
<p>M. David Peterson</p>
</blockquote>
<p>You can find the project here: <a href="http://github.com/casualjim/ironnails">http://github.com/casualjim/ironnails</a></p>
<p>At this moment it&#8217;s definitely not finished at all, but it does work. The remainder of the week I&#8217;ll move my previous demo code onto this framework, update the code samples in my chapter and finish the content. I hope I will have all of this done by the end of next week.</p>
<p>Back to the IronNails project:</p>
<p>Because DLR objects cannot be used to bind to in WPF you have to define a skeleton of the ViewModel in C#, but this will change in the future. When that changes I&#8217;ll look at extending the framework to make use of some other WPF patterns like defining a DependencyObject and Behaviors. Once those are defined you get a very clean separation between design and behavior.</p>
<p>This is abstracted away from you but in the background the framework works with the View &#8211; ViewModel &#8211; Model &#8211; Controller pattern although I&#8217;ve tried to keep your exposure to the view model to a minimum. The framework follows naming conventions per language. So in C# and XAML you camel case stuff and in IronRuby you underscore stuff.</p>
<p>The very core of the framework is defined in C# but most of the code is IronRuby, depending on how hard it will be after the DLR RTM&#8217;s I may look at adding support for all the DLR languages.</p>
<blockquote><p>IronNails      <br />========= </p>
<p>IronNails is a framework inspired by the Rails and rucola frameworks. It offers a rails-like way of developing      <br />applications with IronRuby and Windows Presentation Foundation (WPF).       <br />This framework uses the pattern Model &#8211; ViewModel &#8211; View &#8211; Controller (M-VM-V-C). It should be able to run on both WPF       <br />and Silverlight.       <br />The idea is that the views can be created using a design tool like Blend for example and just save that xaml as is. The       <br />designer should not need to use anything else than drag and drop to create a GUI design. The behaviors are then added to       <br />the view by using predefined behaviors in the framework or by defining your own behavior.       <br />The framework then generates a proxy for the view which will be used to transparently wire up the commands in the       <br />behaviors to controller actions. </p>
</blockquote>
<p>You are now able to write the following code for a controller: </p>
<pre class="ruby" name="code">class MyController &lt; IronNails::Controller::Base

  view_action :show_message, :triggers =&gt; :my_button do
    MessageBox.show &quot;This is the great message from a block&quot;
  end

  view_action :change_color, :triggers =&gt; { :element =&gt; :my_text_block, :event =&gt; :mouse_enter }
  view_action :reset_color, :triggers =&gt; { :element =&gt; :my_text_block, :event =&gt; :mouse_leave } do |view|
    view.my_text_block.foreground = :black.to_brush
  end

  view_object :people, Person.find_all

  def change_color(view)
    view.my_text_block.foreground = :red.to_brush
  end

end</pre>
<p></p>
<p>At this moment the project has 0 unit tests, it has below minimal documentation and it still needs a work like defining the behaviors. I have to move on with my book but intend to continue developing this framework after my book is finished and IronRuby RTM&#8217;s.&#160; There are some more workarounds in the project that will all disappear as IronRuby progresses.</p>
<div><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fflanders.co.nz%2f2008%2f08%2f07%2fironnails-introduction%2f"><img alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fflanders.co.nz%2f2008%2f08%2f07%2fironnails-introduction%2f" border="0" /></a> </div>
<div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:b145efcd-14b0-4d36-9aa2-efed49897e0d" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">Technorati Tags: <a href="http://technorati.com/tags/IronRuby" rel="tag">IronRuby</a>,<a href="http://technorati.com/tags/IronRubyInAction" rel="tag">IronRubyInAction</a>,<a href="http://technorati.com/tags/IronNails" rel="tag">IronNails</a>,<a href="http://technorati.com/tags/WPF" rel="tag">WPF</a></div>
]]></content:encoded>
			<wfw:commentRss>http://flanders.co.nz/2008/08/07/ironnails-introduction/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Ninject: Getting all the stuff you&#8217;ll need</title>
		<link>http://flanders.co.nz/2008/04/17/ninject-getting-all-the-stuff-youll-need/</link>
		<comments>http://flanders.co.nz/2008/04/17/ninject-getting-all-the-stuff-youll-need/#comments</comments>
		<pubDate>Wed, 16 Apr 2008 22:13:48 +0000</pubDate>
		<dc:creator>Ivan Porto Carrero</dc:creator>
				<category><![CDATA[.NET 3.5]]></category>
		<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[Lightspeed]]></category>
		<category><![CDATA[Ninject]]></category>
		<category><![CDATA[Nlog]]></category>

		<guid isPermaLink="false">http://flanders.co.nz/2008/04/17/ninject-getting-all-the-stuff-youll-need/</guid>
		<description><![CDATA[I have a new project I started and I could reevaluate my toolset   I decided to take a closer look at Ninject, Moq and NSpecify.&#160; Moq has been talked about enough I think, a really nice way of mocking and I will definitely be using more of it. My original plan was to [...]]]></description>
			<content:encoded><![CDATA[<p>I have a new project I started and I could reevaluate my toolset <img src='http://flanders.co.nz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  I decided to take a closer look at <a href="http://ninject.org">Ninject</a>, <a href="http://code.google.com/p/moq/">Moq</a> and <a href="http://https//nspecify.svn.sourceforge.net/svnroot/nspecify">NSpecify</a>.&#160; <a href="http://code.google.com/p/moq/">Moq</a> has been talked about enough I think, a really nice way of mocking and I will definitely be using more of it. My original plan was to write one big blog post.. but it is going to be far too long, so I&#8217;m breaking it up in smaller bite size pieces.</p>
<p>What I did was download the code, have it rest on my pc for about a week, updated again when I really got round to using it. I read the <a title="The Ninject Manual" href="http://dojo.ninject.org/wiki/display/NINJECT/Ninject+Manual">wiki</a> which gives a short introduction on what&#8217;s what in Ninject and everybodies jobs. Decided that the wiki was cool for some more theoretical knowledge but I really needed to see more code.</p>
<p>I opened the project and something rare happened: I was actually very happy with the code I found, not always the case I can tell you <img src='http://flanders.co.nz/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> .&#160; Anyway the gold is in the unit tests, it&#8217;s got great test coverage and it shows lots of the possibilities of Ninject. It&#8217;s like a great big manual for you to get really advanced with it really quickly.&#160; I was slightly disappointed to see that there was no <a href="http://nlog-project.com">NLog</a> support for Ninject, that disappointment quickly turned in to joy when I figured out it only took me 20 minutes to plug NLog in. And it was added to the trunk the same day.</p>
<p>Now I don&#8217;t want to make this post about which DI framework is better Windsor, Spring, Structuremap or Ninject. I just know that Ninject and I will become good friends over the next couple of months I like it. Ninject outsources its proxy generation to either Castle&#8217;s DynamicProxy2 or to LinFu DynamicProxy.&#160; LinFu seemed like an interesting choice after reading <a href="http://www.codeproject.com/KB/cs/LinFuPart1.aspx">this codeproject article</a>. It&#8217;s supposedly faster than castle&#8217;s dynamic proxy. Luckily Ayende is there to put this in <a href="http://www.ayende.com/Blog/archive/2007/10/16/Trusting-the-benchmark.aspx">perspective</a>. And I can confirm that the error messages etc castle&#8217;s dynamic proxy generates are a lot more useful than LinFu.</p>
<p><img height="293" alt="Screenshot - LinFuGraph.png" src="http://www.codeproject.com/KB/cs/LinFuPart1/LinFuGraph.png" width="546" /></p>
<p>Anyway I&#8217;m using LinFu at the moment as the proxy generator for Ninject. I will walk you through a sample application I built that will deal with the following subjects of Ninject, Lightspeed and NLog. For Ninject we will use the dependency injection and it&#8217;s interceptor possibilities to implement AOP style logging. For Lightspeed we will create our own logger to plug into the context so that we can log what Lightspeed does too. And we want NLog to log through Lightspeed to our database so we&#8217;ll be creating a custom target for NLog as well.</p>
<p>But let&#8217;s start at the beginning doing DI with Ninject <img src='http://flanders.co.nz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p>The most important thing to remember: <strong>MAKE YOUR METHODS VIRTUAL</strong>. Once again <strong>make your methods virtual </strong>otherwise Ninject has a hard time generating proxies for your classes.</p>
<p>Ninject is different from most other DI Containers in that it doesn&#8217;t have XML-configuration, its configuration is done through code (wouldn&#8217;t be hard to add an XML configuration for it tho but what&#8217;s the point). No XML ?? Suits me fine, everybody that ever worked with me will agree : Ivan no like XML editing.&#160; Ninject takes a modular approach by using modules that you pass to a kernel. This is pretty nice that means that an assembly can have a couple of different sets of Modules and all the caller of that assembly needs to do is add the module with the appropriate configuration to their kernel.</p>
<p>Ninject supports DI on constructors, properties, methods and fields: <a title="http://dojo.ninject.org/wiki/display/NINJECT/Injection+Patterns" href="http://dojo.ninject.org/wiki/display/NINJECT/Injection+Patterns">http://dojo.ninject.org/wiki/display/NINJECT/Injection+Patterns</a>.    <br />It basically boils down to decorating the item you want to inject with the attribute <em>[Inject]</em></p>
<p>Ninject allows you to do a lot of configuration through the use of attributes. But I think I&#8217;ll leave it at that for today and continue this tomorrow.   <br />Let&#8217;s look at a concrete class from what we&#8217;ve seen so far. The class below is the Logger implementation to plug into the LightSpeedContext. We will finish this later on but for now this will be enough to summarize today&#8217;s post.</p>
<pre class="csharp" name="code">using Ninject.Core;
using Ninject.Core.Logging;

using ILightSpeedLogger = Mindscape.LightSpeed.Logging.ILogger;
using INinjectLogger = Ninject.Core.Logging.ILogger;

namespace LoggingDemo.UI.Integration
{
///
/// This class intercepts logging messages from the LightSpeed context and
/// sends them to our NLog logger.
///
public class LightSpeedLogger : ILightSpeedLogger
{
private readonly INinjectLogger logger = NullLogger.Instance;

public LightSpeedLogger()
{
}

[Inject]
public LightSpeedLogger(INinjectLogger logger)
{
this.logger = logger;
}

#region ILogger Members

public virtual void LogSql(object sql)
{
logger.Info(sql.ToString());
}

public virtual void LogDebug(object text)
{
logger.Debug(text.ToString());
}

#endregion
}
}</pre>
<p>Let me know what you think <img src='http://flanders.co.nz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fflanders.co.nz%2f2008%2f04%2f17%2fninject-getting-all-the-stuff-youll-need%2f"><img alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fflanders.co.nz%2f2008%2f04%2f17%2fninject-getting-all-the-stuff-youll-need%2f" border="0" /></a></p>
<div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:1ad711c8-ccf8-4672-9e47-b78fb9fd556e" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">Technorati Tags: <a href="http://technorati.com/tags/LightSpeed" rel="tag">LightSpeed</a>,<a href="http://technorati.com/tags/Ninject" rel="tag">Ninject</a>,<a href="http://technorati.com/tags/NLog" rel="tag">NLog</a>,<a href="http://technorati.com/tags/Dependency%20Injection" rel="tag">Dependency Injection</a>,<a href="http://technorati.com/tags/IoC" rel="tag">IoC</a></div>
<div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:b80ed6bc-3bf0-4d18-b0ec-ee82ce235513" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">del.icio.us Tags: <a href="http://del.icio.us/popular/LightSpeed" rel="tag">LightSpeed</a>,<a href="http://del.icio.us/popular/Ninject" rel="tag">Ninject</a>,<a href="http://del.icio.us/popular/NLog" rel="tag">NLog</a>,<a href="http://del.icio.us/popular/Dependency%20Injection" rel="tag">Dependency Injection</a>,<a href="http://del.icio.us/popular/IoC" rel="tag">IoC</a></div>
]]></content:encoded>
			<wfw:commentRss>http://flanders.co.nz/2008/04/17/ninject-getting-all-the-stuff-youll-need/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Consuming YouTube using XLinq</title>
		<link>http://flanders.co.nz/2008/02/27/consuming-youtube-using-xlinq/</link>
		<comments>http://flanders.co.nz/2008/02/27/consuming-youtube-using-xlinq/#comments</comments>
		<pubDate>Wed, 27 Feb 2008 02:28:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.NET 3.5]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://blog.koolkraft.net/2008/02/27/consuming-youtube-using-xlinq/</guid>
		<description><![CDATA[I had to implement an integration with youtube for a client yesterday. Google provides API&#8217;s but they are for Java and PHP. I&#8217;m using C# for this project. So I decided to use XLinq to fetch the feeds and parse them into classes for what I needed. 
I only need titles, movies and a thumbnail [...]]]></description>
			<content:encoded><![CDATA[<p>I had to implement an integration with youtube for a client yesterday. Google provides API&#8217;s but they are for Java and PHP. I&#8217;m using C# for this project. So I decided to use XLinq to fetch the feeds and parse them into classes for what I needed. </p>
<p>I only need titles, movies and a thumbnail for each item. So I haven&#8217;t implemented all of the properties. And I am impressed. From having no exposure to XLinq whatsoever to having it parse feeds and being able to use those feeds in my monorail application took me about an hour. Since this is the very first time I use XLinq I imagine there is room for improvement, please tell me so when I&#8217;m wrong.</p>
<p>The classes I show here can be used as follows:    </p>
<pre class="csharp" name="code">YouTubePlayList.LoadForUser("<<username>>").ForEach(pl => Response.Write("<span style="color: blue">" + pl.Id + "</span>"));

var url = http://gdata.youtube.com/feeds/api/playlists/<
<playlistid>;
YouTubeCollection.LoadFrom(url).ForEach(yt => Response.Write(yt.Title + ", " + yt.MovieUrl + ""));</pre>
</p>
<pre class="csharp" name="code">
public class YouTubeCollection : List<YouTubeItem>
    {
        public YouTubeCollection()
        {
        }

        public YouTubeCollection(IEnumerable<YouTubeItem> collection)
            : base(collection)
        {
        }

        public static YouTubeCollection LoadFrom(string uri)
        {
            var feed = XElement.Load(uri);

            XNamespace ns = "http://www.w3.org/2005/Atom";
            XNamespace media = "http://search.yahoo.com/mrss/";

            var list = new YouTubeCollection(from item in feed.Elements(ns + "entry").Elements(media + "group")
                        select new YouTubeItem
                        {
                            Title = item.Element(media + "title").Value,
                            MovieUrl = (from el in item.Elements(media + "content")
                                     where el.Attribute("type").Value == "application/x-shockwave-flash"
                                     select el.Attribute("url").Value).First(),
                             ThumbnailUrl = (from el in item.Elements(media + "thumbnail")
                                             select el.Attribute("url").Value).First()
                        });

            return list;
        }

    }

    public class YouTubePlayList : List<YouTubePlayListItem>
    {
        public YouTubePlayList()
        {
        }

        public YouTubePlayList(IEnumerable<YouTubePlayListItem> collection) : base(collection)
        {
        }

        public static YouTubePlayList LoadForUser(string user)
        {
            var url = string.Format("http://gdata.youtube.com/feeds/api/users/{0}/playlists", user);

            var feed = XElement.Load(url);

            XNamespace ns = "http://www.w3.org/2005/Atom";
            XNamespace gd = "http://schemas.google.com/g/2005";

            var list = new YouTubePlayList(from item in feed.Elements(ns + "entry")
                                           select new YouTubePlayListItem
                                             {
                                                 Name = item.Element(ns + "title").Value,
                                                 Id = item.Element(gd + "feedLink").Attribute("href").Value
                                             });

            return list;
        }
    }

    [DataContract]
    public class YouTubePlayListItem
    {
        [DataMember]
        public string Name { get; set; }
        [DataMember]
        public string Id { get; set; }
    }

    [DataContract]
    public class YouTubeItem
    {
        private string _id;
        [DataMember]
        public string Id
        {
            get
            {
                return MovieUrl.Split('/').Last();
            }
            set
            {
                _id = value;
            }
        }

        [DataMember]
        public string Title { get; set; }

        [DataMember]
        public string MovieUrl { get; set; }

        [DataMember]
        public string ThumbnailUrl { get; set; }
    }</pre>
<p> </p>
</p>
<div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:146f067f-4d66-4d0d-af7b-b18e191829ef" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">Technorati Tags: <a href="http://technorati.com/tags/XLinq" rel="tag">XLinq</a>,<a href="http://technorati.com/tags/youtube" rel="tag">youtube</a></div>
]]></content:encoded>
			<wfw:commentRss>http://flanders.co.nz/2008/02/27/consuming-youtube-using-xlinq/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Compiling Mono and IronRuby on OSX Leopard</title>
		<link>http://flanders.co.nz/2008/02/05/compiling-mono-and-ironruby-on-osx-leopard/</link>
		<comments>http://flanders.co.nz/2008/02/05/compiling-mono-and-ironruby-on-osx-leopard/#comments</comments>
		<pubDate>Tue, 05 Feb 2008 04:32:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.NET 3.5]]></category>
		<category><![CDATA[IronRuby]]></category>

		<guid isPermaLink="false">http://blog.koolkraft.net/2008/02/05/compiling-mono-and-ironruby-on-osx-leopard/</guid>
		<description><![CDATA[I tried to compile IronRuby on OS X (leopard) with the dmg I downloaded from the mono website, and that didn&#8217;t work.
I then uninstalled that mono version by running monoUninstall.sh and proceeded to get mono from subversion. I&#8217;m putting these steps on my blog more for future reference when I decide to reinstall my box [...]]]></description>
			<content:encoded><![CDATA[<p>I tried to compile IronRuby on OS X (leopard) with the dmg I downloaded from the mono website, and that didn&#8217;t work.</p>
<p>I then uninstalled that mono version by running monoUninstall.sh and proceeded to get mono from subversion. I&#8217;m putting these steps on my blog more for future reference when I decide to reinstall my box for some reason.</p>
<p>Download <a href="ftp://ftp.gnu.org/gnu/gettext/gettext-0.17.tar.gz">gettext</a>, <a href="http://pkgconfig.freedesktop.org/releases/pkg-config-0.23.tar.gz">pkgconfig</a> and <a href="ftp://ftp.gtk.org/pub/glib/2.12/glib-2.12.12.tar.bz2">glib2.0</a></p>
<p>extract the archives and build them in the following order gettext, pkgconfig, glib2.0</p>
<p>./configure &#8211;prefix=/opt/local<br />
make<br />
sudo make install</p>
<p>At this point it would be wise to set the PKG_CONFIG_PATH environment variable. I added the following line to ~/.bash_profile</p>
<p>export PKG_CONFIG_PATH=&#8221;/usr/local/lib/pkgconfig:/opt/local/lib/pkgconfig&#8221;</p>
<p>next it&#8217;s time to check out the mono sources from their repositories</p>
<p>cd ~/<br />
mkdir tools<br />
mkdir mono<br />
svn co svn://anonsvn.mono-project.com/source/trunk/mono<br />
svn co svn://anonsvn.mono-project.com/source/trunk/mcs<br />
svn co svn://anonsvn.mono-project.com/source/trunk/libgdiplus<br />
svn co svn://anonsvn.mono-project.com/source/trunk/moon<br />
svn co svn://anonsvn.mono-project.com/source/trunk/olive<br />
svn co svn://anonsvn.mono-project.com/source/trunk/gtk-sharp</p>
<p>checking those out will take a while</p>
<p>now go into the mono directory and build mono</p>
<p>cd mono<br />
./autogen.sh &#8211;prefix=/opt/local/mono &#8211;with-preview=yes &#8211;with-moonlight=yes</p>
<p><span style="font-size: 10px;">&#8211;with-preview enables the .NET 3.5 features that have been implemented so far<br />
&#8211;with-moonlight enables support for moonlight</span></p>
<p>make<br />
sudo make install</p>
<p>This will also take some time and when it completes you can check if mono is installed by typing mono -V</p>
<p>That&#8217;s it for mono, now onto IronRuby</p>
<p style="margin: 0px; font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">cd ~/tools</p>
<p style="margin: 0px; font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">svn co http://ironruby.rubyforge.org/svn/trunk ironruby</p>
<p style="margin: 0px; font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">sudo gem install pathname2</p>
<p style="margin: 0px; font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">rake compile mono=1</p>
<p style="margin: 0px; font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">
<p style="margin: 0px; font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">And that should be all <img src='http://flanders.co.nz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p style="margin: 0px; font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">
<p style="margin: 0px; font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;"><span style="text-decoration: underline;">UPDATE:</span> I&#8217;ve got <a title="Building ironruby from source" href="http://flanders.co.nz/2008/12/30/building-ironruby-with-mono-on-osx/" target="_blank">new instructions</a> for building IronRuby</p>
]]></content:encoded>
			<wfw:commentRss>http://flanders.co.nz/2008/02/05/compiling-mono-and-ironruby-on-osx-leopard/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
