I just started looking at .NET 3.5, so please forgive me if you asked this question before. I struggle with the decent use of extension methods, in that I just downloaded the suteki shop to host MVC e-commerce. This project has a fairly standard repository template that extends IRepository.
To extend the basic functionality opened by this interface, ie extension methods are used:
public static class CategoryRepositoryExtensions { public static Category GetRootCategory(this IRepository<Category> categoryRepository) { return categoryRepository.GetById(1); } }
Now everything is fine and good, but the interfaces, as far as I know, act like contracts for objects that implement them.
The fact that the repository was paired suggests an attempt at an agnostic approach to the data layer. However, if I created my own data layer, I would be confused as to what extension methods I would have to create to make sure I met the contract requirement that I have for classes that implement my repository classes.
It seems like an older way to create an IRepository and then an extension that allows you to see much better what is required, for example.
ICategoryRepoitory : IRepository<Category> { Category GetRootCategory(); }
So, I think my question is, does using Extention methods seem wrong to anyone else? If not, why? Should I not moan about it?
EDIT:
The above example seems to be a good example of why extension methods can be very useful.
I believe that my problem is that certain features of data access implementation hovered in the extension method in the assembly of data access mechanisms.
Thus, if I changed it to another mechanism, I would have to create a similar extension method in this assembly.