[DependencyInjection] Added support for closure as a factory method