Using the dependency injection system
Dependency injection is a technique for obtaining a class's dependencies. It separates creating a class from using that class.
Assume that we have a UserRegistrationService class that uses SmsService to send a verification SMS, as shown in the following code block:
public class UserRegistrationService
{
    private readonly SmsService _smsService;
    public UserRegistrationService(SmsService smsService)
    {
        _smsService = smsService;
    }
    public async Task RegisterAsync(
        string username,
        string password,
        string phoneNumber)
    {
        //...save user in the database
  ...