Git Product home page Git Product logo

Comments (5)

alcaeus avatar alcaeus commented on June 12, 2024 1

As far as I can see, there are actually some packages that don't quite conform to the specification. This leads to problems.

I agree. The specification says to not request dependencies in register, as not all services have been registered at that point. If other tools ignore that, that's on them and should be reported (and fixed) there.

Another thing I don't understand is why you register through the resolving function instead of the make function.

The make method actually resolves a dependency, which isn't what we need. We need to call the extend method on the DatabaseManager service to inject a custom extension for the mongodb database driver. We can't use the extend method of the service container for this, but instead need to inject this when the db service is resolved. The only way to achieve this is by using resolving.

Like I said: if tools break because do what a bolded sentence in the docs tells them not to do, that's not on us, that's on them. I'm closing this as won't fix.

from laravel-mongodb.

GromNaN avatar GromNaN commented on June 12, 2024

Hello @zyz954489346, do you have any idea how we can fix this issue?

from laravel-mongodb.

alcaeus avatar alcaeus commented on June 12, 2024

Hi @zyz954489346, I believe the issue is actually in your code. Quoting from the Service Providers documentation:

Within the register method, you should only bind things into the service container. You should never attempt to register any event listeners, routes, or any other piece of functionality within the register method.

In your code, you are registering a listener, which you shouldn't be doing in register, but rather in boot. Again, quoting from the documentation:

So, what if we need to register a view composer within our service provider? This should be done within the boot method. This method is called after all other service providers have been registered, meaning you have access to all other services that have been registered by the framework.

from laravel-mongodb.

zyz954489346 avatar zyz954489346 commented on June 12, 2024

Hi @zyz954489346, I believe the issue is actually in your code. Quoting from the Service Providers documentation:

Within the register method, you should only bind things into the service container. You should never attempt to register any event listeners, routes, or any other piece of functionality within the register method.

In your code, you are registering a listener, which you shouldn't be doing in register, but rather in boot. Again, quoting from the documentation:

So, what if we need to register a view composer within our service provider? This should be done within the boot method. This method is called after all other service providers have been registered, meaning you have access to all other services that have been registered by the framework.

@alcaeus You're right, but there's no way to let other package writers to do that.
As far as I can see, there are actually some packages that don't quite conform to the specification. This leads to problems. As a user of the package, there is no other way but to override the Provider. 

Another thing I don't understand is why you register through the resolving function instead of the make function. I read other similar packages, most of which are register through the make function.

from laravel-mongodb.

zyz954489346 avatar zyz954489346 commented on June 12, 2024

Hello @zyz954489346, do you have any idea how we can fix this issue?

@GromNaN I temporarily solved the problem by rewriting Provider, but this is really not an elegant solution.

from laravel-mongodb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.