kohesive / injekt

Dependency Injection for Kotlin
MIT License
235 stars 20 forks source link

Allow expiration of an instance from registry #3

Open apatrida opened 9 years ago

apatrida commented 9 years ago

If an instance is useless (i.e. an ElasticSearch Client connection is dead) or known to be done, it should be able to be expired from the registry. This is important for PerKey factories that generate items and hold on to them, and eventually they need to be removed if the set is not finite.

yoavst commented 9 years ago

I'm writing it here because it can be a part of it. For testing purposes, or for RAM purposes, add a clear() method that clears all the data. I've got a problem with existing data in my tests (I Inject stubs to check if the classes works as intended).

apatrida commented 9 years ago

For testing you can create your own scope, and drop it to clear memory.

in the @Before method, ...

Injekt = InjektScope(DefaultRegistrar())

Will replace the global scope with a new one each time. It is defined as:

public @Volatile var Injekt: InjektScope = InjektScope(DefaultRegistrar())

so can be reset. I can also add clear methods (clearValues(), clearFactories(), ?)

yoavst commented 9 years ago

Yes, I've done doing that and then I saw this post :)

apatrida commented 9 years ago

I'll add clear methods in future release

apatrida commented 9 years ago

let me know if priority should be higher than "soon...."

yoavst commented 9 years ago

No, it is OK. Currently I need it only for testing, and I've created a base InjektableTest class.