0

検索しただけで質問の答えが見つからなかったのはこれが初めてだと思います。

会社のシステムをリメイクするためにいくつかのプロトタイプを作成していて、理解できない問題にぶつかりました。

私は、合理的に一般的なDAO結合依存性注入を利用しようとしています。私が抱えている問題は、インターフェイスのメソッド内でクエリ定義にサードパーティのライブラリを使用したいということです。

public interface TestDAO<TEntity>
{
    /// <summary>
    /// get ALL the things
    /// </summary>
    /// <returns></returns>
    IEnumerable<TEntity> GetAll();

    /// <summary>
    /// Runs a supplied "where" clause and returns ALL the matched results
    /// </summary>
    IEnumerable<TEntity> FindAll(Specification<TEntity> specification);
}

この場合の仕様は、LinqSpecs と呼ばれるサードパーティ ライブラリのオブジェクトです。

これを行うことで、本質的にインターフェイスの実装でサードパーティのライブラリへの依存を強制していることを理解しています。

ライブラリの使用を控えることができることは理解していますが、可能であれば、少なくともその有用性を評価するまでは保持したいと考えています。

私の質問は、サードパーティの依存関係をドラッグせずにこれを行う方法(または同様の方法)があるかどうかです。

前もって感謝します。

4

2 に答える 2

0

拡張メソッドを追加できます。誰かが を使用する場合、さらに依存関係Specificationを取得します。LinqSpec

namespace Dao
{
    public interface TestDAO<TEntity>
    {
        /// <summary>
        /// get ALL the things
        /// </summary>
        /// <returns></returns>
        IEnumerable<TEntity> GetAll();
    }

namespace DaoExtensions
{
    public static class TestDAOExtensions
    {
        /// <summary>
        /// Runs a supplied "where" clause and returns ALL the matched results
        /// </summary>
        publicc static IEnumerable<TEntity> FindAll(this TestDAO<TEntity> dao, 
                                                    Specification<TEntity> specification);
    }
}
于 2012-08-21T03:27:27.530 に答える
0

実際には、インターフェイス TestDAO に、独自のインターフェイスの背後に隠すことができる検索フィルターを提供したいと考えています。

    public interface TestDAO<TEntity>
    {
        IEnumerable<TEntity> FindAll(ISearchFilter<TEntity> specification);
    }

    public interface ISearchFilter<TEntity>
    {
    }

searchfilter 実装には実際のデータが含まれています

    public class LinqSpecsSearchFilter : ISearchFilter<TEntity>
    {
        Specification<TEntity> specification;
    }

このアプローチの欠点は、LinqSpecs.Specification を取得するために、TestDAO 実装が醜いキャストを行わなければならないことです。

于 2012-08-21T05:05:07.043 に答える