About Servicelocator, Adpaterawareinterface injection

Source: Internet
Author: User

Today learning ZF2 process, the video said to the database in the table to inherit Tablegateway, and then registered in ServiceManager, but there is no $adapter, need in Servicemanger, configure initializer, Add a class that implements Intializerinterface, which has a initialize method that determines if the class that the service produces implements Adapterinterface, then Setdbadapter () is executed, Inject Serivcielocator->get (' adpater ') into the class so that the $adpater is automatically injected when the Usertable service is invoked.

Then, I think is if usertable directly implement Servicelocatorawareinterface is not can also inject adater into it, so, try, servicelocator can come in, but the service is to directly produce instances, There's no way to give servicelocator to $adapter, so we have to implement Adapterinterface, initialize it and inject it in.

About Servicelocator, Adpaterawareinterface injection

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.