<?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>Stefano Ricciardi &#187; C#</title>
	<atom:link href="http://stefanoricciardi.com/tag/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://stefanoricciardi.com</link>
	<description>On Software Development and Thereabouts</description>
	<lastBuildDate>Tue, 15 Nov 2011 07:57:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Dependency Injection for Dummies</title>
		<link>http://stefanoricciardi.com/2011/11/08/dependency-injection-for-dummies/</link>
		<comments>http://stefanoricciardi.com/2011/11/08/dependency-injection-for-dummies/#comments</comments>
		<pubDate>Tue, 08 Nov 2011 09:10:31 +0000</pubDate>
		<dc:creator>stefanoricciardi</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Design and Patterns]]></category>
		<category><![CDATA[agile]]></category>
		<category><![CDATA[IoC]]></category>

		<guid isPermaLink="false">http://stefanoricciardi.com/?p=1487</guid>
		<description><![CDATA[Antonio Vidal has translated this post into Spanish: you can find it here. Dependency injection is a very simple concept: if you have an object that interacts with other objects the responsibility of finding a reference to those objects at run time is moved outside of the object itself. What does it mean for an [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fstefanoricciardi.com%2F2011%2F11%2F08%2Fdependency-injection-for-dummies%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fstefanoricciardi.com%2F2011%2F11%2F08%2Fdependency-injection-for-dummies%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><em><a href="http://codecriticon.com/">Antonio Vidal</a> has translated this post into Spanish: you can find it <a href="http://codecriticon.com/dependencia-inyeccion-dummies/">here</a>.</em></p>
<p>Dependency injection is a very simple concept: if you have an object that interacts with other objects the responsibility of finding a reference to those objects at run time is moved outside of the object itself.</p>
<p>What does it mean for an object to &quot;interact&quot; with other objects? Generally it means invoking methods or reading properties from those objects. So if we have a class <code>A</code> that invokes method <code>Calculate</code> on class <code>B</code>, we can say that <code>A</code> interacts with <code>B</code>.</p>
<p>In the following example we show class <code>A</code> interacting with class <code>B</code>. We can equally say that <class>A</class> <i>depends</i> on class <code>B</code> to fulfill a responsibility. In this case, it not only invokes its method <code>Calculate</code> but it also creates a new instance of that class.</p>
<pre class="brush:csharp">class A
{
  private B _b;

  public A
  {
    _b = new B();
  }

  public int SomeMethod()
  {
    return (_b.Calculate() * 2);
  }
}</pre>
<p>In the following example, on the other side, the responsibility of getting a reference to an implementation of a class of type <code>B</code> is moved <i>outside</i> of <code>A</code>:</p>
<pre class="brush:csharp">class A
{
  private B _b;
  public A(B b)
  {
    _b = b;
  }
  public int SomeMethod()
  {
    return _(b.Calculate * 2);
  }
}</pre>
<p>In this case we say that a dependency (<code>B</code>) has been <i>injected</i> into <code>A</code>, via the constructor. Of course, you can also inject dependencies via a property (or even a regular method), like in the following example:</p>
<pre class="brush:csharp">class A
{
  private B _b;

  public B B
  {
     get { return _b; }
     set { _b = value; }
  }

  public int SomeMethod()
  {
    if (_b != null)
        return _b.RetrieveValue() * 2;}
    else
        // HANDLE THIS ERROR CASE
        return -1;
  }
}</pre>
<p>So this is all there is about dependency injection. Everything else just builds on this core concept.</p>
<p>Like for example Inversion Of Control (IoC) tools which helps you wiring together your objects at run time, injecting all dependencies as needed. So what exactly is Inversion of Control and how does it relate to Dependency Injection (DI)?</p>
<p>I like to associate IoC to the <a href="http://en.wikipedia.org/wiki/Hollywood_Principle">Hollywood Principle</a>: &quot;<em>Don&#39;t call us, we&#39;ll call you</em>&quot;. IoC is a design principle where <quote>reusable generic code controls the execution of problem-specific code</quote>: it is a characteristic of many frameworks, where the application is built extending or customizing a common skeleton; you put your own classes at specific points and the framework will call you when needed.</p>
<p>You can use an IoC container as a framework to perform Dependency Injection on your behalf: you tell the container which are the concrete implementation classes for your dependencies and the container will make sure that your constructors or setters will be called with the right objects.</p>
<p>Therefore, IoC containers are just a <i>convenience</i> to simplify how dependency injection is handled. But even if you don&#39;t use one you could still manually perform dependency injection.</p>
<p>(If you want to have a look at how an IoC container works you can jump to my <a href="http://stefanoricciardi.com/2011/01/21/ninject-mini-tutorial-part-1/">mini tutorial on Ninject</a>).</p>
<p>Why is the concept of dependency injection important? Because by applying it, you simplify your design (separating the responsibility of using an object from the responsibility of retrieving that object) and your code becomes much easier to test, since you can mock out the dependencies substituting them with fake (stub) objects. But that is the subject for another post.</p>

]]></content:encoded>
			<wfw:commentRss>http://stefanoricciardi.com/2011/11/08/dependency-injection-for-dummies/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Code Snippets for the Dispose Pattern</title>
		<link>http://stefanoricciardi.com/2011/05/25/code-snippets-for-the-dispose-pattern/</link>
		<comments>http://stefanoricciardi.com/2011/05/25/code-snippets-for-the-dispose-pattern/#comments</comments>
		<pubDate>Wed, 25 May 2011 14:08:34 +0000</pubDate>
		<dc:creator>stefanoricciardi</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[visual studio 2010]]></category>

		<guid isPermaLink="false">http://stefanoricciardi.com/?p=1407</guid>
		<description><![CDATA[         ]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fstefanoricciardi.com%2F2011%2F05%2F25%2Fcode-snippets-for-the-dispose-pattern%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fstefanoricciardi.com%2F2011%2F05%2F25%2Fcode-snippets-for-the-dispose-pattern%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>I thougth I&#8217;d just share a couple of Visual Studio C# code snippets to implement disposable classes, based on the well known .NET <a href="http://msdn.microsoft.com/en-us/library/b1yfkh5e(v=VS.100).aspx">dispose pattern</a>.</p>
<p>You can download it from <a href="http://stefanoricciardi.com/blog/wp-content/uploads/2011/05/DisposePattern.zip">here</a> or simply copy and past it from the listing below. Feel free to rename the shortcut to whatever you like <img src='http://stefanoricciardi.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<pre class="brush:xml">
&lt;?xml version="1.0" encoding="utf-8" ?&gt;
&lt;CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"&gt;
  &lt;CodeSnippet Format="1.0.0"&gt;
    &lt;Header&gt;
      &lt;Title&gt;Base class disposable implementation.&lt;/Title&gt;
      &lt;Shortcut&gt;bdisp&lt;/Shortcut&gt;
      &lt;Description&gt;
        Code snippet to create a scheleton implementation
        of the IDisposable pattern for a base class.
      &lt;/Description&gt;
      &lt;Author&gt;Stefano Ricciardi&lt;/Author&gt;
      &lt;SnippetTypes&gt;
        &lt;SnippetType&gt;Expansion&lt;/SnippetType&gt;
      &lt;/SnippetTypes&gt;
    &lt;/Header&gt;
    &lt;Snippet&gt;
      &lt;Declarations&gt;
        &lt;Literal&gt;
          &lt;ID&gt;ClassName&lt;/ID&gt;
          &lt;ToolTip&gt;Name of the class.&lt;/ToolTip&gt;
          &lt;Default&gt;ClassName&lt;/Default&gt;
        &lt;/Literal&gt;
      &lt;/Declarations&gt;
      &lt;Code Language="csharp"&gt;
        &lt;![CDATA[
    public class $ClassName$: IDisposable
    {
        private bool _disposed = false;

        //Implement IDisposable.
        public void Dispose()
        {
          Dispose(true);
          GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
          if (!_disposed)
          {
            if (disposing)
            {
              // Free other state (managed objects).
            }
            // Free your own state (unmanaged objects).
            // Set large fields to null.
            _disposed = true;
          }
        }

        // Use C# destructor syntax for finalization code.
        ~$ClassName$()
        {
          // Simply call Dispose(false).
          Dispose(false);
        }
    }            ]]&gt;
      &lt;/Code&gt;
    &lt;/Snippet&gt;
  &lt;/CodeSnippet&gt;
  &lt;CodeSnippet Format="1.0.0"&gt;
    &lt;Header&gt;
      &lt;Title&gt;Base class disposable implementation.&lt;/Title&gt;
      &lt;Shortcut&gt;ddisp&lt;/Shortcut&gt;
      &lt;Description&gt;
        Code snippet to create a scheleton implementation of the
        IDisposable pattern	for a derived class.
      &lt;/Description&gt;
      &lt;Author&gt;Stefano Ricciardi&lt;/Author&gt;
      &lt;SnippetTypes&gt;
        &lt;SnippetType&gt;Expansion&lt;/SnippetType&gt;
      &lt;/SnippetTypes&gt;
    &lt;/Header&gt;
    &lt;Snippet&gt;
      &lt;Declarations&gt;
        &lt;Literal&gt;
          &lt;ID&gt;DerivedClassName&lt;/ID&gt;
          &lt;ToolTip&gt;Name of the derived class.&lt;/ToolTip&gt;
          &lt;Default&gt;Derived&lt;/Default&gt;
        &lt;/Literal&gt;
        &lt;Literal&gt;
          &lt;ID&gt;BaseClassName&lt;/ID&gt;
          &lt;ToolTip&gt;Name of the base class.&lt;/ToolTip&gt;
          &lt;Default&gt;Base&lt;/Default&gt;
        &lt;/Literal&gt;
      &lt;/Declarations&gt;
      &lt;Code Language="csharp"&gt;
        &lt;![CDATA[
  public class $DerivedClassName$: $BaseClassName$
  {
      private bool _disposed = false;

      protected override void Dispose(bool disposing)
      {
          if (!_disposed)
          {
              if (disposing)
              {
                  // Release managed resources.
              }
              // Release unmanaged resources.
              // Set large fields to null.
              // Call Dispose on your base class.

              _disposed = true;
          }

          base.Dispose(disposing);
      }
      // The derived class does not have a Finalize method
      // or a Dispose method without parameters because it inherits
      // them from the base class.
  }
]]&gt;
      &lt;/Code&gt;
    &lt;/Snippet&gt;
  &lt;/CodeSnippet&gt;
&lt;/CodeSnippets&gt;
</pre>

]]></content:encoded>
			<wfw:commentRss>http://stefanoricciardi.com/2011/05/25/code-snippets-for-the-dispose-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ninject Mini Tutorial &#8211; Part 2</title>
		<link>http://stefanoricciardi.com/2011/02/04/ninject-mini-tutorial-part-2/</link>
		<comments>http://stefanoricciardi.com/2011/02/04/ninject-mini-tutorial-part-2/#comments</comments>
		<pubDate>Fri, 04 Feb 2011 13:17:43 +0000</pubDate>
		<dc:creator>stefanoricciardi</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Design and Patterns]]></category>
		<category><![CDATA[IoC]]></category>
		<category><![CDATA[ninject]]></category>
		<category><![CDATA[OOP]]></category>

		<guid isPermaLink="false">http://stefanoricciardi.com/?p=1337</guid>
		<description><![CDATA[Go to Part 1 &#160; Controlling the Life Cycle of your Objects In the previous post we did not concern ourselves with the lifecycle of the object returned from Ninject kernel. Ninject provides the following 4 built-in lifecycles (scopes): Transient (default) Singleton (only one instance) Thread (one instance per thread) Request (one instance per web [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fstefanoricciardi.com%2F2011%2F02%2F04%2Fninject-mini-tutorial-part-2%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fstefanoricciardi.com%2F2011%2F02%2F04%2Fninject-mini-tutorial-part-2%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><em>Go to <a href="http://stefanoricciardi.com/2011/01/21/ninject-mini-tutorial-part-1/">Part 1</a></em></p>
<p>&nbsp;</p>
<h2>Controlling the Life Cycle of your Objects</h2>
<p>In the previous post we did not concern ourselves with the lifecycle of the object returned from Ninject kernel. Ninject provides the following 4 built-in lifecycles (<em>scopes</em>):</p>
<ol>
<li>Transient (default)</li>
<li>Singleton (only one instance)</li>
<li>Thread (one instance per thread)</li>
<li>Request (one instance per web request).</li>
</ol>
<p>You can create <em>custom scopes</em> if needed.</p>
<h4>Singleton:</h4>
<pre class="brush:csharp">using (IKernel kernel = new StandardKernel())
{
    kernel.Bind&lt;ITaxCalculator&gt;()
        .To&lt;TaxCalculator&gt;()
        .InSingletonScope()
        .WithConstructorArgument(&quot;rate&quot;, .2M);

    var tc1 = kernel.Get&lt;ITaxCalculator&gt;();
    var tc2 = kernel.Get&lt;ITaxCalculator&gt;();

    Assert.Same(tc1, tc2);
}</pre>
<h4>Transient:</h4>
<pre class="brush:csharp">using (IKernel kernel = new StandardKernel())
{
    kernel.Bind&lt;ITaxCalculator&gt;()
        .To&lt;TaxCalculator&gt;()
        .InTransientScope()
        .WithConstructorArgument(&quot;rate&quot;, .2M);

        var tc1 = kernel.Get&lt;ITaxCalculator&gt;();
        var tc2 = kernel.Get&lt;ITaxCalculator&gt;();

        Assert.NotSame(tc1, tc2);
}</pre>
<h2>More Details on Injection Patterns</h2>
<p>With Ninject you can inject:</p>
<ol>
<li>Constructor parameters</li>
<li>Properties</li>
<li>Methods</li>
</ol>
<p>Before considering each one in turn, we just need to introduce the <code>[Inject]</code> attribute which may be used to tag constructors, properties and methods requiring injection. Obviously, by tagging constructors, properties or methods, your objects cease to be <a href="http://en.wikipedia.org/wiki/Plain_Old_CLR_Object">POCO</a>s.</p>
<h3>Constructor Injection</h3>
<p>We have already seen an example of constructor injection in <a href="http://stefanoricciardi.com/2011/01/21/ninject-mini-tutorial-part-1/">Part I</a> when the kernel auto-magically injected an implementation of <code>ITaxCalculator</code> to the <code>Sale Area</code> constructor. In that case, even if we didn&#39;t tag the constructor with the <code>[Inject]</code> attribute, the kernel was able to perform the required binding. How?</p>
<p>That was actually a special case: when there is <em>only one</em> constructor available, the tagging is not needed. On the other hand, if there&#39;s more than one constructor defined, then then kernel can inject a dependency to only one constructor that needs to have the <code>[Inject]</code> attribute:</p>
<pre class="brush:fsharp">public class Sale3
{
    private readonly ITaxCalculator taxCalculator;

    public Sale3() { }

    [Inject]
    public Sale3(ITaxCalculator taxCalculator)
    {
        this.taxCalculator = taxCalculator;
    }

    // other stuff
}</pre>
<h3>Properties Injection</h3>
<p>Instead of passing in the dependencies through the constructor, you can also inject them as properties. Injecting properties is pretty straightforward:</p>
<pre class="brush:csharp">public class Sale2
{
    [Inject]
    public ITaxCalculator TaxCalculator { get; set; } 

    // implicit default constructor and other stuff... 

    public decimal GetTotal()
    {
        decimal total = 0M;
        foreach (var item in lineItems)
        {
            total += TaxCalculator.CalculateTax(item.TotalPrice)
                    + item.TotalPrice;
        } 

        return total;
    }
}</pre>
<p>Usage (note that we never explicitely set the <code>TaxCalculator</code>):</p>
<pre class="brush:csharp">using (IKernel kernel = new StandardKernel())
{
    kernel.Bind&lt;ITaxCalculator&gt;()
                  .To&lt;TaxcCalculator&gt;()
                  .WithConstructorArgument(&quot;rate&quot;, .2M);

    var lineItem1 = new SaleLineItem(&quot;Gone with the wind&quot;, 10M, 1);
    var lineItem2 = new SaleLineItem(&quot;Casablanca&quot;, 5M, 2);

    var sale = kernel.Get&lt;Sale2&gt;(); // property injection!
    sale.AddItem(lineItem1);
    sale.AddItem(lineItem2);

    Assert.Equal(24M, sale.GetTotal());
}</pre>
<p>There&#39;s an important caveat: if you have 2 or more properties injected, the order in which each dependency is injected is not predictable. This might complicate your design, if those dependencies are coupled somehow (e.g. dependency A needs dependency B). For this kind of situations, constructor or method injection is usually preferred.</p>
<h3>Methods Injection</h3>
<p>Finally, it&rsquo;s also possible to tag methods for injection. As with constructor parameters, it&rsquo;s possible to inject more than one value at once.</p>
<pre class="brush:csharp">public class Sale4
{
    private ITaxCalculator taxCalculator;

    // other stuff

    // method injection, will be called by the kernel
    [Inject]
    public void SetTaxCalculator(ITaxCalculator taxCalculator)
    {
        this.taxCalculator = taxCalculator;
    }

    public decimal GetTotal()
    {
        decimal total = 0M;
        foreach (var item in lineItems)
        {
            total += taxCalculator.CalculateTax(item.TotalPrice)
                  + item.TotalPrice;
        }

        return total;
    }
}</pre>
<p>Usage (note that we never explicitely call the <code>SetTaxCalculator</code>):</p>
<pre class="brush:csharp">using (IKernel kernel = new StandardKernel())
{
    kernel.Bind&lt;ITaxCalculator&gt;()
          .To&lt;TaxCalculator&gt;()
          .WithConstructorArgument(&quot;rate&quot;, .2M);

    var lineItem1 = new SaleLineItem(&quot;Gone with the wind&quot;, 10M, 1);
    var lineItem2 = new SaleLineItem(&quot;Casablanca&quot;, 5M, 2);

    var sale = kernel.Get&lt;Sale4&gt;(); // method injection!
    sale.AddItem(lineItem1);
    sale.AddItem(lineItem2);

    Assert.Equal(24M, sale.GetTotal());
}</pre>
<p><em>Go to <a href="http://stefanoricciardi.com/2011/01/21/ninject-mini-tutorial-part-1/">Part 1</a></em></p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http://stefanoricciardi.com/2011/02/04/ninject-mini-tutorial-part-2/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://stefanoricciardi.com/2011/02/04/ninject-mini-tutorial-part-2/" border="0" alt="kick it on DotNetKicks.com" /></a></p>

]]></content:encoded>
			<wfw:commentRss>http://stefanoricciardi.com/2011/02/04/ninject-mini-tutorial-part-2/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Ninject Mini Tutorial &#8211; Part 1</title>
		<link>http://stefanoricciardi.com/2011/01/21/ninject-mini-tutorial-part-1/</link>
		<comments>http://stefanoricciardi.com/2011/01/21/ninject-mini-tutorial-part-1/#comments</comments>
		<pubDate>Fri, 21 Jan 2011 13:12:23 +0000</pubDate>
		<dc:creator>stefanoricciardi</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Design and Patterns]]></category>
		<category><![CDATA[IoC]]></category>
		<category><![CDATA[ninject]]></category>
		<category><![CDATA[OOP]]></category>

		<guid isPermaLink="false">http://stefanoricciardi.com/?p=1327</guid>
		<description><![CDATA[What Is Ninject There are several Inversion of Control (IoC) containers for .NET to pick from (such as Castle Windsor, Structure Map and Microsoft Unity, just to name just a few).&#160; Ninject is one of the newest entries in the arena, but it&#8217;s now sufficiently stable at version 2.0. Ninject tries to focus on &#8220;simplicity [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fstefanoricciardi.com%2F2011%2F01%2F21%2Fninject-mini-tutorial-part-1%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fstefanoricciardi.com%2F2011%2F01%2F21%2Fninject-mini-tutorial-part-1%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<h2>What Is Ninject</h2>
<p>There are several Inversion of Control (IoC) containers for .NET to pick from (such as <a href="http://stw.castleproject.org/Windsor.MainPage.ashx">Castle Windsor</a>, <a href="http://structuremap.net/structuremap/index.html">Structure Map</a> and <a href="http://msdn.microsoft.com/en-us/library/ff663144.aspx">Microsoft Unity</a>, just to name just a few).&nbsp; <a href="http://ninject.org/">Ninject</a> is one of the newest entries in the arena, but it&rsquo;s now sufficiently stable at version 2.0.</p>
<p>Ninject tries to focus on &ldquo;<em>simplicity and ease of use</em>&rdquo;, removing features that are not deemed necessary (to the point that XML configuration is not offered out-of-the box).</p>
<p>In this and following posts we&rsquo;ll explore some example of how to use Ninject. I assume that you are somehow familiar with the basic concepts of <em>Inversion of Control</em> and <em>Dependency Injection</em>; if that&rsquo;s not the case, you should consider having a look at this <a href="http://en.wikipedia.org/wiki/Inversion_of_control">wikipedia entry</a> (better yet, take some time and read Martin Fowler f<a href="http://martinfowler.com/articles/injection.html">amous post</a> on the subject).&nbsp;&nbsp;</p>
<h2>Setup</h2>
<p>Installing Ninject is quite easy: you simply download the pre-built DLLs it from <a href="http://ninject.org/download">here</a>. Since Ninject is open source, you can also get the sources from <a href="https://github.com/ninject/ninject">github</a> and build it on your own.</p>
<p>On my Windows machine, I have copied the DLLs on <em>C:\Ninject</em>.</p>
<h2>Getting your Feet Wet With Ninject</h2>
<p>Once you have Ninject DLLs somewhere on your hard-drive, in order to get started you only need to reference them (typically you only need to reference <tt>NInject.dll</tt> ). As we said, no XML configuration is required.</p>
<p>Let&rsquo;s see a few basic examples (the complete source code with unit tests I present in this series are available on <a href="https://github.com/stefanoric/NINJECTTUTORIAL">github</a>).</p>
<h3>&quot;Hello, Ninject&rdquo;</h3>
<p>Suppose we have a fairly simple service to calculate the taxes for a given amount, defined in an <code>ITaxCalculator</code> interface:</p>
<pre class="brush:csharp">decimal CalculateTax(decimal gross);</pre>
<p>and a trivial implementation <code>TaxCalculator</code> as follows:</p>
<pre class="brush:csharp">public class TaxCalculator : ITaxCalculator
{
    private readonly decimal _rate;

    public TaxCalculator(decimal rate)
    {
        _rate = rate;
    }

    public decimal CalculateTax(decimal amount)
    {
        return Math.Round(_rate * amount, 2);
    }
}</pre>
<p>Now, one or more classes might need to use an <code>ITaxCalculator</code> implementation to fulfill their responsibility (such as calculating the total price for a shopping cart). We can say that an implementation of <code>ITaxCalculator</code> is a <em>dependency</em> to them.</p>
<p>Like many IoC containers, Ninject uses a central object (which it calls the <em>kernel</em>) to provide concrete implementations of dependencies at run-time. The <code>Standard Kernel</code> is the default implementation of such an object. Let&#39;s see it in action:</p>
<pre class="brush:csharp">using (IKernel kernel = new StandardKernel())
{
    kernel.Bind&lt;ITaxCalculator&gt;()
          .To&lt;TaxCalculator&gt;()
          .WithConstructorArgument(&quot;rate&quot;, .2M);

    var tc = kernel.Get&lt;ITaxCalculator&gt;();
    Assert.Equal(20M, tc.CalculateTax(100M));
}</pre>
<p>&nbsp;</p>
<p>As you can see, through a fluent interface we are instructing the kernel how to <em>bind</em> (resolve) requests for a <code>ITaxCalculator</code> to a <code>TaxCalculator</code> class (a concrete implementation), passing to its constructor a given tax rate (20% in this case).</p>
<p>The example continues showing how a client can retrieve an implementation of the service through the kernel (via the <code>Get()</code> method) and use it.</p>
<h3>Some Magic</h3>
<p>You might argue that the little example above is far from impressing. So let&rsquo;s now see Ninject performing something more clever.</p>
<p>Suppose we have a <code>Sale</code> class modeling a ongoing transaction on a ecommerce site. Such a class in our example depends on a <code>ITaxCalculator</code>to compute the final price of the shopping cart.</p>
<pre class="brush:csharp">public class Sale
{
    private readonly ITaxCalculator taxCalculator;

    public Sale(ITaxCalculator taxCalculator)
    {
        this.taxCalculator = taxCalculator;
    }

    // more stuff....

    public decimal GetTotal()
    {
	// use the tax calculator to calculate the total
    }
}</pre>
<p>We might create the sale in the obvious way, based on the preceding example:</p>
<pre class="brush:csharp">kernel.Bind&lt;ITaxCalculator&gt;()
          .To&lt;TaxCalculator&gt;()
          .WithConstructorArgument(&quot;rate&quot;, .2M);
var sale = new Sale(kernel.Get&lt;ITaxCalculator&gt;());&gt;</pre>
<p>More interestingly, it&#39;s possible to let Ninject to find out how a <code>Sale</code> should be built based on the binding information it has received:</p>
<pre class="brush:csharp">kernel.Bind&lt;ITaxCalculator&gt;()
          .To&lt;TaxCalculator&gt;()
          .WithConstructorArgument(&quot;rate&quot;, .2M);
var sale = kernel.Get&lt;Sale&gt;();</pre>
<p>Ninject is smart enough to build a Sale class for us taking care of fulfilling the dependencies behind the scenes. This an example of <em>autowiring</em>, a most convenient feature of many IoC containers.</p>
<p><em>Go to <a href="http://stefanoricciardi.com/2011/02/04/ninject-mini-tutorial-part-2//">Part 2</a></em></p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http://stefanoricciardi.com/2011/01/21/ninject-mini-tutorial-part-1/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://stefanoricciardi.com/2011/01/21/ninject-mini-tutorial-part-1/" border="0" alt="kick it on DotNetKicks.com" /></a></p>

]]></content:encoded>
			<wfw:commentRss>http://stefanoricciardi.com/2011/01/21/ninject-mini-tutorial-part-1/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>File Transfer with WCF: Part III</title>
		<link>http://stefanoricciardi.com/2010/09/02/file-transfer-with-wcf-part-iii/</link>
		<comments>http://stefanoricciardi.com/2010/09/02/file-transfer-with-wcf-part-iii/#comments</comments>
		<pubDate>Thu, 02 Sep 2010 12:08:55 +0000</pubDate>
		<dc:creator>stefanoricciardi</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[SOA]]></category>

		<guid isPermaLink="false">http://stefanoricciardi.com/?p=1099</guid>
		<description><![CDATA[This is the third post on a small series about transferring large files with WCF using streaming : File Transfer With WCF File Transfer With WCF: Part II File Transfer With WCF: Part III I am closing this series of posts by sharing a skeleton for the client side handling of the uploaded and downloaded [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fstefanoricciardi.com%2F2010%2F09%2F02%2Ffile-transfer-with-wcf-part-iii%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fstefanoricciardi.com%2F2010%2F09%2F02%2Ffile-transfer-with-wcf-part-iii%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><em>This is the third post on a small series about transferring large files with WCF using streaming</em> :</p>
<ul>
<li><a href="http://stefanoricciardi.com/2009/08/28/file-transfer-with-wcp/">File Transfer With WCF</a></li>
<li><a href="http://stefanoricciardi.com/2009/10/02/file-transfer-with-wcf-part-ii/">File Transfer With WCF: Part II</a></li>
<li><a href="http://stefanoricciardi.com/2010/09/02/file-transfer-with-wcf-part-iii/">File Transfer With WCF: Part III</a></li>
</ul>
<p>I am closing this series of posts by sharing a skeleton for the client side handling of the uploaded and downloaded files. Please note that the following are excerpt from a larger context and so will not compile in your environment <em>as is</em>: they are only intended to give a rough idea of how the files can be handled.</p>
<h3>Download</h3>
<pre class="brush:csharp">
 private void IssueDownloadRequest(string localFile, string serviceUrl, FileDownloadMessage request)
{
    this.service = this.proxy.OpenProxy(serviceUrl);

    try
    {
        using (FileDownloadReturnMessage response = this.service.DownloadFile(request))
        {
            if (response != null &#038;&#038; response.FileByteStream != null)
            {
                SaveFile(response.FileByteStream, localFile);
            }
        }

        this.proxy.CloseProxy(this.service);
    }
    catch (Exception e)
    {
        throw new FileTransferProxyException("Error while downloading the file", e);
    }
    finally
    {
        // we expect the stream returned from the server to be closed by the
        // server itself so nothing to be done with it here. Just abort
        // the proxy if needed.
        this.proxy.AbortProxyIfNeeded(this.service);
    }
}

private static void SaveFile(Stream saveFile, string localFilePath)
{
    const int bufferSize = 65536; // 64K

    using (FileStream outfile = new FileStream(localFilePath, FileMode.Create))
    {
        byte[] buffer = new byte[bufferSize];
        int bytesRead = saveFile.Read(buffer, 0, bufferSize);

        while (bytesRead > 0)
        {
            outfile.Write(buffer, 0, bytesRead);
            bytesRead = saveFile.Read(buffer, 0, bufferSize);
        }
    }
}
</pre>
<h3>Upload</h3>
<pre class="brush:csharp">
public void UploadFile(string localFileName, string serviceUrl, FileTypeEnum fileType)
{
    this.service = this.proxy.OpenProxy(serviceUrl);
    try
    {
        using (Stream fileStream = new FileStream(localFileName, FileMode.Open, FileAccess.Read))
        {
            var request = new FileUploadMessage();
            string remoteFileName = null;
            if (fileType == FileTypeEnum.Generic)
            {
                // we are using the service as a "FTP on WCF"
                // give the remote file the same name as the local one
                remoteFileName = Path.GetFileName(localFileName);
            }

            var fileMetadata = new FileMetaData(localFileName, remoteFileName, fileType);
            request.MetaData = fileMetadata;
            request.FileByteStream = fileStream;

            this.service.UploadFile(request);
            this.proxy.CloseProxy(this.service);
        }
    }
    catch (IOException)
    {
        throw new FileTransferProxyException("Unable to open the file to upload");
    }
    catch (Exception e)
    {
        throw new FileTransferProxyException(e.Message);
    }
    finally
    {
        this.proxy.AbortProxyIfNeeded(this.service);
    }
 }
</pre>
<p><a href="http://www.dotnetkicks.com/kick/?url=http://stefanoricciardi.com/2010/09/02/file-transfer-with-wcf-part-iii/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://stefanoricciardi.com/2010/09/02/file-transfer-with-wcf-part-iii/" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<p><a rev="vote-for" href="http://dotnetshoutout.com/File-Transfer-with-WCF-Part-III-Stefano-Ricciardi"><img alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fstefanoricciardi.com%2F2010%2F09%2F02%2Ffile-transfer-with-wcf-part-iii%2F" style="border:0px"/></a></p>

]]></content:encoded>
			<wfw:commentRss>http://stefanoricciardi.com/2010/09/02/file-transfer-with-wcf-part-iii/feed/</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
		<item>
		<title>A Fluent Builder in C#</title>
		<link>http://stefanoricciardi.com/2010/04/14/a-fluent-builder-in-c/</link>
		<comments>http://stefanoricciardi.com/2010/04/14/a-fluent-builder-in-c/#comments</comments>
		<pubDate>Wed, 14 Apr 2010 20:27:40 +0000</pubDate>
		<dc:creator>stefanoricciardi</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Design and Patterns]]></category>

		<guid isPermaLink="false">http://stefanoricciardi.com/?p=884</guid>
		<description><![CDATA[When it comes to the number of arguments to pass to a function, Uncle Bob is pretty clear. Quoting from Clean Code: The ideal number of arguments for a function is zero (niladic). Next comes one (monadic), followed closely by two (dyadic). Three arguments (triadic) should be avoided when possible. More than three (polyadic) requires [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fstefanoricciardi.com%2F2010%2F04%2F14%2Fa-fluent-builder-in-c%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fstefanoricciardi.com%2F2010%2F04%2F14%2Fa-fluent-builder-in-c%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>When it comes to the number of arguments to pass to a function, <a href="http://www.objectmentor.com/omTeam/martin_r.html">Uncle Bob</a> is pretty clear. Quoting from <a href="http://www.amazon.co.uk/gp/product/0132350882?ie=UTF8&amp;tag=stefaricci-21&amp;linkCode=as2&amp;camp=1634&amp;creative=19450&amp;creativeASIN=0132350882">Clean Code</a><img style="margin: 0px; border-style: none !important;" src="http://www.assoc-amazon.co.uk/e/ir?t=stefaricci-21&amp;l=as2&amp;o=2&amp;a=0132350882" border="0" alt="" width="1" height="1" />:</p>
<blockquote><p>The ideal number of arguments for a function is zero (niladic). Next comes one (monadic), followed closely by two (dyadic). Three arguments (triadic) should be avoided when possible. More than three (polyadic) requires very special justification – and then shouldn’t be used anyway.</p></blockquote>
<p>Still, some objects might have more than 3 attributes or properties and you usually need some way to initialize them via the constructor. Some attribute might not be mandatory, therefore on some occasions you can get by with a few overloads adding more parameters as needed.   </p>
<p>Consider the following (contrieved) example from the world of soccer. I have picked a few attributes that encapsulate the concept of a <code>Team</code>.</p>
<pre class="brush:csharp">
namespace Soccer
{
    public enum Color
    {
        White,
        Red,
        Green,
        Blue
    }

    public class Team
    {
        string Name { get; set; }
        string NickName { get; set; }
        Color ShirtColor { get; set; }
        string HomeTown { get; set; }
        string Ground { get; set; }

        public Team(
            string name,
            string nickName,
            Color shirtColor,
            string homeTown,
            string ground)
        {
            Name = name;
            NickName = nickName;
            ShirtColor = shirtColor;
            HomeTown = homeTown;
            Ground = ground;
        }
    }
}</pre>
<p>Let&#8217;s try initializing one team:</p>
<pre class="brush:csharp">Team team1 = new Team(
    "Manchester United",
    "The Red Devils",
    Color.Red,
    "Manchester",
    "Old Trafford");
</pre>
<p>In this case we are passing 5 arguments into the constructor. Consider that most of the parameters is a string, therefore it&#8217;s quite easy to get confused and invert the order of some parameter (the first two or the last two). The compiler would not be able to help in this case.</p>
<p>What may help here is a builder object with a <a href="http://en.wikipedia.org/wiki/Fluent_interface">fluent interface</a> which can help specifying all the attributes of the team. Something like the following:</p>
<pre class="brush:csharp">TeamBuilder tb = new TeamBuilder();
Team team2 =
    tb.CreateTeam("Real Madrid")
        .WithNickName("Los Merengues")
        .WithShirtColor(Color.White)
        .FromTown("Madrid")
        .PlayingAt("Santiago Bernabeu")
        .Build();
</pre>
<p>Let&#8217;s see the code for the <code>TeamBuilder</code> class:</p>
<pre class="brush:csharp">public class TeamBuilder
{
    private string name;
    private string nickName;
    private Color shirtColor;
    private string homeTown;
    private string ground;

    public TeamBuilder CreateTeam(string name)
    {
        this.name = name;
        return this;
    }

    public TeamBuilder WithNickName(string nickName)
    {
        this.nickName = nickName;
        return this;
    }

    public TeamBuilder WithShirtColor(Color shirtColor)
    {
        this.shirtColor = shirtColor;
        return this;
    }

    public TeamBuilder FromTown(string homeTown)
    {
        this.homeTown = homeTown;
        return this;
    }

    public TeamBuilder PlayingAt(string ground)
    {
        this.ground = ground;
        return this;
    }

    public Team Build()
    {
        return new Team(name, nickName, shirtColor, homeTown, ground);
    }
}
</pre>
<p>The only catch in the solution above is that the caller needs to call <code>Build()</code> at the end of the call chain.</p>
<p>We can improve the solution using an <a href="http://msdn.microsoft.com/en-us/library/z5z9kes2%28VS.71%29.aspx">implicit user-defined type conversion operator</a>:</p>
<pre class="brush:csharp">public class TeamBuilder
{
    private string name;
    private string nickName;
    private Color shirtColor;
    private string homeTown;
    private string ground;

    public TeamBuilder CreateTeam(string name)
    {
        this.name = name;
        return this;
    }

    public TeamBuilder WithNickName(string nickName)
    {
        this.nickName = nickName;
        return this;
    }

    public TeamBuilder WithShirtColor(Color shirtColor)
    {
        this.shirtColor = shirtColor;
        return this;
    }

    public TeamBuilder FromTown(string homeTown)
    {
        this.homeTown = homeTown;
        return this;
    }

    public TeamBuilder PlayingAt(string ground)
    {
        this.ground = ground;
        return this;
    }

    // CONVERSION OPERATOR
    public static implicit operator Team(TeamBuilder tb)
    {
        return new Team(
            tb.name,
            tb.nickName,
            tb.shirtColor,
            tb.homeTown,
            tb.ground);
    }
</pre>
<p>This allows you to create new teams in a more natural way as follows:</p>
<pre class="brush:csharp">TeamBuilder tb = new TeamBuilder();

Team team3 = tb.CreateTeam("Chelsea")
    .WithNickName("The blues")
    .WithShirtColor(Color.Blue)
    .FromTown("London")
    .PlayingAt("Stamford Bridge");
</pre>
<p>The above solution, albeit quite simple, is a good starting point. To make it ready for real-world code, you should making it more robust with some error checking (what happens if I omit some call from the chain? If I pass an invalid argument? Etc&#8230;).</p>
<p>More, you might want to hide the actual implementation from the clients and extract an interface or abstract class from the concrete <code>TeamBuilder</code>. This is left to the reader as an excercise <img src='http://stefanoricciardi.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http://stefanoricciardi.com/2010/04/14/a-fluent-builder-in-c/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://stefanoricciardi.com/2010/04/14/a-fluent-builder-in-c/" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<p>    <a rev="vote-for" href="http://dotnetshoutout.com/Submit?url=http://stefanoricciardi.com/2010/04/14/a-fluent-builder-in-c/"><br />
        <img alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http://stefanoricciardi.com/2010/04/14/a-fluent-builder-in-c/" style="border:0px"/><br />
    </a></p>

]]></content:encoded>
			<wfw:commentRss>http://stefanoricciardi.com/2010/04/14/a-fluent-builder-in-c/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Comparing Floating Point Numbers</title>
		<link>http://stefanoricciardi.com/2010/03/02/comparing-floating-point-numbers/</link>
		<comments>http://stefanoricciardi.com/2010/03/02/comparing-floating-point-numbers/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 13:29:00 +0000</pubDate>
		<dc:creator>stefanoricciardi</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://stefanoricciardi.wordpress.com/?p=807</guid>
		<description><![CDATA[Floating Points and Rounding Errors. Working with floating points number can sometimes provide some (un)pleasant surprise, since many real numbers do not have a finite representation and this can lead to rounding errors. If you need to refresh your knowledge (and have some time to spare), you can find a great treatment in the article [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fstefanoricciardi.com%2F2010%2F03%2F02%2Fcomparing-floating-point-numbers%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fstefanoricciardi.com%2F2010%2F03%2F02%2Fcomparing-floating-point-numbers%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<h2>Floating Points and Rounding Errors.</h2>
<p>Working with floating points number can sometimes provide some (un)pleasant surprise, since many real numbers do not have a finite representation and this can lead to rounding errors. </p>
<p>If you need to refresh your knowledge (and have some time to spare), you can find a great treatment in the article <a href="http://docs.sun.com/source/806-3568/ncg_goldberg.html">What Every Computer Scientist Should Know About Floating-Point Arithmetic</a>:</p>
<blockquote><p>
Squeezing infinitely many real numbers into a finite number of bits requires an approximate representation. Although there are infinitely many integers, in most programs the result of integer computations can be stored in 32 bits. In contrast, given any fixed number of bits, most calculations with real numbers will produce quantities that cannot be exactly represented using that many bits. Therefore the result of a floating-point calculation must often be rounded in order to fit back into its finite representation. This rounding error is the characteristic feature of floating-point computation.
</p></blockquote>
<p>A small example should make the problem clearly visible:</p>
<pre class="brush:csharp">
class Program
{
    static void Main(string[] args)
    {
        double a = 22.4;
        double b = a / 131;

        double c = 0;
        for (int i = 0; i < 131; i++)
        {
            c += b;
        }

        Console.WriteLine("Are they equal?: {0}", a == c);
        Console.WriteLine("Difference (a - c) is {0} ", a - c);
    }
}
</pre>
<p>Here we are taking a double (a), diving it by 131 and then creating a new number (c) by adding the result of that division 131 times. By pure math, a and c should be equal. If you try this small program yourself, this is the output that you would get:</p>
<pre>
Are they equal?: False
Difference (a - c) is -4,9737991503207E-14
</pre>
<p>As you can see, the result is not what you might expect, and it's affected by a rounding error that is building up every time b is added to the partial result c.</p>
<p>Note that this is dependent on the number that I have chosen. If you substitute 131 with 5, you will not experience this problem.</p>
<h2>Your Own Comparer</h2>
<p>Sometimes this behavior might annoy you, especially when you don't need such a high precision and a “rough” equality is all you need. A typical situation is unit testing an algorithm against some expected result: your assertions may fail because of a rounding error, even though the logic of your algorithm is formally correct.</p>
<p>In such a case, you might want to implement your own comparer. A desirable property for such a comparer is a threshold value: if the difference between two floating points is <em>below</em> that threshold they are considered equal.</p>
<p>All you need is to implement the .NET interface <code><a href="http://msdn.microsoft.com/en-us/library/ms132151.aspx">IEqualityComparer</a></code><a href="http://msdn.microsoft.com/en-us/library/ms132151.aspx"> </a>interface.</p>
<pre class="brush:csharp">
class DoubleComparer : IEqualityComparer
{
    private readonly double threshold;

    public DoubleComparer(double threshold)
    {
        this.threshold = threshold;
    }

    public bool Equals(double x, double y)
    {
        return Math.Abs(x - y) < this.threshold;
    }

    public int GetHashCode(double obj)
    {
       return obj.GetHashCode();
    }
}
</pre>
<p>I have created my own comparer to use in my unit tests. I only have to implement 2 methods: <code>Equals()</code> and <code>GetHashCode()</code>.</p>
<p>I don't care much for the actual algorithm of the hashcode implementation, so I am reusing <code>double</code> own algorithm.</p>
<p>Instead, I have applied my own logic to the Equals method: to me, two doubles are equal if the absolute value of their difference is within a given threshold (which I can pass to the comparer in the constructor).</p>
<h2>The Comparer In Use</h2>
<p>Suppose I have an algorithm to calculate the histogram of a given collection of doubles, and a unit test to validate the calculation against a collection of expected results.</p>
<p>In the example below, <em>samples</em> are the input values which I want to create the histogram for, and <em>expectedBreaks</em> is a sequence containing the left and right limits of the bins of the histogram (in the example I am requiring 5 bins, so the number of breaks is 5 + 1 = 6).</p>
<pre class="brush:csharp">
var p = new HistogramProvider();
double[] samples = { 20, 12, 4, 22, 19, 24, 9, 5, -12.2, 13, 0 };
double[] expectedBreaks = { -12.2, -4.96, 2.28, 9.52, 16.76, 24 };

var histogram = p.CreateHistogram(samples, 5);

Assert.IsTrue(expectedBreaks.SequenceEqual<double>(
                       histogram.Breaks,
                       new DoubleComparer(0.01)));
</pre>
<p>I have figured out the threshold to pass (0.01) based on the relative size of the doubles under analysis. Of course, you should use your own judgement to come up with a sensible threshold according of the range of your input data.</p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fstefanoricciardi.com%2f2010%2f03%2f02%2fcomparing-floating-point-numbers%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fstefanoricciardi.com%2f2010%2f03%2f02%2fcomparing-floating-point-numbers%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<p><a rev="vote-for" href="http://dotnetshoutout.com/Comparing-Floating-Point-Numbers"><img alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fstefanoricciardi.com%2F2010%2F03%2F02%2Fcomparing-floating-point-numbers%2F"></a></p>

]]></content:encoded>
			<wfw:commentRss>http://stefanoricciardi.com/2010/03/02/comparing-floating-point-numbers/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Generics With Type Uknown At Compile Time</title>
		<link>http://stefanoricciardi.com/2010/02/18/generics-with-type-uknown-at-compile-time/</link>
		<comments>http://stefanoricciardi.com/2010/02/18/generics-with-type-uknown-at-compile-time/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 20:32:20 +0000</pubDate>
		<dc:creator>stefanoricciardi</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[generics]]></category>
		<category><![CDATA[reflection]]></category>

		<guid isPermaLink="false">http://stefanoricciardi.com/?p=773</guid>
		<description><![CDATA[The following is an example of a service containing both generic method calls and generic types. public interface IContainer&#60;T&#62; { IEnumerable&#60;IProperty&#60;T&#62;&#62; Properties { get; } } public interface IPropertyService { IContainer&#60;T&#62; GetProperties&#60;T&#62;(string propertyCode); } Now suppose that you don&#8217;t know the actual type of the data until runtime (possibly because the type is retrieved from [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fstefanoricciardi.com%2F2010%2F02%2F18%2Fgenerics-with-type-uknown-at-compile-time%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fstefanoricciardi.com%2F2010%2F02%2F18%2Fgenerics-with-type-uknown-at-compile-time%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>The following is an example of a service containing both generic method calls and generic types.</p>
<pre class="brush:csharp">
public interface IContainer&lt;T&gt;
{
    IEnumerable&lt;IProperty&lt;T&gt;&gt; Properties { get; }
}

public interface IPropertyService
{
    IContainer&lt;T&gt; GetProperties&lt;T&gt;(string propertyCode);
}
</pre>
<p>Now suppose that you don&#8217;t know the actual type of the data until runtime (possibly because the type is retrieved from a DB or from some other service). You need a way to interact with these generics, and <a href="http://msdn.microsoft.com/en-us/library/system.reflection.aspx">Reflection </a>can help you here.</p>
<p>Let&#8217;s assume that you have managed to get the <code>Type</code> of the data that you are handling (such as <code>string</code>, <code>decimal</code>, <code>double</code>, etc&#8230;) and that you have a concrete implementation of the <code>IPropertyService</code> (perhaps through Dependency Injection).</p>
<p>Once you have that, you can invoke the <code>GetProperty</code> method in the following way:</p>
<pre class="brush:csharp">
Type type = // ... this is the actual runtime type
IPropertyService service = // ... this is an instance of the service

Type serviceType = typeof(IPropertyService);
MethodInfo getPropertiesInfo =
    serviceType.GetMethod(&quot;GetProperties&quot;, new Type[] { typeof(string) });

if (getPropertiesInfo == null)
{
    // Uh-oh.... has the interface changed after we wrote this? Throw an exception...
}

Type[] genericArguments = { type }; // we only have one generic argument (&lt;t&gt;)
MethodInfo getPropertiesMethodInfo =
    getPropertiesInfo.MakeGenericMethod(genericArguments);

// Finally invoke the method to search for a price
var propertiesContainer =
    getPropertiesMethodInfo.Invoke(service, new object[] { &quot;price&quot; });
</pre>
<p>As you can see are quite a few steps to be performed, but at the end, through reflection, you end up with a container filled with all the objects that you have required.</p>
<p>Now assume that you want to access to the single properties contained in the IContainer. You need some way to invoke the C# property <code>Properties</code>. defined on <code>IContainer</code>. Similarly to the <a href="http://msdn.microsoft.com/en-us/library/system.reflection.methodinfo.aspx">MethodInfo</a> class, System.Reflection has a <a href="http://msdn.microsoft.com/en-us/library/system.reflection.propertyinfo.aspx">PropertyInfo </a>class that you can use to work with Properties.</p>
<p>The following solution, despite compiling fine, will not work at run-time:</p>
<pre class="brush:csharp">
PropertyInfo containerInfo = typeof(IContainer&lt;&gt;).GetProperty(&quot;Properties&quot;); // WRONG!!!
if (containerInfo == null)
{
    // the interface has changed. Throw an exception
}

var properties = containerInfo.GetValue(container, null) as IEnumerable;
</pre>
<p>If you try to run this, you will be greeted by the following exception: <em>Late bound operations cannot be performed on types or methods for which ContainsGenericParameters is true.</em></p>
<p>After scratching my head for a while, I realized that I should have first created a generic type at run-time before retrieving the <code>PropertyInfo</code>:</p>
<pre class="brush:csharp">
Type containerType = typeof(IContainer&lt;&gt;).MakeGenericType(type);
PropertyInfo containerInfo = containerType.GetProperty(&quot;Properties&quot;);
if (containerInfo == null)
{
    // the interface has changed. Throw an exception
}

var properties = containerInfo.GetValue(container, null) as IEnumerable;
</pre>
<p>At this point I have a collection of <code>IProperties</code> which I can enumerate through. If needed, since the types in this collection are also generic, I need to repeat the process above until I reach a fundamental type (such as <code>string</code>, <code>double</code>, etc&#8230;).</p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fstefanoricciardi.com%2f2010%2f02%2f18%2fgenerics-with-type-uknown-at-compile-time%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fstefanoricciardi.com%2f2010%2f02%2f18%2fgenerics-with-type-uknown-at-compile-time%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<p><a rev="vote-for" href="http://dotnetshoutout.com/Generics-With-Type-Uknown-At-Compile-Time-Stefano-Ricciardis-Blog"><img alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fstefanoricciardi.com%2F2010%2F02%2F18%2Fgenerics-with-type-uknown-at-compile-time%2F"></a></p>

]]></content:encoded>
			<wfw:commentRss>http://stefanoricciardi.com/2010/02/18/generics-with-type-uknown-at-compile-time/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>See Your XML Docs As You Type With CR Documentor</title>
		<link>http://stefanoricciardi.com/2010/01/22/see-your-xml-docs-as-you-type-with-cr-documentor/</link>
		<comments>http://stefanoricciardi.com/2010/01/22/see-your-xml-docs-as-you-type-with-cr-documentor/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 19:39:29 +0000</pubDate>
		<dc:creator>stefanoricciardi</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Documentor]]></category>
		<category><![CDATA[Ghost-Doc]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>

		<guid isPermaLink="false">http://stefanoricciardi.wordpress.com/?p=701</guid>
		<description><![CDATA[Introduction Almost 10 years ago now I used to be a Java developer in Motorola. After a long hiatus in the embedded systems and a job change, I have come back to enterprise development, this time in .Net. I remembered that in the good ol’ days it required 2 steps to see the final rendering [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fstefanoricciardi.com%2F2010%2F01%2F22%2Fsee-your-xml-docs-as-you-type-with-cr-documentor%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fstefanoricciardi.com%2F2010%2F01%2F22%2Fsee-your-xml-docs-as-you-type-with-cr-documentor%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<h3>Introduction</h3>
<p>Almost 10 years ago now I used to be a Java developer in Motorola. After a long hiatus in the embedded systems and a job change, I have come back to enterprise development, this time in .Net.</p>
<p>I remembered that in the good ol’ days it required 2 steps to see the final rendering of the XML documentation: firing javadoc (usually from within an ANT task) and the open up the content in a browser.</p>
<p>I was quite surprised to see that in the .Net area seeing the final output of the docs was not as straightforward as I hoped for. Yes, there was <a href="http://ndoc.sourceforge.net/">NDoc</a> to parse the XML, but its development stopped around 2005 and it’s doesn’t support anything beyond C# 2.0. There’s also <a href="http://www.codeplex.com/Sandcastle">Sandcastle</a>, but to make it work for me it has required a few downloads and a bit of tweaking here and there. And integrating it into my NAnt task had not been that easy either. But somehow in the end I have pulled that out.</p>
<p>Therefore I have been pleasantly surprised when I met <strong>CR Documentor, </strong>a little plug-in for visual studio that let’s you see your XML documentation <em>as you write it</em>. It’s almost like having a WYSIWYG editor, without having to launch Sandcastle, wait for the complete build, and open up the browser.</p>
<h3>Installation</h3>
<ul>
<li><a href="http://code.google.com/p/cr-documentor/"><img style="display:inline;border-width:0;margin:0;" title="cr_documentor-logo" src="http://stefanoricciardi.files.wordpress.com/2010/01/cr_documentorlogo.gif" border="0" alt="cr_documentor-logo" width="100" height="102" align="right" /></a>Requirements:
<ul>
<li>Visual Studio 2005 or greater (I am pretty confident that you need at least a Professional version as opposed to Express). I am running it on Visual Studio Team System 2008, not sure whether it works also on 2010.</li>
<li>The DXCore plugin framework from DevExpress. Possibly the best (and only?) way to get it is to get through the excellent free <a href="http://www.devexpress.com/Products/Visual_Studio_Add-in/CodeRushX/">CodeRush Xpress for C# and VB</a></li>
</ul>
</li>
<li>Download the plugin: CR Documentor is hosted at Google Code at <a href="http://code.google.com/p/cr-documentor/">this link</a>.</li>
<li>Copy the dll in your DX-Core plugin-folder (<tt>C:\Users\&lt;username&gt;\Documents\DevExpress\IDE Tools\Community\PlugIns</tt>)</li>
<li>Restart Visual Studio</li>
</ul>
<h3>Usage</h3>
<ol>
<li>CR Documentor adds itself in the right click menu, close to the bottom. From the submenu, choose “Show CR_Documentor window”.<a href="http://69.175.59.226/~stefano3/blog/wp-content/uploads/2010/01/cr_documentor1.png"><img style="display:inline;margin-left:0;margin-right:0;border-width:0;" title="CR_documentor-1" src="http://69.175.59.226/~stefano3/blog/wp-content/uploads/2010/01/cr_documentor1_thumb.png" border="0" alt="CR_documentor-1" width="244" height="212" /></a></li>
<li>A new window opens up in floating mode (I prefer to dock-it to the right side together with my solution explorer and luckily the plug-in remembers this choice every time I open the window after closing it and at startup).<a href="http://69.175.59.226/~stefano3/blog/wp-content/uploads/2010/01/image.png"><img style="display:inline;border-width:0;" title="image" src="http://69.175.59.226/~stefano3/blog/wp-content/uploads/2010/01/image_thumb.png" border="0" alt="image" width="244" height="127" /></a></li>
<li>Now every time your cursor is on an XML doc, you can see the preview in the Documentor window. See for example when I put the cursor on the XML doc of a class: I get a complete picture of the documentation for that class and its methods all in real time.<br />
<a href="http://stefanoricciardi.files.wordpress.com/2010/01/image1.png"><img style="display:inline;border-width:0;" title="image" src="http://69.175.59.226/~stefano3/blog/wp-content/uploads/2010/01/image_thumb1.png" border="0" alt="image" width="229" height="244" /></a></li>
<li>There are a few other features that I don’t use very often. All of them are accessible by the right-click content sensitive menu:
<ul>
<li>Expand/Collapse all XML comments in the editor</li>
<li>Insert XML docs templates (<a href="http://stefanoricciardi.com/2009/06/19/must-have-vs-2008-free-plug-ins-2-ghost-doc/">I prefer to use GhostDoc for that</a>).</li>
<li></li>
</ul>
</li>
</ol>
<h3>Configuration</h3>
<p>Like all DXCore plugins, you can access to the configuration by pressing ALT+CTRL+SHIFT+O combination. I like to check all my options to Sandcastle because that’s the tool that I will be using to create the final XML documentation.</p>
<p><a href="http://69.175.59.226/~stefano3/blog/wp-content/uploads/2010/01/image2.png"><img style="display:inline;border-width:0;" title="image" src="http://69.175.59.226/~stefano3/blog/wp-content/uploads/2010/01/image_thumb2.png" border="0" alt="image" width="244" height="161" /></a></p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fstefanoricciardi.com%2f2010%2f01%2f22%2fsee-your-xml-docs-as-you-type-with-cr-documentor%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fstefanoricciardi.com%2f2010%2f01%2f22%2fsee-your-xml-docs-as-you-type-with-cr-documentor%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<p><a rev="vote-for" href="http://dotnetshoutout.com/See-Your-XML-Docs-As-You-Type-With-CR-Documentor-Stefano-Ricciardis-Blog"><img style="border:0;" src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fstefanoricciardi.com%2F2010%2F01%2F22%2Fsee-your-xml-docs-as-you-type-with-cr-documentor%2F" alt="Shout it" /></a></p>
<p><!-- AddThis Button BEGIN --></p>
<p><a href="http://www.addthis.com/bookmark.php?v=250"><img style="border-width:0;" src="http://s7.addthis.com/static/btn/lg-share-en.gif" alt="Bookmark and Share" width="125" height="16" /></a></p>
<div id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:e6ceeafa-fe5c-4bd6-a48d-325da43e5abc" class="wlWriterSmartContent" style="display:inline;float:none;margin:0;padding:0;">Technorati Tags: <a rel="tag" href="http://technorati.com/tags/Programming">Programming</a>,<a rel="tag" href="http://technorati.com/tags/C%23">C#</a>,<a rel="tag" href="http://technorati.com/tags/visual+Studio+2008" class="broken_link">visual Studio 2008</a>,<a rel="tag" href="http://technorati.com/tags/Tools">Tools</a></div>

]]></content:encoded>
			<wfw:commentRss>http://stefanoricciardi.com/2010/01/22/see-your-xml-docs-as-you-type-with-cr-documentor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Singleton Service Locator Pattern</title>
		<link>http://stefanoricciardi.com/2009/10/29/a-singleton-service-locator-pattern/</link>
		<comments>http://stefanoricciardi.com/2009/10/29/a-singleton-service-locator-pattern/#comments</comments>
		<pubDate>Thu, 29 Oct 2009 13:40:47 +0000</pubDate>
		<dc:creator>stefanoricciardi</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Design and Patterns]]></category>
		<category><![CDATA[OOP]]></category>

		<guid isPermaLink="false">http://stefanoricciardi.net/?p=543</guid>
		<description><![CDATA[This is the third post of a series on the Service Locator pattern. In the first post I described how to create a basic service locator for your C# application, while in the second post I introduced lazy initialization of the services. We now add another piece to our puzzle, transforming the Service Locator class [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fstefanoricciardi.com%2F2009%2F10%2F29%2Fa-singleton-service-locator-pattern%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fstefanoricciardi.com%2F2009%2F10%2F29%2Fa-singleton-service-locator-pattern%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>This is the third post of a series on the Service Locator pattern. In the <a href="http://stefanoricciardi.com/2009/09/25/service-locator-pattern-in-csharpa-simple-example/">first post</a> I described how to create a basic service locator for your C# application, while in the <a href="http://stefanoricciardi.com/2009/10/13/service-locator-pattern-in-c-with-lazy-initialization/">second post</a> I introduced lazy initialization of the services.</p>
<p>We now add another piece to our puzzle, transforming the Service Locator class into a <a href="http://en.wikipedia.org/wiki/Singleton_pattern">singleton</a>.</p>
<h1>The Singleton Pattern</h1>
<p>The singleton is arguably the most known and controversial design pattern. Some say <a href="http://c2.com/cgi/wiki?SingletonsAreGood">singletons are good</a>, some says <a href="http://c2.com/cgi/wiki?SingletonsAreEvil">singletons are evil</a>. Eric Gamma himself (one of the <a href="http://c2.com/cgi/wiki?GangOfFour">Gang Of Four</a>) in a recent <a href="http://www.informit.com/articles/article.aspx?p=1404056">interview</a> stated that (emphasis added):</p>
<blockquote><p>When discussing which patterns to drop, we found that we still love them all. (Not really—<strong>I&#8217;m in favor of dropping Singleton. Its use is almost always a design smell.</strong>)</p></blockquote>
<p>I don&#8217;t have a strong opinion either way; I tend to use it sparingly and in the following code I will show how to apply this pattern to the service locator. There are already countless blogs discussing the pros and the cons of the singleton pattern, therefore I won&#8217;t discuss about it any further.</p>
<h1>The Singleton Service Locator</h1>
<p>The following was our initial implementation (other details of the classes have been removed for clarity). The constructor was <em>internal</em>, allowing all potential clients from within the assembly to invoke it. Clients could either pass around a reference to the created service locator, or instantiate new instances each time:</p>
<pre class="brush:csharp">
internal class ServiceLocator : IServiceLocator
{
    // a map between contracts -&gt; concrete implementation classes
    private IDictionary&lt;Type, Type&gt; servicesType;

    // a map containing references to concrete implementation already instantiated
    // (the service locator uses lazy instantiation).
    private IDictionary&lt;Type, object&gt; instantiatedServices;

    internal ServiceLocator()
    {
        this.servicesType = new Dictionary&lt;Type, Type&gt;();
        this.instantiatedServices = new Dictionary&lt;Type, object&gt;();

        this.BuildServiceTypesMap();
    }

    // rest of the methods
 }
</pre>
<p>To implement the singleton pattern, we make the constructor <em>private</em> and provide clients with a static method through which we can retrieve an instance of the service.</p>
<p>Note how the creation of the single instance of the ServiceLocator class is itself lazy and thread safe. There are a few variations on the theme when it comes to singleton thread safe initialization (see for example <a href="http://www.yoda.arachsys.com/csharp/singleton.html">this post</a> by Jon Skeet).</p>
<pre class="brush:csharp">
internal class ServiceLocator : IServiceLocator
{
        // a map between contracts -&gt; concrete implementation classes
        private IDictionary&lt;Type, Type&gt; servicesType;
        private static readonly object TheLock = new Object();

        private static IServiceLocator instance;

        // a map containing references to concrete implementation already instantiated
        // (the service locator uses lazy instantiation).
        private readonly IDictionary&lt;Type, object&gt; instantiatedServices;

        private ServiceLocator()
        {
            this.servicesType = new Dictionary&lt;Type, Type&gt;();
            this.instantiatedServices = new Dictionary&lt;Type, object&gt;();

            this.BuildServiceTypesMap();
        }

        public static IServiceLocator Instance
        {
            get
            {
                lock (TheLock) // thread safety
                {
                    if (instance == null)
                    {
                        instance = new ServiceLocator();
                    }
                }

                return instance;
            }
        }

        // rest of the methods
 }
</pre>
<p>Clients will now simply invoke the <code>GetService()</code> method through the singleton instance, without having to create a new object each time:</p>
<pre class="brush:csharp">
IServiceA service = ServiceLocator.Instance.GetService&lt;IUniverseFileServiceAdapter&gt;();
</pre>
<p><!-- Kick it BEGIN --><br />
<a href="http://www.dotnetkicks.com/kick/?url=http%3A%2F%2Fstefanoricciardi.com%2F2009%2F10%2F29%2Fa-singleton-service-locator-pattern"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3A%2F%2Fstefanoricciardi.com%2F2009%2F10%2F29%2Fa-singleton-service-locator-pattern" border="0" alt="kick it on DotNetKicks.com" /></a><br />
<!-- Kick it END --></p>
<p>    <a rev="vote-for" href="http://dotnetshoutout.com/Submit?url=http://stefanoricciardi.com/2009/10/29/a-singleton-service-locator-pattern/"><br />
        <img alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http://stefanoricciardi.com/2009/10/29/a-singleton-service-locator-pattern/"><br />
    </a></p>
<p><!-- AddThis Button BEGIN --></p>
<p><a href="http://www.addthis.com/bookmark.php?v=250"><img style="border:0;" src="http://s7.addthis.com/static/btn/lg-share-en.gif" alt="Bookmark and Share" width="125" height="16" /></a></p>
<p><!-- AddThis Button END --></p>
<div id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:e6ceeafa-fe5c-4bd6-a48d-325da43e5abc" style="display:inline;float:none;margin:0;padding:0;">Technorati Tags: <a rel="tag" href="http://technorati.com/tags/Programming">Programming</a>, <a rel="tag" href="http://technorati.com/tags/C%23">C#</a>, <a rel="tag" href="http://technorati.com/tags/design">Design</a>, <a rel="tag" href="http://technorati.com/tags/ood">OOD</a></div>

]]></content:encoded>
			<wfw:commentRss>http://stefanoricciardi.com/2009/10/29/a-singleton-service-locator-pattern/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

