Extract provider creation into a generic function