// UserService and BookService are scoped services. Are these unmanaged resources?
public class UserService : IDisposable
{
private IBookService _bookService;
private IUserRepository _userRepository;
public UserService(
IBookService bookService,
IUserRepository userRepository
) {
_bookService = bookService;
_userRepository = userRepository;
}
// ... methods
public void Dispose()
{
// is it effective to use Dispose like that?
// are _bookService and _userRepository unmanageable resources?
_bookService?.Dispose();
_userRepository?.Dispose();
// is it needed/effective to set those to null?
_bookService = null;
_userRepository = null;
}
}
// UserRepository is scoped
public class UserRepository : IUserRepository, IDisposable
{
private readonly DbContext _context;
public UserRepository(DbContext context)
{
_context = context;
}
// ... methods
public void Dispose()
{
// is it effective to use Dispose like that?
_context?.Dispose();
// is it needed/effective to set it to null?
_context = null;
}
}
// UserService and BookService are scoped services. Are these unmanaged resources?
public class UserService : IDisposable
{
private IBookService _bookService;
private IUserRepository _userRepository;
public UserService(
IBookService bookService,
IUserRepository userRepository
) {
_bookService = bookService;
_userRepository = userRepository;
}
// ... methods
public void Dispose()
{
// is it effective to use Dispose like that?
// are _bookService and _userRepository unmanageable resources?
_bookService?.Dispose();
_userRepository?.Dispose();
// is it needed/effective to set those to null?
_bookService = null;
_userRepository = null;
}
}
// UserRepository is scoped
public class UserRepository : IUserRepository, IDisposable
{
private readonly DbContext _context;
public UserRepository(DbContext context)
{
_context = context;
}
// ... methods
public void Dispose()
{
// is it effective to use Dispose like that?
_context?.Dispose();
// is it needed/effective to set it to null?
_context = null;
}
}