javaee / hk2

A light-weight and dynamic dependency injection framework
https://javaee.github.io/hk2
Other
112 stars 83 forks source link

OperationHandle implement AutoCloseable #368

Closed buko closed 6 years ago

buko commented 7 years ago

Would be nice to simplify the Operation API a bit to something like:

try (OperationHandle<StateTransaction> handle = manager.createAndStartOperation(TransactionScopeImpl.INSTANCE, transaction)) {

}

This would allow users to pass in the OperationData when the Operation is created and also ensure the Operation will always be closed.

buko commented 7 years ago

The same is true of ServiceHandle. It's not the end of the world either way but it would be nice to be able to write:

try (ServiceHandle<A> a = findA()) {
...
}

Rather than the more verbose form of initializing a to null and then using try/finally to ensure the ServiceHandle is always destroyed.

What do people think?

AutoCloseable now exists on Android so it shouldn't affect Android devs. It does require Java 7 to work.

glassfishrobot commented 6 years ago

Closing this as this issue is migrated to https://github.com/eclipse-ee4j/glassfish-hk2/issues/369