RepositoryProvider provider = new RepositoryProvider();
IRepository<int> repo = provider.GetRepository<int>();
IList<IEntity<int>> list = repo.GetAll();
IEntity<int> entry = repo.Get(10);
interface IEntity<TId>
where TId : struct
{
TId Id { get; set; }
}
class Entity<TId> : IEntity<TId>
where TId : struct
{
public virtual TId Id { get; set; }
}
interface IRepository<TId>
where TId : struct
{
IEntity<TId> Get(TId id);
IList<IEntity<TId>> GetAll();
}
class Repo<TId> : IRepository<TId>
where TId : struct
{
public IEntity<TId> Get(ValueType id)
{
return default(Entity<TId>);
}
public IList<IEntity<TId>> GetAll()
{
return new List<IEntity<TId>>();
}
}
class RepositoryProvider
{
public IRepository<TId> GetRepository<TId>()
where TId : struct
{
return new Repo<TId>();
}
}