JasperFx / lamar

Fast Inversion of Control Tool and Successor to StructureMap
https://jasperfx.github.io/lamar
MIT License
572 stars 119 forks source link

Transient instances created by lambda functions are not properly registered for disposal #71

Closed CodingGorilla closed 6 years ago

CodingGorilla commented 6 years ago

This creates a unit test which demonstrates that when a lambda function is used to generate an instance with a transient lifetime, that instance is created in a dependent class' constructor function but never registered for disposal in the containing scope.

My proposed solution is to add some generated code that attempts to cast the constructed instance to IDisposable and if it casts, then add it to the scope's Disposables collection during construction of the depending instance.

CodingGorilla commented 6 years ago

This is a bit hacky and I'm not sure it's the best solution, but it does solve the problem.