0
작업 단위 클래스가 있으므로 데이터베이스 컨텍스트를 삭제하는 메소드가 있습니다. 하지만 데이터베이스 컨텍스트를 저장소 클래스 인 NotesRepository에 전달하는 경우에도 NotesRepository 클래스에 컨텍스트를 처리해야합니까? 그렇지 않으면이 컨텍스트가 작업 클래스 단위로 처리 되었기 때문에 필요하지 않습니다.작업 단위 및 저장소 패턴의 단위 및 데이터베이스 컨텍스트 처분
public class UnitOfWork : IDisposable
{
private DatabaseContext context = new DatabaseContext();
private NotesRepository notesRepository;
public NotesRepository NotesRepository
{
get
{
if (this.notesRepository == null)
{
this.notesRepository = new NotesRepository(context);
}
return notesRepository;
}
}
private bool disposed = false;
protected virtual void Dispose(bool disposing)
{
if (!this.disposed)
{
if (disposing)
{
context.Dispose();
}
}
this.disposed = true;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
}
이것은 저장소 클래스 :
public class NotesRepository
{
private DatabaseContext context;
public NotesRepository(DatabaseContext context)
{
this.context = context;
}
public IQueryable<Notes> GetAllNotes()
{
return (from x in context.Notes
orderby x.CreateDate descending
select x);
}
}