ivlevAstef / DITranquillity

Dependency injection for iOS (Swift)
MIT License
421 stars 32 forks source link

resolve many on lazy #145

Closed evgeniy-bizhanov closed 4 years ago

evgeniy-bizhanov commented 5 years ago

Hi, let test: [Lazy<Provider>] = [*container] is work but let test: [Lazy<Provider>] = many(*container) doesn't

Fatal error: Can't cast Optional to Array<Lazy>

what workaround could be? thanx

ivlevAstef commented 5 years ago

oh... this case not worked now. Lazy not worked with many. My bad.

I'm special fix in version 3.8.1 for only this case.

evgeniy-bizhanov commented 5 years ago

thanx, but still not working(

by the way DIPart's load is not called, when it's part of DIFramework container.append(part: Part.self) through container is work but through DIFramework does not

ivlevAstef commented 5 years ago

@evgeniy-bizhanov ... but tests worked. for example:

let container = DIContainer()
container.register(FooService.init)
      .as(check: ServiceProtocol.self){$0}
 container.register(BarService.init)
      .as(check: ServiceProtocol.self){$0}
let services: [Lazy<ServiceProtocol>] = many(*container)
XCTAssertEqual(services.count, 2)
XCTAssertNotEqual(services[0].value.foo(), services[1].value.foo())

Your used 3.8.1 version?

about DIPart and DIFramework - it's works (tested on modular big project). Maybe you not fully understand how work DIFramework, but normally case it doesn't matter. Worked code:

let container = DIContainer()
container.append(framework: YourFramework.self)

class YourFramework: DIFramework {
   static func load(container: DIContainer) {
        container.append(part: YourPart.self)
   }
}

class YourPart: DIPart {
  static func load(container: DIContainer) {
        container.register(...)
   }
}
evgeniy-bizhanov commented 5 years ago

yes, it was 3.8.1, but seems it was cached( I reinstalled pod and it worked thanks for the quick support:)

evgeniy-bizhanov commented 4 years ago

I found that resolving Lazy property by tag also not working..

let lazy: Lazy<Service> = by(tag: EmailService.self, on: *container)

info: Not found type: Lazy with tag: EmailService Fatal error: Can't resolve type Service. For more information see logs.: file 2019-09-15 15:21:51.149208+0700 ForFun[12579:885258] Fatal error: Can't resolve type Service. For more information see logs.: file error: Execution was interrupted, reason: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0). The process has been returned to the state before expression evaluation.

ivlevAstef commented 4 years ago

:( I will see on Monday

ivlevAstef commented 4 years ago

@evgeniy-bizhanov fix in version 3.8.2.

evgeniy-bizhanov commented 4 years ago

It works, thanks!:)