Generated Code¶
The SmsModule declaration generates effect methods and DI registration. The generated layer wraps the hand-written ISmsService interface.
What Gets Generated¶
Given:
[EffectsModule(typeof(ISmsService))]
[ServiceRegistration(nameof(AddDefaultSms))]
public static partial class SmsModule
{
public static void AddDefaultSms(this IServiceCollection services)
{
services.TryAddSingleton<ISmsService, InMemorySmsService>();
}
}
Effect Methods¶
public static partial class SmsModule
{
public static partial class Sms
{
public static Eff<RT, SmsResult> SendAsync<RT>(SmsMessage message)
where RT : IHasSmsService =>
liftEff<RT, SmsResult>(async rt =>
await rt.SmsService.SendAsync(message));
public static Eff<RT, SmsResult> GetStatusAsync<RT>(SmsMessageId messageId)
where RT : IHasSmsService =>
liftEff<RT, SmsResult>(async rt =>
await rt.SmsService.GetStatusAsync(messageId));
}
}
Capability Interface¶
DI Registration¶
AddDefaultSms() uses TryAddSingleton — production providers (Twilio, Bandwidth) registered first take priority over InMemorySmsService.
Using Without Effects¶
public class NotificationService(ISmsService smsService)
{
public async Task SendVerification(PhoneNumber phone, string code)
{
await smsService.SendAsync(new SmsMessage
{
From = new PhoneNumber("+15551234567"),
To = phone,
Body = $"Your code is {code}"
});
}
}
For functional effect composition, see Effects Composition.