How do I conditionally register components?

Note for doc writing: This will be about using modules or XML config to do the logic.