C
C#2y ago
Djinn

✅ Error while injecting generic interface

public class Repository<TId, TEntity> : IRepository<TId, TEntity> where TEntity : class
{
}
public class Repository<TId, TEntity> : IRepository<TId, TEntity> where TEntity : class
{
}
public interface IRepository<TId, TEntity> where TEntity : class
{
public Task<TEntity?> GetAsync(TId id);
public void Update(TEntity entity);
public void Delete(TEntity entity);
}
public interface IRepository<TId, TEntity> where TEntity : class
{
public Task<TEntity?> GetAsync(TId id);
public void Update(TEntity entity);
public void Delete(TEntity entity);
}
6 Replies
Thinker
Thinker2y ago
typeof(IRepository<,>)
Djinn
DjinnOP2y ago
oh god thank you
Florian Voß
Florian Voß2y ago
what excatly does this mean if we leave the generic types blank? I would have thought we do typeof(IRepository<TId, TEntity>) rather than typeof(IRepository<,>)
Thinker
Thinker2y ago
typeof(IRepository<,>) is the type of IRepository<TId, TEntity> without any of its parameters substituted. typeof(IRepository<TId, TEntity>) wouldn't work because TId and TEntity don't exist in that context
Florian Voß
Florian Voß2y ago
I think I understand, thank you
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server