Comments (11)
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.
@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.
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.
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.
Great. No pressure. Just letting you know how I use it and what real life problems arise ;-)
from container.
Appreciated 👍
from container.
If it stays like it is now, also fine.
from container.
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.
Or they could be defined in the service provider itself in a similar way to the provides
array/method. Thoughts?
from container.
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.
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)
- References are unallowed HOT 1
- Can't override a definition.
- Setting concrete does not reset arguments. HOT 4
- [2.x] Add support for PHP 8 HOT 2
- Extends causing an infinite loop HOT 1
- Inconsistent Behavior HOT 12
- Question: Possible to use tags in Service Providers? HOT 3
- Fatal error: incompatible declaration of get method against PSR interface, in some PHP versions HOT 5
- Returning from an inflector HOT 7
- Support for non-object concrete values HOT 3
- Question: How to "inflect once" for shared services? HOT 13
- Preceeding slash confusing fully qualified class names HOT 1
- Extends causing an infinite loop HOT 2
- Question: Can Container Change an Alias? HOT 1
- Huge performance hits when having a bigger application with a lot of service definitions HOT 6
- How swap added definition HOT 1
- Auto wiring a shared dependency HOT 1
- Infinate loop in resolving non-existant class HOT 1
- Question: How to achieve autowiring inside the service provider? HOT 1
- Is this package still maintained? HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from container.