love_php/app/Providers/MomentServiceProvider.php
2026-04-02 09:20:51 +08:00

39 lines
835 B
PHP

<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use App\Services\MomentService;
use App\Repositories\Eloquent\SmsRepository as Sms;
class MomentServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
//
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
//使用singleton绑定单例
$this->app->singleton('test', function($app){
return new MomentService(new Sms($app));
});
//使用bind板顶实际到接口以便依赖注入
$this->app->bind('App\Contracts\MomentContract', function($app){
return new MomentService(new Sms($app));
});
}
}