は、私は2つの複雑なクラスを持っています。このフォーマットBaseRepository.Get(へUserServiceの呼び出しのインスタンスを使用してオーバーライド財産紛争
public class UserRepository : BaseRepository<User>
{
public User Get(object id)
{
// Do specific user get including Role DP
return context.Users.Include("Role").Find(id);
}
}
public class UserService : BaseService<User>
{
public UserRepository repo = new UserRepository();
}
)の代わりUserRepository.Getの()。 、「ゲット
public class UserService : BaseService<User>
{
public UserRepository repo = new UserRepository();
public User Get(object id)
{
// This call to UserRepository.Get()
return repo.Get(id);
}
}
本当の問題は、私が29、「リポジトリ」を持っているということですので、私は追加「(int)を取得する」必要があります。
私がやりたいための唯一の方法は、このようなコードを複製しています(エンティティ)」、「保存(IEnumerable)」、「削除(エンティティ)」、「削除(IEnumerable)」などのコードを作成することができます。
BaseServiceのメソッドがrepoサブクラスを呼び出すように、BaseServiceのプロパティ "repo"を置き換える方法はありますか?
これの最も重要な部分は、DIが使いやすいことです。 –
私は本当にそれを行いますが、BaseRepositoryが "Get"を定義していればUseRepositoryのGetメソッドをオーバーライドできません。 BaseRepository.Get()はcontext.Setを返します。().Find(id)のみオーバーライドされたレポにこのメソッドがない場合。 –
Pythonizo
すべてありがとう。あなたの助けを借りてこれを解決し、BaseService.Get()に "virtual"を追加し、UserService.Get()に "オーバーライド"してください。 – Pythonizo