I am creating a simple messaging system in WCF and have implemented a minimal repository called MessageRepository.
It implements the contract IMessageRepository which is as follows:
using System;
using Violet.Model.Entities;
namespace Violet.Model.Abstract
{
public interface IMessageRepository
{
void DeliverMessage(string message_from, string message_to, string message_text);
}
}
Now I am confused as to whether to implement a separate service layer IService which invokes the model layer to interact with the database or to decorate the [ServiceContract] and [OperationContract] attributes on the IMessageRepository itself to minimize the layers in my application.
Which do you think is a better approach considering the application would grow over time?
In general it probably isn’t a good idea to expose your Data Access layer directly via a service. By creating a real service, and simply using your Repository, you have the flexibility to change them independently.
In general this is called the Single Responsibility Principle