AliSoftware / Dip

Simple Swift Dependency container. Use protocols to resolve your dependencies and avoid singletons / sharedInstances!
MIT License
978 stars 75 forks source link

Is it possible to inject generics? #175

Closed nikans closed 6 years ago

nikans commented 7 years ago

Take for example Service as a protocol with some assiciatedtypes and ServiceImp1: Service and ServiceImp2: Service generic classes. I haven't tested yet, but a mind exercise tells me that it shouldn't work. Am I right?

ilyapuchka commented 6 years ago

You can't do register { ServiceImp1() as Service }, it's a Swift limitation, not Dip. You can do register { ServiceImp1() } but it will only register concrete type. You can try to apply type-arasure technique if it suites your case.