Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lumen - Registering Class in Service Provider #14

Open
memoishin opened this issue May 8, 2018 · 6 comments
Open

Lumen - Registering Class in Service Provider #14

memoishin opened this issue May 8, 2018 · 6 comments
Labels

Comments

@memoishin
Copy link

memoishin commented May 8, 2018

I am registering an Aspect class in the AopServiceProvider. However, it does not seem to work.

Here is my code:

public function register()
{
     $this->app->singleton(LoggingAspect::class, function (Application $app) {
        return new LoggingAspect($app->make(LoggerInterface::class));
    });

    $this->app->tag([LoggingAspect::class], 'goaop.aspect');
}

Now even if I have the code as this:

public function register()
{
     $this->app->singleton(LogsasasagingAspect::class, function (Application $app) {
        return new LoggingAspect($app->make(LoggesasarInterface::class));
    });

    $this->app->tag([LoggasaingAspect::class], 'goaop.aspect');
}

It still doesn't show any error.

This service provider has been registered as:

$app->register(App\Providers\AopServiceProvider::class);
Is this normal or is there any fix for this?

@SerafimArts
Copy link
Member

Registration of services in a DI Container is declarative and should not cause errors until the specified service is resolved.

In this case, errors will occur when u call: $app->make(LogsasasagingAspect::class).

But I did not understand the question. :D

@memoishin
Copy link
Author

As you mentioned, "errors will occur when u call: $app->make(LogsasasagingAspect::class)", however, i do not receive any error message.

Also, the aop functionality does not work. I am using Lumen 5.6. Can this be the reason why it doesn't work?

@SerafimArts
Copy link
Member

To be honest, I did not check the package works for Lumen at all. Here you need the experience of other developers who have adapted it.

Ping @lisachenko

@lisachenko
Copy link
Member

I think @qrazi has an experience with Lumen, because he have contributed #11

@memoishin
Copy link
Author

memoishin commented May 11, 2018

I have managed to make it work using some concepts from the slides by Chris Flynn and using the demo examples that was provided.

I believed making this change in bootstrap/app.php made it work:

use Go\Aop\Features;
$applicationAspectKernel = App\lib\ApplicationAspectKernel::getInstance();

$applicationAspectKernel->init([
'debug' => true,
'appDir' => DIR . '/../app/Http/Controllers/',
'cacheDir' => DIR . '/../cache',

'features' => Features::INTERCEPT_FUNCTIONS,

]);

@qrazi
Copy link
Contributor

qrazi commented May 13, 2018

Right, so obviously I didn't finish testing after commit #11... 😖 Based on this issue testing the lumen integration and:

https://github.com/laravel/lumen-framework/pull/723/files should allow Lumen to have a more Laravel-like registration of ServiceProviders, i.e. the boot() of each provider will only be called after the register() of all providers has run.

I'll look more into this to get it into a proper solutions, leaving this issue open

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

4 participants