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: README.md
+51-1Lines changed: 51 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -432,6 +432,7 @@ The default is `NSLock`, but you can choose `DispatchSemaphore` or a separate qu
432
432
`Service[Params]SafeProvider` является наследником обычных провайдеров, поэтому доступен весь стандартный набор методов и можно хранить и передавать такой провайдер как обычный. Но в дополнение есть один метод - `getServiceAsResultNotSafe()`, который проигнорирует любые блокировки и выполнит обычное не безопасное получение сервиса.
let service = container.firstService.getServiceAsOptional()
451
452
```
452
453
454
+
### ServiceObtainError
455
+
456
+
If an error occurs as a result of getting the service, the provider returns `ServiceObtainError` with the original error and detailed information.
457
+
The error will contain information about the service in whose factory the error was throwed. Since services are dependent on each other and there is nesting when getting, the error may occur when getting a dependent service, and not when getting the original one - for this purpose, the error contains information about the path to the service with the error.
458
+
459
+
#
460
+
461
+
Если в результате получения сервиса возникла ошибка, то провайдер вернет `ServiceObtainError` с исходной ошибкой и подробной информацией.
462
+
В ошибке будет информацией об сервисе, в фабрике которого была получена ошибка. Т.к. сервисы зависимы между собой и при получении есть вложенность, то ошибка может возникнуть при получении зависимого сервиса, а не при запросе исходного - для этого в ошибке есть информация о пути до сервиса с ошибкой.
463
+
464
+
465
+
#### An example get ServiceObtainError and nested services:
466
+
```swift
467
+
structFirstServiceFactory: ServiceFactory {
468
+
let mode: ServiceFactoryMode = .lazy
469
+
funcmakeService() throws-> FirstService {
470
+
throwSomeError()
471
+
}
472
+
}
473
+
474
+
structSecondServiceFactory: ServiceFactory {
475
+
let firstService: ServiceProvider<FirstService>
476
+
477
+
let mode: ServiceFactoryMode = .many
478
+
funcmakeService() throws-> SecondService {
479
+
returnSecondServiceImpl(
480
+
firstService: try firstService.getService()
481
+
)
482
+
}
483
+
}
484
+
485
+
do {
486
+
let service =try secondServiceProvider.getService()
Creating and configuring the container is only available for swift code, but for objective-c, you can provide a special wrapper to getting the services.
457
501
458
502
`ServiceProviderObjC` (in Objective-C is visible as `ServiceProvider`) and `ServiceParamsProviderObjC` (in Objective-C is visible as `ServiceParamsProvider`) can be created from any `Service[Params]Provider`, passing it (swift option) to the constructor in the swift code.
You can get the service through selectors `[ServiceProvider getService]` and `[ServiceProvider getServiceAndReturnError:]`, also `[ServiceParamsProvider getServiceWithParams:]` and `[ServiceProvider getServiceWithParams:andReturnError:]`.
0 commit comments