# The StorageRepository Class¶

The \TYPO3\CMS\Core\Resource\StorageRepository is the main class for creating and retrieving file storage objects. It contains a number of utility methods, some of which are described here, some others which appear in the other code samples provided in this chapter.

## Getting the Default Storage¶

Of all available storages, one may be marked as default. This is the storage that will be used for any operation whenever no storage has been explicitly chosen or defined (for example, when not using a combined identifier).

/**
* @var \TYPO3\CMS\Core\Resource\StorageRepository
*/
private $storageRepository; public function __construct(StorageRepository$storageRepository)
{
$this->storageRepository =$storageRepository;
}

public function example(): void
{
$defaultStorage =$this->storageRepository->getDefaultStorage();
}


Note

This may return null if no default Storage exists.

## Getting any storage¶

The StorageRepository should be used when retrieving any storage.

/**
* @var \TYPO3\CMS\Core\Resource\StorageRepository
*/
private $storageRepository; public function __construct(StorageRepository$storageRepository)
{
$this->storageRepository =$storageRepository;
}

public function example(): void
{
$storage =$this->storageRepository->getStorageObject(3);
}