Over a million developers have joined DZone.

The wages of sin: Re-creating the Stored Procedure API in C#

·

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.

Topics:

Published at DZone with permission of Ayende Rahien, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}