Git Product home page Git Product logo

Comments (11)

hannesvdvreken avatar hannesvdvreken commented on August 26, 2024

so there will be a BootableServiceProviderInterface. but what if I'd have this:

class AppServiceProvider extends \League\Container\ServiceProvider implements \League\Container\ServiceProvider\BootableServiceProviderInterface
{
    public function register()
    {
        //
    }

    public function boot()
    {
        $this->container->inflector(ContainerAwareInterface::class)
            ->invokeMethod('setContainer', [ContainerInterface::class]);
    }
}

class EventingServiceProvider extends \League\Container\ServiceProvider implements \League\Container\ServiceProvider\BootableServiceProviderInterface
{
    public function register()
    {
        //
    }

    public function boot()
    {
        $object = $this->container->get(ContainerAwareObject::class);
        // ...
    }
}

What if these are registered in the opposite way? There's shouldn't be a order constraint between serviceproviders.

from container.

philipobenito avatar philipobenito commented on August 26, 2024

@hannesvdvreken do you have a suggestion on how to achieve this? As it is, for eager loading there has to be an order constraint.

from container.

hannesvdvreken avatar hannesvdvreken commented on August 26, 2024

Nah, I don't know. When you want to simply define this SP and make it work:

class AppServiceProvider extends \League\Container\ServiceProvider
{
    protected $provides = [ContainerAwareInterface::class];

    public function register()
    {
        $this->container->inflector(ContainerAwareInterface::class)
            ->invokeMethod('setContainer', [ContainerInterface::class]);
    }
}

You'd need to go up the inheritance tree for every resolved object to see which interfaces it implements and which classes it extends. That's a potentially expensive reflection operation.

Maybe, just maybe:

class ServiceProvider
{
    protected $inflectors = [ContainerAwareInterface::class];

    public function hasInflectorsFor($object) {
        foreach ($inflectors as $inflector) {
            if ($object instanceof $inflector) {
                return true;
            }
        }
        return false;
    }
}

from container.

philipobenito avatar philipobenito commented on August 26, 2024

Once you start looking in to bypassing order constraints more than I already have with the lazy loading (I know this doesn't help for inflectors) then the complexity really starts to grow.

I'm improving inflector functionality this week and that might help the situation from a user land perspective so I'll give you a shout once I've pushed that stuff.

from container.

hannesvdvreken avatar hannesvdvreken commented on August 26, 2024

Great. No pressure. Just letting you know how I use it and what real life problems arise ;-)

from container.

philipobenito avatar philipobenito commented on August 26, 2024

Appreciated 👍

from container.

hannesvdvreken avatar hannesvdvreken commented on August 26, 2024

If it stays like it is now, also fine.

from container.

philipobenito avatar philipobenito commented on August 26, 2024

What I'm thinking is that there is now a service provider aggregate that stores all service providers, a second argument could be passed to the addServiceProvider method that are the dependency service providers of the one you are registering. That way, before register is invoked, the register method of the dependencies will be invoked (if they haven't been already).

from container.

philipobenito avatar philipobenito commented on August 26, 2024

Or they could be defined in the service provider itself in a similar way to the provides array/method. Thoughts?

from container.

hannesvdvreken avatar hannesvdvreken commented on August 26, 2024

Not a fan of that. Service Providers don't really have to know which other SP can register something. If I want to hand the container my own Service Provider which builds a certain type of object in a much better way with my own dependencies...

from container.

philipobenito avatar philipobenito commented on August 26, 2024

Yeah, that's my thoughts, it's too much, but it is the only way around the order constraints if we want to keep lazy loading, which I do.

from container.

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.