1

ASP.NET MVC ソリューションには、各モデルのサービスを含むサービス レイヤーがあります。たとえば、DocumentModel の場合、ファクトリのように機能して保存を行う UoW クラスによってインスタンス化されるドキュメント サービスがあります。

public class UnitOfWork : IUnitOfWork
{
    private IRepositoryFactory _repositoryFactory;

    public UnitOfWork()
        : this(new RepositoryFactory())
    {

    }

    public UnitOfWork(IRepositoryFactory repositoryFactory)
    {
        _repositoryFactory = repositoryFactory;
    }

    private IDocumentService _DocumentService;
    public IDocumentService DocumentService
    {
        get
        {
            if (_DocumentService == null)
            {
                _DocumentService = new DocumentService(_repositoryFactory.DocumentRepository);
            }
            return _DocumentService;
        }
    }
}

ここで、DocumentService から 2 つまたは 3 つの他のリポジトリにアクセスできる必要があるとします。この新しいリポジトリを注入する最良の方法は何ですか? それらをコンストラクターに追加します (さらに別のリポジトリを追加する必要がある場合は面倒になる可能性があります)。または、必要なリポジトリに DocumentService でアクセスできるようにするリポジトリ ファクトリ (IRepositoryFactory) を挿入する必要があります。

4

0 に答える 0