エンティティごとに個別のリポジトリクラスがあります。ここで、リポジトリインスタンスを使用するドメインオブジェクトにいくつかの静的メソッドを実装したいと思いますが、このアプローチの欠点は、静的変数(Webアプリケーションではうまく機能しない)でリポジトリインスタンスを保持する必要があるか、作成する必要があることです各静的メソッドの新しいインスタンス。これに対するより良いアプローチはありますか(つまり、リポジトリインスタンスを使用してドメインクラスに静的メソッドを実装する)?あなたのアイデアを共有してください。
ベースリポジトリ:
public abstract class AbstractRepository<TEntity> : IabstractRepository<TEntity>
where TEntity : EntityObject
{
protected CivilRegistryEntities civilContext;
public AbstractRepository()
{
civilContext = CivilRegistryEntities.Instance; // Per HTTP request singletone.
}
// Other method implementation goes here.
}
エンティティリポジトリごと:
public class BirthReportRepository : AbstractRepository<BirthReport>
{
}
ドメイン/エンティティ/モデルオブジェクト:
public partial class BirthReport
{
//Not works well in web application.
private static BirthReportRepository repository = new BirthReportRepository();
public static BirthReport Method1()
{
return repository.SomeMethod();
}
public static BirthReport Method2()
{
return repository.SomeOtherMethod();
}
// Other methods(both static and instance) goes here.
}