Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

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

DZone's Guide to

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

· ·
Free Resource

RavenDB vs MongoDB: Which is Better? This White Paper compares the two leading NoSQL Document Databases on 9 features to find out which is the best solution for your next project.  

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.

Get comfortable using NoSQL in a free, self-directed learning course provided by RavenDB. Learn to create fully-functional real-world programs on NoSQL Databases. Register today.

Topics:

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}