I understand that empty interfaces are likely to be a code smell. I find myself using one, and I am unable to find what the design flaw is.
I have a DBServer abstract class, called Server
public abstract class Server
{
protected ICustomerRepository CustomerRepository;
public string HostName{ get; }
protected Server(string HostName)
{
this.HostName = HostName;
}
protected GetCustomers()
{
return CustomerRepository.GetCustomers();
}
}
Since I use two DB Engines, say A and B, I have two implemetations.
Implementation for A requires a ICustomerRepository
for A, say ACustomerRepository
.
However, in order to be able to unit-test the implementation for A, I will use an interface IACustomerRepository
and inject the dependency.
The problem is that this interface is empty.
public interface ICustomerRepository
{
string HostName { get; set; }
IEnumerable<ICustomer> GetCustomers();
}
public interface IACustomerRepository:ICustomerRepository
{
}
This interface implements the logic to retrive data from the DB for engine A:
class ACustomerRepository : IACustomerRepositoryRepository
{
public IEnumerable<ICustomer> GetCustomers()
{
//Data retrieval logic...
}
}
This implementation is injected into the Server
implementation for A, using Unity:
public class ServerA: Server
{
public ServerA (
string HostName,
IACustomerRepository ACustomerRepository):
base(HostName)
{
CustomerRepository = ACustomerRepository;
ACustomerRepository.HostName = HostName;
}
}
Unity config:
container.RegisterType<IACustomerRepository, ACustomerRepository>();
I have read about 'marker interfaces', but I am not really sure it applies here.
Could you help me identify the underlying issue, so that I can fix this code smell?