The wages of sinRe-creating the Stored Procedure API in C#

time to read 5 min | 868 words

Originally posted at 3/10/2011

This time, this is a review of the Sharp Commerce application. Again, I have stumbled upon the application by pure chance, and I have very little notion about who wrote it. The problem is that this system seems to be drastically more complicated than it should be.

In this case, I want to look at the type of API that is exposed:

image

If this reminds you of the bad old days of having only Stored Procedure API available, that is not by chance. Far worst than that, however, is the call paths where this is used.

  • IEmailTemplateRepository.Get(EmailTemplateLookup) is implemented as
    public EmailTemplate Get(EmailTemplateLookup emailId)
    {
        return Get((int)emailId);
    }
    and is only used in:
    • EmailService.Get(EmailTemplateLookup) whose implementation is:
      public EmailTemplate GetEmail(EmailTemplateLookup template)
      {
          return emailTemplateRepository.Get(template);
      }
  • ICategoryRepository.GetParentCategories is only used from:
    • CategoryService.GetParentCategories which is implemented as:
      public IEnumerable<Category> GetParentCategories()
      {
          IEnumerable<Category> categories = categoryRepository.GetParentCategories();
      
          return categories;
      }
  • ICurrencyRepository.GetEnabledCurrencies is only used from:
    • CurrencyService.GetEnabledCurrencies which is implemented as:
      public IEnumerable<Currency> GetEnabledCurrencies()
      {
           return currencyRepository.GetEnabledCurrencies();
      }
  • For that matter, let us take a look at the entire CurrencyService class, shall we?

    public class CategoryService : ICategoryService
    {
        private readonly ICategoryRepository categoryRepository;
    
        public CategoryService(ICategoryRepository categoryRepository)
        {
            this.categoryRepository = categoryRepository;
        }
    
        public IList<Category> GetCategories()
        {
            return categoryRepository.GetAll();
        }
    
        public Category GetCategory(int id)
        {
            return categoryRepository.Get(id);
        }
    
        public void SaveOrUpdate(Category categoryModel)
        {
            categoryRepository.SaveOrUpdate(categoryModel);
        }
    
        public void Delete(Category category)
        {
            categoryRepository.Delete(category);
        }
    
        public IEnumerable<Category> GetParentCategories()
        {
            IEnumerable<Category> categories = categoryRepository.GetParentCategories();
    
            return categories;
        }
    }

    To be honest, I really don’t see the point.

    Now, just a hint on the next few posts, there are places where I think wrapping the usage of the NHibernate API was a good idea, even if I strongly disagree with how this was done.

    More posts in "The wages of sin" series:

    1. (24 Mar 2011) Hit that database one more time…
    2. (23 Mar 2011) Inverse leaky abstractions
    3. (22 Mar 2011) Proper and improper usage of abstracting an OR/M
    4. (21 Mar 2011) Re-creating the Stored Procedure API in C#
    5. (18 Mar 2011) Over architecture in the real world