Use an extension function for initializing

Would it be a solution to wrap this code in another function which is called immediately?