Knowledgebase

Understanding the Service Container Print

  • phplaravel, guide, howto, solution, zillionkinghost, hosting, support
  • 0

How dependencies are provided.

WHAT IT IS

A mechanism that creates objects and supplies what they need.

WHAT THAT MEANS PRACTICALLY

You declare what a class requires, and it is provided automatically.

WHY THAT MATTERS

Classes do not create their own dependencies, so those can be substituted.

WHAT THAT ENABLES

Testing, by supplying a substitute Changing an implementation without editing everything using it

WHAT BINDING MEANS

Telling the container how to construct something, or which implementation to use for an interface.

WHERE THAT IS DONE

In service providers, which run at startup.

WHAT SERVICE PROVIDERS DO

Register bindings and perform startup configuration.

WHAT FACADES ARE

A concise way of reaching services in the container.

WHAT TO KNOW ABOUT THEM

Convenient, and they obscure dependencies.

WHAT TO PREFER IN CLASSES YOU WILL TEST

Declared dependencies, provided by the container.

WHAT TO AVOID

Reaching for services from deep inside classes Binding things that do not need binding


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot