@3000 You don’t understand service providers. That’s not how they work at all.
A service provider registers services in the service container. That’s what the register method is for: for registering things. It’s not a service itself that you return something from and type-hint in your application’s classes.
Your BatmanServiceProvider should instead register something in the container. So if you want a Batman service class, that’s what you’d register:
class BatmanServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->register(Batman::class, function () {
// Build and return Batman service class instance...
});
}
}
Now, you’d type-hint the Batman service; not the service provider:
class BatmanController extends Controller
{
protected $batman;
public function __construct(Batman $batman)
{
$this->batman = $batman;
}
}
Because you’re type-hinting the Batman service (and not the service provider), Lumen will look into the container, find the binding, and return that instance.