move repository connection into try-with-resources