DI with disposable objects

前端 未结 3 1317
庸人自扰
庸人自扰 2021-01-21 09:57

Suppose my repository class looks like this:

class myRepository : IDisposable{
    private DataContext _context;
    public myRepository(DataContext context){
           


        
3条回答
  •  伪装坚强ぢ
    2021-01-21 10:38

    Does this mean that I should not be implementing the IDisposable on the repository to clean up the DataContext?

    It sounds like it - from what you're saying, all repositories will share the same DataContext, but the first repository you create will dispose of it.

    What creates the DataContext? Whatever that is, it should dispose of it.

提交回复
热议问题