You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Dip/Dip/Dip.swift
+6-4Lines changed: 6 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -88,14 +88,16 @@ public class DependencyContainer {
88
88
- parameter factory: generic factory that should be used to create concrete instance of type
89
89
- parameter scope: scope of the component. Default value is `Prototype`
90
90
91
-
-note: You should not call this method directly, instead call any of other `register` methods. You _should_ use this method only to register dependency with more runtime arguments than _Dip_ supports (currently it's up to six). Though before you do that you should probably review your design and try to reduce number of depnedencies.
91
+
-note: You should not call this method directly, instead call any of other `register` methods. You _should_ use this method only to register dependency with more runtime arguments than _Dip_ supports (currently it's up to six) like in this example:
let service1 = webServices.resolve(NSURL(string: "http://example.url")!, 80) as WebServiceAPI // service1.name == "1"
117
-
let service2 = webServices.resolve(80, NSURL(string: "http://example.url")!) as WebServiceAPI //service1.name == "2"
118
-
let service3 = webServices.resolve(80, NSURL(string: "http://example.url")?) as WebServiceAPI //service1.name == "3"
116
+
let service1 = webServices.resolve(NSURL(string: "http://example.url")!, 80) as WebServiceAPI // service1 is WebServiceImp1
117
+
let service2 = webServices.resolve(80, NSURL(string: "http://example.url")!) as WebServiceAPI //service2 is WebServiceImp2
118
+
let service3 = webServices.resolve(80, NSURL(string: "http://example.url")) as WebServiceAPI //service3 is WebServiceImp3
119
119
120
120
```
121
+
Though Dip provides support for up to six runtime arguments out of the box you can extend this number using following code snippet for seven arguments:
121
122
122
-
### Runtime arguments
123
-
124
-
You can register factories that accept up to six arguments. When you resolve dependency you can pass those arguments to `resolve()` method and they will be passed to the factory. Note that _number_, _types_ and _order_ of parameters matters. Also use of optional parameter and not optional parameter will result in two factories registered in container.
125
-
126
-
```swift
127
-
let webServices =DependencyContainer() { webServices in
0 commit comments