Factory for object creation and dependency injection.