twgOren / roroioc

IOC Injection for python
MIT License
0 stars 1 forks source link

instance_ioc_container.py: obtain all resources from payload before integrating them #17

Closed avish closed 6 years ago

avish commented 6 years ago

This addresses the issue when attempting to obtain a resource from the payload throws an exception. In the original implementation, the integration process is not atomic, and so any exception thrown mid-way would cause all previously integrated resources to stay integrated, but without the arm operation considered successful; this in turn will not clean them up during un-arm, and will fail subsequent attempt at arming the same container because of the assertion that checks that each resource being integrated has not already been integrated.

The new implementation obtains all the resources from the payload first, so that any exceptions are raised at that point, and before any state has been changed. Only if all the resources have been obtained successfully we continue and integrate them all into the context. As a bonus, the check that extends the context to accommodate out-of-bounds handle numbers can now happen once per arming rather than once per provided resource.

This addresses issue #16.