Support the ongoing development of Laravel.io →
posted 8 years ago
IOC
Last updated 2 years ago.
0

Ok, so changing the service provider like so:

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

use App\Support\UserMessage\UserMessage;
use App\Contracts\UserMessageContract;

class UserMessageProvider extends ServiceProvider
{
    protected $defer = true;

    public function register()
    {
        $this->app->singleton(UserMessageContract::class, function ($app)
        {
            return new UserMessage();
        });

        $this->app->alias(UserMessageContract::class, 'usermessage');
    }

    public function provides()
    {
        return [UserMessageContract::class, 'usermessage'];
    }
}

gives the desired result. The class gets resolved out of the IoC container and I can still use the alias, i.e app('usermessage');

Last updated 8 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

john052 john052 Joined 26 May 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.