Repository pattern, one interface, multiple classes
<p>Given this code</p>

<pre><code>public interface IRepository&lt;T&gt;
{
    IQueryable&lt;T&gt; GetAll();
}
</code></pre>

<p>and this</p>

<pre><code>public class XmlProductRepository : IRepository&lt;Product&gt;
{
    private const string RelativePath = "~/data/products.xml";

    public string Filename { get; private set; }
    public XmlLoader Loader { get; private set; }

    public XmlProductRepository(HttpContextBase httpContext, XmlLoader loader)
    {
        Filename = httpContext.Server.MapPath(RelativePath);
        Loader = loader;
    }

    public IQueryable&lt;Product&gt; GetAll()
    {
        return Loader.Load&lt;ProductCollection&gt;(Filename).AsQueryable();
    }
}
</code></pre>

<p>what would you do to support many object types (apart from Product, additional 20 types like Plugin, Extension, Page, Section, etc.)? The implementation of the interface is the same for all object types, the only thing that is different is the RelativePath - we want to save different types into different folders organised by their type name, like so </p>

<ul>
<li>~/data/Product/...</li>
<li>~/data/Plugin/...</li>
<li>~/data/Page/...</li>
</ul>

<p><strong>So assume the only thing that changes is the path. Obviously we don't want to make a repository class for each one of those object types and copy the same code into each one of those classes.</strong> We just want to construct the path based on the object used for T.</p>
