リファクタリング中に、私はベースリポジトリからいくつかのデコレータに多くの機能を移動しようとしていました。何らかの理由で循環的な依存エラーが発生しています。完全なエラーは次のとおりです。シンプルインジェクタ:条件付きデコレータの周期的依存性エラー
設定が無効です。タイプ
IValidator<EntityDTO>
のインスタンスを作成できませんでした。構成が無効です。タイプEntityReaderExcludeDefaultEntitiesDecorator
は、それ自体に直接的または間接的に依存します。ここで
ここに私のIValidator
実装(流暢検証)
public class EntityValidator : IValidator<EntityDTO>
{
private readonly Data.IEntityReader _repo;
public EntityValidator(Data.IEntityReader repo)
{
_repo = repo;
RuleFor(e => e.GroupId).NotEqual(Guid.Empty)
.WithMessage("The selected group is invalid");
// more rules
}
}
は私のデコレータの実装が
public class EntityReaderExcludeDefaultEntitiesDecorator : IEntityReader
{
private readonly IEntityReader _reader;
public EntityReaderExcludeDefaultEntitiesDecorator(IEntityReader reader)
{
_reader = reader;
}
public EntityDTO FindById(Guid id)
{
var entity = _reader.FindById(id);
if (entity.Name.Equals(DocumentConstants.DEFAULT_ENTITY_NAME)) return null;
return entity;
}
// more methods
}
されており、ここに私の設定は、私は
container.RegisterConditional(typeof(IEntityWriter),
typeof(Service.Decorators.EntityWriterValidationDecorator),
context => context.Consumer.ServiceType != typeof(IGroupWriter));
// Do not use the decorator in the Document Writer (We need to find the 'None' entity
container.RegisterConditional(typeof(IEntityReader),
typeof(Service.Decorators.EntityReaderExcludeDefaultEntitiesDecorator),
context => context.Consumer.ServiceType != typeof(IDocumentWriter));
container.RegisterConditional<IEntityWriter, DocumentEntityWriter>(c => !c.Handled);
container.RegisterConditional<IEntityReader, DocumentEntityReader>(c => !c.Handled);
デコレータのためですより多くの情報を与えるだろうb私はこれがなぜなのか分かりません。デコレータを正しくセットアップしなかったのですか?
登録が正しく行われたため、IValidator
の登録が含まれていませんでした。このエラーは、IValidator<EntityDTO>
をインスタンス化できない理由は、EntityReaderExcludeDefaultEntitiesDecorator
に依存関係の問題があることを示しているようです。
他に必要な場合は、教えてください。
あなたの質問は混乱しています。あなたのコードが 'AbstractValidator'を示し、あなたの登録に 'IEntityReader'を登録している間、例外メッセージは' IValidator 'について話します。迷っています。 –
Steven
@スティーブン申し訳ありません。私は少しそれを更新しました。しかしIValidatorの登録は正しいです。その例外はデコレータに問題があると言われているので、IValidatorの登録はしていません。それは問題に関係しているようには見えなかった。 – Carson