Implement IDisposable in abstract class

Yuri

I have following abstract class and need to implement IDisposable to make sure that DbContent will be disposed all the time properly.

public abstract class DataRepositoryBase<T> : DataRepositoryBase<T, MainDbContext>
    where T : class, IIdentifiableEntity, new()
{

}

what is the best way to achieve that?

Please NOTE: I'm greatly aware on how to use IDisposable in concrete classes but implementation of this functionality in the abstract class - not very clear

Adam Houldsworth

I would take the implementation provided in this answer:

Proper use of the IDisposable interface

And in derived types override the Dispose(bool disposing) method if the derived type needs to also dispose of stuff, remembering to call base. If it doesn't need to, then simply do nothing with the base implementation.

Make sure it makes sense to expose the need to call Dispose on this type's public contract, it could be a sign of a leaked abstraction (though not always).

This would at the very least be a good start.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Implement IDisposable in derived class

From Dev

Implement IDisposable in derived class

From Dev

Nested abstract class in an abstract class and how to implement it

From Dev

Class must be declared as abstract or implement abstract method

From Dev

How to implement an abstract class in Go?

From Dev

Elegant way to implement abstract class

From Dev

implement abstract adapter class in MainActivity

From Dev

How to create Mock to a class that implement an abstract class

From Dev

How to implement IDisposable interface in a class inherited from SocketAsyncEventArgs

From Dev

Should I implement IDisposable when class has IDisposable member but no unmanaged resources?

From Dev

Abstract class implement a generic Interface Type

From Dev

How to implement generic fields from abstract class?

From Dev

implement nested abstract class with getter/setter

From Dev

parse anonymous class does not implement abstract method

From Dev

How to implement Interface to an abstract class which is constraint?

From Dev

Scala akka : implement abstract class with subtype parameter

From Dev

Java how to implement and design an abstract class

From Dev

How to implement methods of an abstract class? (Java)

From Dev

How to Implement Extension Method in Abstract Class

From Dev

How to implement Interface to an abstract class which is constraint?

From Dev

How to implement Abstract class in laravel 5.3

From Dev

How to implement operator+ in abstract base class

From Dev

Implement abstract method inside of scalatest class

From Dev

Class must either be declared abstract or implement abstract method

From Dev

Class must either be declared abstract or implement abstract method?

From Dev

Class must either be declared abstract or implement abstract method error

From Dev

Class must either be declared abstract or implement abstract method: Intellij error?

From Dev

RxAndroid: Class must either be declared abstract or implement abstract method error

From Dev

Class must either be declared abstract or implement abstract method: Intellij error?

Related Related

  1. 1

    Implement IDisposable in derived class

  2. 2

    Implement IDisposable in derived class

  3. 3

    Nested abstract class in an abstract class and how to implement it

  4. 4

    Class must be declared as abstract or implement abstract method

  5. 5

    How to implement an abstract class in Go?

  6. 6

    Elegant way to implement abstract class

  7. 7

    implement abstract adapter class in MainActivity

  8. 8

    How to create Mock to a class that implement an abstract class

  9. 9

    How to implement IDisposable interface in a class inherited from SocketAsyncEventArgs

  10. 10

    Should I implement IDisposable when class has IDisposable member but no unmanaged resources?

  11. 11

    Abstract class implement a generic Interface Type

  12. 12

    How to implement generic fields from abstract class?

  13. 13

    implement nested abstract class with getter/setter

  14. 14

    parse anonymous class does not implement abstract method

  15. 15

    How to implement Interface to an abstract class which is constraint?

  16. 16

    Scala akka : implement abstract class with subtype parameter

  17. 17

    Java how to implement and design an abstract class

  18. 18

    How to implement methods of an abstract class? (Java)

  19. 19

    How to Implement Extension Method in Abstract Class

  20. 20

    How to implement Interface to an abstract class which is constraint?

  21. 21

    How to implement Abstract class in laravel 5.3

  22. 22

    How to implement operator+ in abstract base class

  23. 23

    Implement abstract method inside of scalatest class

  24. 24

    Class must either be declared abstract or implement abstract method

  25. 25

    Class must either be declared abstract or implement abstract method?

  26. 26

    Class must either be declared abstract or implement abstract method error

  27. 27

    Class must either be declared abstract or implement abstract method: Intellij error?

  28. 28

    RxAndroid: Class must either be declared abstract or implement abstract method error

  29. 29

    Class must either be declared abstract or implement abstract method: Intellij error?

HotTag

Archive