循環参照問題が発生しているプロジェクトがあります。外部キーを解決するための循環参照と循環参照
私は "質問"オブジェクトのリストを持つことができる "イベント"オブジェクトを持っています 私は親 "イベント"を得ることができる "質問"オブジェクトを持っています。
エンティティフレームワークを使用していた場合は、フレームワークによって管理されますが、何らかの理由で、クライアントからEntity Frameworkを使用しないという要件があります。だから、私はEFの動作をシミュレートしようとしました。なぜなら、彼らは最終的に彼らの感覚に来て、私にEFを使用させると確信しています。ここで私はどのように進めるのですか。
public class EventRepository : AbstractRepository<Event>, IEventRepository
{
private readonly IQuestionRepository questionRepository;
public EventRepository(IContext context, IQuestionRepository questionRepository)
{
this.questionRepository = questionRepository;
}
public Event GetNew(DataRow row)
{
return new GeEvent(this.questionRepository) { // Load the event from the datarow }
}
public class GeEvent : Event
{
private readonly IQuestionRepository questionRepository;
public GeEvent(IQuestionRepository questionRepository)
{
this.questionRepository = questionRepository;
}
public override List<Question> Questions { get { return this.questionRepository.GetByIdEvent(this.IdEvent); }}
}
}
public class QuestionRepository : AbstractRepository<Question>, IQuestionRepository
{
private readonly IEventRepository eventRepository;
public QuestionRepository(IContext context, IEventRepository eventRepository)
{
this.eventRepository = eventRepository;
}
public Question GetNew(DataRow row)
{
return new GeQuestion(this.eventRepository) { // Load the question from the datarow }
}
public class GeQuestion : Question
{
private readonly IEventRepository eventRepository;
public GeQuestion(IEventRepository eventRepository)
{
this.eventRepository = eventRepository;
}
public override Event Event { get { return this.eventRepository.Get(this.IdEvent); }}
}
}
私が見ることができるように、私は "鶏や卵"の場合があります。 EventRepositoryを作成するには、QuestionRepositoryが必要で、QuestionRepositoryを作成するにはEventRepositoryが必要です。リポジトリ(とサービス)を正しくテストすることができないDependencyResolverを直接使用する以外に、どうすれば依存関係を管理して、外部キー "a la" Entity Frameworkをロードできますか?
私はサンプルを単純に保つために外部キーの「遅延読み込み」を簡略化しました。
BTW2何かを助けることができるのであれば、私はオートファックを使用します。
おかげ
お返事ありがとうございます。私は知っている、デザインは理想よりも小さいです。私は通常、Entity Frameworkを使用しますが、クライアントは、彼のプログラマーはすでに多くのことを学んでいるので、クライアントは絶対に反対しています.EFはこれまでのステップにすぎません...まあ... EFは、あなたは知っています...クライアントは王様です。 私は、クライアントがその感覚に来て私にEFを使用できるようになるまで、プロパティセッターに行く必要があると思います。 もう一度お返事ありがとうございます。 –