My use case is very similar to the question asked on stack overflow. Link below
Is there a way to achieve this?