2

自動インクリメンタルID(guid、interlocked.increment、ObjectIdGenerator ...)についてよく読んでいますが、私の状況では何も見つかりません。

私のドメイン モデルでは、ユーザーは、作成するアクティビティごとに自動プログレッシブ数値 ID を要求します。

これはユーザーリクエストなので、ドメインモデルに入れたいのですが、通常、適切なアーキテクチャのない古いアプリケーションで行うモードは、データベースにアクセスし、最大値を取得して1を追加します。ドメインレイヤーはdbを認識してはならないので、オブジェクトでそれを行うことはできません。

コントロールの欠如のためにデータベースIDが好きではありません(アクティビティの作成時に、データベース管理者がユーザーエラーのIDを変更する必要がある場合があります)。

interlocked.increment は問題ないように見えますが、私のアプリケーションはすべてのユーザー マシンにインストールされているため、使用できません

わかりやすくプログレッシブでなければならないので、GUIDは使用できません

Domain-Driven-Design の Service Domain に関する Lev Gorodinski の記事で良いアイデアを見つけました。

なにか提案を?

編集:レフ・ゴロディンスキーのアイデア:

public class Activity {
  public int Id {get; private set;}
  public string Description {get;set;}

  public Activity (string description){
    this.Description = description 
    this.Id = generator.GenerateId()
  }
}

public interface IIdGenerator{
  int GenerateId()
}

しかし、「ジェネレーター」が定義されている場所が表示されず、IIdGenerator の実装が見つかりません。実装をどこに配置すればよいですか? ActivityRepositoryで?はいの場合、 IActiviryRepositoryInterface の IIdGenerator を省略できますか?

4

1 に答える 1

1

私の考え:

ドメイン層

public class Activity {
  public int Id {get; private set;}
  public string Description {get;set;}

  public Activity (string description){
    this.Description = description 
    var activityRepository = kernel.Get<IActivityRepository>();
    this.Id = activityRepository .GetMaxId() + 1 
  }
}

public interface IActivityRepository{
  public int GetMaxId();
}

データ アクセス層

public class ActivityRepository
{
    pulic int GetMaxId()
    {
      // query for retriving max id from table
    }
}

どこか (どこ?) 私は Ninject で依存性注入を定義します

var kernel = new StandardKernel();
kernel.Bind<IActivityRepository>().To<ActivityRepository>();
于 2013-09-16T08:45:45.427 に答える