samedi 12 janvier 2019

Switch between two repositories without user knowing

I have two properties that are the implementations of the same interface as follows:

ICarRepository CarRepository => server.CarRepository;

ICarRepository LocalCarRepository => localDB.CarRepository;

The server.CarRepository is missing a method that is only present in the localDB.Repository.

Instead of having seperate CarRepository and LocalCarRepository, I would like to conveniently call a single CarRepository and have it call the server.CarRepository first and will automatically switch to localDB.CarRepository when it's time to use the missing method3(). How can I do that?

The repositories are implemented as follows:

Server.CarRepository

public class CarRepository()
{
 public override void method1 ()
{
}
 public override void method2 ()
{
}

}

localDB.CarRepository

public class CarRepository()
{
 public virtual void method1 ()
{
}
 public virtual void method2 ()
{
}

 public void method3 ()
{
}
}

Aucun commentaire:

Enregistrer un commentaire