using System.Collections.Generic;
using System.Threading.Tasks;
public interface INotificationService
Task SendEmailAsync(string to, string subject, string body);
public sealed class NotificationService : INotificationService
public async Task SendEmailAsync(string to, string subject, string body)
using(var httpClient = new HttpClient())
var response = await httpClient.PostAsync("https://notification-service.com/api/emails/send", new StringContent(body));
response.EnsureSuccessStatusCode();
public string Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public sealed class ReportingService
private readonly INotificationService _notificationService;
public ReportingService(INotificationService notificationService)
_notificationService = notificationService;
public async Task SendReportsAsync(List<User> users)
foreach (var user in users)
await SendReportAsync(user);
private async Task SendReportAsync(User user)
await _notificationService.SendEmailAsync(user.Email, "Your report", $"Hi, {user.Name}!");