Closed ilyapuchka closed 7 years ago
First option (after just removing generic arguments from register/resolve API) looks possible but not very attractive in terms of API.
container.register(Service.self) { ServiceImp() }
let service = try! container.resolve(Service.self) as! Service
Gets worse with runtime arguments:
container.register(Service.self, argumentsType: (Int, Int).self) { args in
let (a1, a2) = args as! (Int, Int)
return ServiceImp(a1, a2)
}
let service = try! container.resolve(Service.self, withArguments: (arg1, arg2)) as! Service
Don't think it makes much sense. Second option should be still investigated. At least it should be possible to implement minimal interception functionality with just getting callback before calling any method.
To avoid moving feature dependent on Foundation we can use compile directives and simply do not include this code for not Darwin architecture.
That actually has two sides:
1. Using Dip from Objective-C code. That will require adding register/resolve apis that will accept type as parameter (#75)NSObject
s (like interception using NSProxy, anything else?)If something of that should be implemented it will make sense to do it in a separate repo and maybe also create Dip org and gather there all repos. Also would let us to extract simple app to it's own repo, living only playground here.