---
title: "DI and actions — Media Library for Laravel | Roundly"
description: "Skip the facade: inject MediaLibraryManager or call a single-purpose action — the facade method → action map."
url: https://roundly-consulting.com/open-source/docs/media-library-for-laravel/without-facade
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Media Library for Laravel](https://roundly-consulting.com/open-source/docs/media-library-for-laravel.md)

# DI and actions

The facade is the recommended default, not the only way in. Three entry points run the same code: the MediaLibrary facade (shortest), the manager RoundlyConsulting\\MediaLibrary\\MediaLibraryManager — the facade's root, a container singleton also aliased media — injected through the constructor (same API, explicit dependency, no static calls), and actions (single-purpose classes with execute(), for composing into your own actions, jobs and commands).

## Inject the manager

```php
use RoundlyConsulting\MediaLibrary\MediaLibraryManager;

final class AvatarController
{
    public function __construct(private MediaLibraryManager $media) {}

    public function store(Request $request): Media
    {
        return $this->media->for($request->user())->addFromRequest('avatar')->toBucket('avatar');
    }
}
```

## Call an action

```php
use RoundlyConsulting\MediaLibrary\Actions\MoveMediaAction;
use RoundlyConsulting\MediaLibrary\Actions\RegenerateVariantsAction;

app(MoveMediaAction::class)->execute($media, $otherUser, 'gallery', 'cold');
app(RegenerateVariantsAction::class)->execute($media, only: ['thumb'], force: true);
```

## Facade method → action

| Facade method | Action |
| --- | --- |
| `add*() / draft() → toBucket()` | `AddMediaAction` |
| `attach()` | `AttachMediaAction` |
| `bindDraft()` | `BindDraftMediaAction` |
| `move() / moveToDisk()` | `MoveMediaAction` |
| `moveVariantsToDisk()` | `MoveMediaVariantsAction` |
| `copy()` | `CopyMediaAction` |
| `replace()` | `ReplaceMediaAction` |
| `delete() / clear() / clearBucket()` | `DeleteMediaAction` |
| `regenerate() / variants()->regenerate()` | `RegenerateVariantsAction` |
| `pruneDrafts()` | `PruneDraftsAction` |
| `remote()->fetch()` | `FetchRemoteUrlAction` |
| `remote()->vet()` | `VetRemoteUrlAction` |

- Every mutation — from the facade, a for() handle, the trait or a Media model method — funnels through one manager verb that resolves one action from the container, so a container override of an action applies everywhere.
- MediaLibrary::fake() swaps the manager in the container too, so injected managers are faked as well. Calling an action directly bypasses the fake.
- remote() and its two actions store nothing, so the fake keeps them real — Http::fake() answers their requests.
- GenerateVariantsAction is an internal building block (it renders exactly the definitions it is handed) — regenerate through RegenerateVariantsAction or MediaLibrary::regenerate().

## Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

[More ways to support, including crypto](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

## Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/media-library-for-laravel.md)
