public static void main(string[] args)
IDbContext<Policy> dbcontext=new DbContext<Policy>();
IRepository<Policy> repository=new Repository<Policy>(dbcontext);
IRetry retry=new Retry();
PolicyRepository policyRep=new PolicyRepository(repository,retry);
Policy policy=new Policy{};
public class PolicyRepository:Repository<Policy>
private readonly IRetry _retry;
private readonly IRepository<Policy> _repository;
public PolicyRepository(IRepository<Policy> repository,IRetry retry)
public void save(Policy policy)
_retry.RetryOnFailure(()=>_repository.save(policy));
public class Retry: IRetry
public void RetryOnFailure(Action method ,int maxRetryCount=3)
while(initialCount>maxRetryCount)
throw new CommunicationException();
void RetryOnFailure(Action method,int maxRetryCount=3);
public class Repository<T> : IRepository<T> where T : class
private readonly IDbContext<T> _dbcontext;
_dbcontext=new DbContext<T>();
public Repository(IDbContext<T> dbcontext)
public void save(T Entity)
public interface IRepository<T> where T: class
public interface IDbContext<T> where T: class
public class DbContext<T> : IDbContext<T> where T: class
public void save(T Entity)
throw new Exception("test");