The static API (IcalCodec, ImipMessageComposer) needs no setup. Register the services when you want the
codec and the composer injected, a PRODID and parse limits configured once, or a substitute in tests.
using DevOp.ICalendar;
builder.Services.AddDevOpICalendar(options =>
{
options.DefaultProdId = "-//Example Corp//Calendar//EN";
options.ParseLimits = options.ParseLimits with { MaxInputLength = 262_144 };
});
or from configuration:
builder.Services.AddDevOpICalendar(builder.Configuration.GetSection(IcalendarOptions.SectionName));
{
"DevOp": {
"ICalendar": {
"DefaultProdId": "-//Example Corp//Calendar//EN",
"ParseLimits": { "MaxInputLength": 262144, "MaxComponents": 200 }
}
}
}
AddDevOpICalendar() with no argument keeps the defaults. The extension methods are in the
Microsoft.Extensions.DependencyInjection namespace.
| Service | Default implementation | Lifetime |
|---|---|---|
IIcalendarCodec |
DefaultIcalendarCodec |
Singleton |
IImipMessageComposer |
DefaultImipMessageComposer |
Singleton |
IOptions<IcalendarOptions> |
Singleton, validated at startup |
Registration uses TryAdd: a service you registered before calling AddDevOpICalendar is kept, and calling it
twice registers each service once. Both implementations are thread-safe.
IIcalendarCodec has Serialize(document), Serialize(components, method, prodId), SerializeComponent,
Parse and ReadMethod. It delegates to IcalCodec, so the output is byte-for-byte the same as the static API's,
with two differences: DefaultProdId is used when neither the document nor the call names a PRODID, and Parse
applies ParseLimits. IImipMessageComposer has Compose and ComposeToStream and delegates to
ImipMessageComposer unchanged.
public sealed class InvitationSender(IIcalendarCodec codec, IImipMessageComposer composer)
{
public MemoryStream Render(IcalComponent meeting, string from, string to)
{
var ics = codec.Serialize([meeting], ItipMethod.Request);
return composer.ComposeToStream(new ImipMessage
{
From = from,
To = [to],
Subject = meeting.Summary ?? "Invitation",
Calendar = ImipEnvelope.ForOutbound(ics, ItipMethod.Request),
});
}
}
| Option | Default | Rule |
|---|---|---|
DefaultProdId |
-//DevOp//DevOp.ICalendar//EN |
Not blank, no control characters. |
ParseLimits.MaxInputLength |
1,048,576 | Positive. |
ParseLimits.MaxComponents |
1,000 | Positive. |
ParseLimits.MaxPropertiesPerComponent |
1,000 | Positive. |
ParseLimits.MaxLineLength |
65,536 | Positive. |
ParseLimits.MaxNestingDepth |
8 | Positive. |
ParseLimits.MaxTzidLength |
256 | Positive. |
The limits are described on the security page. Invalid options fail at host start
(ValidateOnStart) with an OptionsValidationException that names each bad value, rather than at the first parse.
Each options object has its own ParseLimits instance, so binding configuration never changes
IcalParseLimits.Default.
There is no clock option: the codec never stamps DTSTAMP itself (it falls back to Start), so it has nothing to
read a time from.
ValidateOnStart runs when a generic host starts. Without one, resolve IOptions<IcalendarOptions> once at
startup (or call IStartupValidator.Validate()) to validate early.