Reduce code duplication in DI extensions.