I will give you a little context first
My company chose a design approach for our applications (windows services) to allow more code reuse through centralization (internal nuget repo) of core common code. This makes it easier to maintain test and build new services up until now..
Essentially all of the services use SqlDependency to get notified from the database that work is available for them to process. When the SqlDependency object gets notified it calls the following
public interface IRequestReceiver : IDisposable
{
IEnumerable<IRequest> GetRequests(int maxRequestNumber);
}
which is implemented independently by each application and therefore allows each application to retrieve it's requests from it's known location and process them etc.
Now for the problem
This all worked well up until recently as all the IRequest s were very similar and so we could use a single IRequest interface in common code but put different processing logic in each. unfortunately I have been assigned the task of building a new service whose implementation of IRequest differs significantly from all the previous ones before it.
My issue is I cannot alter IRequest as it is used by multiple live services and I am obliged to stick within the design pattern of our existing services yet I have to include serveral more properties in IRequest that have not existed before and have no relevance to the existing services.
And finally my question
Given I know that an interface is a contract and should therefore not be overloaded, how would I overload or expand or even substitute the existing IRequest interface for just this new service without exposing irrelevant properties to the existing services.
The following are samples of the existing and new IRequest interface
Existing
public interface IRequest
{
int Id { get; }
string CreatedBy { get; }
bool IsActive { get; set; }
DateTimeOffset CreatedDateTime { get; set; }
string LastUpdatedBy { get; set; }#
DateTimeOffset LastUpdatedDateTime { get; set; }
IRequestDetail Detail { get; }
bool Process(CancellationToken token);
}
New
public interface IRequest
{
int Id { get; }
string CreatedBy { get; }
bool IsActive { get; set; }
DateTimeOffset CreatedDateTime { get; set; }
string LastUpdatedBy { get; set; }#
DateTimeOffset LastUpdatedDateTime { get; set; }
int NotificationId { get; set; }
int StatusId { get; set; }
string StatusCode { get; set; }
string StatusMessage { get; set; }
string Destination { get; set; }
string BusinessProcessCode { get; set; }
string MsgType { get; set; }
string MessageId { get; set; }
bool Process(CancellationToken token);
}
As you can see it's just additional properties but I would not like to start introducing these to the existing IRequest interface.
Thank you