0

私はレイヤー間を移動するビジネスレイヤーオブジェクト、ウィジェットを持っています。私は別のレイヤーに異なるプロパティのセットを公開したい。ここでコンパイラはコメントを読めば、それがどのように見えるかです:アセンブリによるアクセスではなくレイヤーによるアクセシビリティ

//bl.dll 

public abstract class Widget 
{ 
    //repo only 
    internal virtual Ppty_A {get;set;} //internal to implementation assembly of repo 

    //repo and service only 
    internal virtual Ppty_B {get;set;} //internal to implementation assemblies of repo/svc 

    //everyone inlcuding presentation 
    public virtual Ppty_C {get;set;} 
} 
public interface IWidgetService 
{ ... } } 
public interface IWidgetRepo 
{ ... } 
public class SimpleWidgetService : IWidgetService 
{ ... } 

//dal.dll 
using bl; 
public WidgetRepo 
{ ... } 

//presentation.dll 
using bl; 
public WidgetController 
{ 
    public WidgetController(IWidgetService ...) 
    ... 
} 

私の考えでは(私はまだこれをテストしていないと、それは半分しか問題を解決)これを行うことです。

//bl.dll 
public abstract class Widget 
{ 
    //repo only simply can't be defined in the abstraction -- can't see you => no contract 

    //repo and service only has to be public? 
    public virtual Ppty_B {get;set;} 

    //at least public is public... 
    public virtual Ppty_C {get;set;} 
} 

//dal.dll 
using bl; 
public SQLWidget : Widget //Or actually DALBLWidget -- see below? 
{ 
    //repo only 
    internal ... 
    internal ... 

    //the rest 
    ... 
} 

なら私はちょうど別の抽象ウィジェットを作成する(DAL-BLウィジェットとBL-UIウィジェットを持つ)か?

+0

なぜこのデザインが必要ですか?カスタムレイヤーの各レイヤーにDTOを作成し、必要なデータだけを渡す方が良いアイデアではないでしょうか? –

+0

私は変更を加えなければならないときに、痛みを伴わずに "列"全体を更新する良い選択肢は知らない。私の直感は、同じエンティティを表す型の数を最小限に抑えることです(私はORMのためだけにもう1つ必要があります) –

+0

列全体を更新することはどういう意味ですか? –

答えて

1

ウィジェットクラスに各レイヤーに対応する異なるインターフェイスを実装させることができます。

public class Widget : IDataLayerWidget, IBusinessLayerWidget 
{ 
// Properties 
} 

public interface IDataLayerWidget 
{ 
    // Properties visible to the DataLayer 
} 

public interface IBusinessLayerWidget 
{ 
    // Properties visible to the BusinessLayer 
} 

ごDataLayerでは、IDataLayerWidgetとし、IBusinessLayerWidgetであなたのビジネス層に働くだろう。

+0

私が考えたものではありませんが、私が望むのは孤立です。現時点では、これがプレゼンテーション層が '(IDataLayerWidget)Widget'や'(IBusinessLayerWidget)Widget'を操作するのを防ぐ方法はありません。 –

+1

それはしません。あるレイヤーが別のレイヤーのデータにアクセスしないようにする場合は、そのレイヤーにデータへのアクセス権を与えないでください。 問題を完璧に解決する方法はありません。いずれかのレイヤーごとに別々のウィジェットを用意し、マッピングを行います。それはあなたに分離を与えます。または、すべてのレイヤーでデータオブジェクトを共有し、ハイカップリングを使用して生きてください。 –

+0

@SebastianWeber、あなたの "はい"答えは私が生きていることです。私は喜んでここでもそれを受け入れるだろう。 –

関連する問題