レスキューへのインターフェイス!
次のようにインターフェイスを定義します。
// Why IEquatable<T>? Because you don't want identifiers that may not
// be able to prove that they're equal or not. Most commonly used
// types used as identifiers already implement IEquatable<T>. For example:
// int, Guid...
public interface ICanBeIdentifiable<TId> where TId : IEquatable<TId>
{
TId Id { get; }
}
を...そして、あまりにも次のようにリポジトリのインターフェース署名を変更します。
public interface IRepository<T> where T : class, ICanBeIdentifiable<Guid>
...
...またはあなたは絶対にドアを開く場合任意の識別子タイプ:
public interface IRepository<TId, T>
where TId : IEquatable<TId>
where T : class, ICanBeIdentifiable<TId>
主な欠点は、ドメインオブジェクトがまったく新しいインターフェースですが、それはその価値があります。