Ephemeral Data

Ephemeral Data Model for managing data validity

Ephemeral Data
Photo by Rich @ rhubbardstockfootage / Unsplash
dotnet add package H.Necessaire

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:

H.Necessaire/Src/H.Necessaire/H.Necessaire/Models/IEphemeralType.cs at master · hinteadan/H.Necessaire
A collection of useful data and execution extensions for .NET - hinteadan/H.Necessaire

Full definition of IEphemeralType

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:

H.Necessaire/Src/H.Necessaire/H.Necessaire/Models/EphemeralTypeBase.cs at master · hinteadan/H.Necessaire
A collection of useful data and execution extensions for .NET - hinteadan/H.Necessaire

EphemeralTypeBase

H.Necessaire/Src/H.Necessaire/H.Necessaire/Models/EphemeralType.cs at master · hinteadan/H.Necessaire
A collection of useful data and execution extensions for .NET - hinteadan/H.Necessaire

EphemeralType