Your proposed approach using dl.dataset should work:
class MyDataset(Dataset):
    def __init__(self):
        self.data = torch.arange(10)
        
    def __getitem__(self, index):
        x = self.data[index]
        return x
    
    def __len__(self):
        return len(self.data)

dataset = MyDataset()
loader = DataLoader(dataset, shuffle=True, batch_size=2)

for data in loader:
    print(data)

for data in loader.dataset:
    print(data)