绑定到闭包
// In any service provider (maybe LoggerServiceProvider)
public function register() {
$this->app->bind(Logger::class, function ($app) {
return new Logger('\log\path\here', 'error');
});
}// Note that this binding is not doing anything technically useful, since this // could all be provided by the container's auto-wiring already.
$this->app->bind(UserMailer::class, function ($app) {
return new UserMailer(
$app->make(Mailer::class),
$app->make(Logger::class),
$app->make(Slack::class)
);
});Last updated