3

I have a project and I follow Repository and UoW patterns. I also have a "service" layer which I also use as my BL layer.

Taking for example a Customer domain model, I might have information that I need to retrieve along with the customer, so in the customer repository class I have the following methods:

public CustomerModel Get(int id);
public IEnumerable<CustomerAddressModel> GetAddresses(int id);
public IEnumerable<CustomerOrderModel> GetOrders(int id);

The above methods make a standard db call in the relevant tables and are called by the service class.

Now I have additional methods that I need to the customer, such as:

public bool HasReminders(int id);
public bool ForwardedToDebtCollection(int id);
//etc...

These methods do not have specific tables but make a db call to different the relevant views.

I would like to keep db-specific code (especially SQL statements) within the repository layer. This is also because the service layer does not have references to EntityFramework and Dapper. These are solely used in the repository layer.

My question:

Should I add the additional methods to the repository layer and let the service layer call these methods, or should they be placed directly in the service layer as they are part of the business logic?

2

I am a proponent of keeping business logic out of the database, and that includes not having views that determines whether there are reminders on a customer.

This can in cases where there are lots of data and lots of concurrent users lead to poor performance. I find that decent caching of data solves this, but I do not work on very large data and under a big user load, so I've never really been in a situation where performance could not be attained.

Coming from that perspective I would not use a HasReminders(int id) method. I would use a GetReminders(int id) method. Similar I would load the data for the customer that contained the possible information on the customer being forwarded to debt collection.

This will have the advantage that you can display all reminders if the user wants them, the data is already loaded. Otherwise the user will have to go to a different view/page to have the reminders loaded.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.