Ephemeral Data
Ephemeral Data Model for managing data validity
dotnet add package H.Necessaire
H.Necessaire proposes and provides a common model for managing data validity, or as I like to call it, ephemeral data.
Meaning storing info about when the given data becomes active, and when it expires.
For example, authentication data like security tokens, or vouchers, or promotional prices, or food supplies, or products with expiration date, etc.
The core model is the IEphemeralType
data contract, with the following main properties:
interface IEphemeralType
{
DateTime CreatedAt
DateTime AsOf
DateTime ValidFrom
TimeSpan? ValidFor
DateTime? ExpiresAt
}
interface IEphemeralType<TPayload> : IEphemeralType
{
TPayload Payload
}
Full definition on GitHub:
Concrete
For easy usage, H.Necessaire also comes with two implementations of IEphemeralType
data contract.
One is an abstract type that needs to be derived and populated with the data properties.
abstract class EphemeralTypeBase : IEphemeralType
The other one is a straight-forward, ready to use, generic type.
class EphemeralType<TPayload> : EphemeralTypeBase, IEphemeralType<TPayload>
Full code on GitHub: