Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
29b9a92a
Commit
29b9a92a
authored
Apr 19, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
di doc WIP [skip ci]
parent
873cf243
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
2 deletions
+36
-2
README.md
docs/guide/README.md
+3
-2
di.md
docs/guide/di.md
+31
-0
index.md
docs/guide/index.md
+2
-0
No files found.
docs/guide/README.md
View file @
29b9a92a
...
@@ -4,5 +4,6 @@ To add new guide, take the following steps:
...
@@ -4,5 +4,6 @@ To add new guide, take the following steps:
1.
Create
`guide-name`
and put there relevant documentation;
1.
Create
`guide-name`
and put there relevant documentation;
2.
If guide has more then one word in name, then it should be with dashes, like:
`console-fixture.md`
,
`module-debug.md`
;
2.
If guide has more then one word in name, then it should be with dashes, like:
`console-fixture.md`
,
`module-debug.md`
;
3.
If your guide is for console commands, than its name should follow convention:
`console-{command}.md`
;
3.
If your guide is about console commands, than its name should follow convention:
`console-{command}.md`
;
4.
If your guide is for custom modules, than its name should follow convention:
`module-{moduleName}.md`
.
4.
If your guide is about module usages, than its name should follow convention:
`module-{moduleName}.md`
.
5.
If your guide is about widget usages, than its name should follow convention:
`widget-{moduleName}.md`
.
docs/guide/di.md
0 → 100644
View file @
29b9a92a
Service Locator and Dependency Injection
========================================
Both service locator and dependency injection are design patterns that allow building software
in a loosely-coupled fashion. Yii uses service locator and dependency injection extensively,
even though you may not be aware of them. In this tutorial, we will explore their implementation
and support in Yii to help you write code more consciously. We also highly recommend you to
read
[
Martin's article
](
http://martinfowler.com/articles/injection.html
)
to get a deeper
understanding of SL and DI.
Service Locator
---------------
A service locator is an object that knows how to provide all sorts of services that an application
might need. The most commonly used service locator in Yii is the
*application*
object accessible through
`\Yii::$app`
. It provides services under the name of
*application components*
. The following code
shows how you can obtain an application component (service) from the application object:
```
php
$request
=
\Yii
::
$app
->
get
(
'request'
);
// or alternatively
$request
=
\Yii
::
$app
->
request
;
```
Behind the scene, the application object serves as a service locator because it extends from
the
[
[yii\di\ServiceLocator
]
] class.
Dependency Injection
--------------------
docs/guide/index.md
View file @
29b9a92a
...
@@ -36,6 +36,7 @@ Base concepts
...
@@ -36,6 +36,7 @@ Base concepts
-
[
Event Handling
](
events.md
)
- The Yii event handling mechanism
-
[
Event Handling
](
events.md
)
- The Yii event handling mechanism
-
[
Behaviors
](
behaviors.md
)
-
[
Behaviors
](
behaviors.md
)
Database
Database
--------
--------
...
@@ -90,6 +91,7 @@ Advanced Topics
...
@@ -90,6 +91,7 @@ Advanced Topics
-
[
Console Application
](
console.md
)
-
[
Console Application
](
console.md
)
-
[
Performance Tuning
](
performance.md
)
-
[
Performance Tuning
](
performance.md
)
-
[
Testing
](
testing.md
)
-
[
Testing
](
testing.md
)
-
[
Service Locator and Dependency Injection
](
di.md
)
References
References
----------
----------
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment