Featurewise for .NET
A library for writing a service featurewise, in C#. Every feature has the same shape: a query, a command or a worker, taking a link and returning a result with cases. And the code that calls features has one way to call any of them.
dotnet add package Featurewise.Core --prerelease # in the service's core
dotnet add package Featurewise.Hosting --prerelease # in each entrypoint
A feature
public class CancelSend(IOutbox outbox) : Command<CancelSend.Args, CancelSend.Result>
{
public record Args(string MessageId) : Link<CancelSend, Result>;
public abstract record Result
{
private Result() { }
public record Cancelled(Messages.Args LinkToMessages) : Result;
public record AlreadySent(Messages.Args LinkToMessages) : Result;
}
public override async Task<Result> Invoke(Args args, CancellationToken cancellationToken)
{
if (await outbox.Find(args.MessageId, cancellationToken) is not { Status: MessageStatus.Queued } message)
return new Result.AlreadySent(new Messages.Args());
await outbox.Save(message with { Status = MessageStatus.Cancelled }, cancellationToken);
return new Result.Cancelled(new Messages.Args());
}
}
CancelSend.Args is the feature's input, and it's a link: a value naming the feature, with its arguments. Each result case says what happened, in words the stakeholders would recognise, and carries the links to what the caller can do next.
What it gives you
- One way to invoke any feature. Entrypoints (a UI backend, an API, a queue worker, a scheduler) hand a link to
Features, which invokes it with the same authorization, logging, tracing and cancellation every time. - Links written in the core. Because a feature's input is a link, the core makes them as ordinary values, checked by the compiler, and offers only those that would work.
- Rules beside each feature, saying who may invoke it, so a link is never offered to someone who'd be refused.
- Links on the wire, as JSON that names the feature's family, so a UI knows a query from a command before following it.
Getting started
The sample service is a minimal featurewise service, on AWS Lambda and runnable on a laptop: the place to start a new one. The demos are services built the same way, running live.
- Code: github.com/ada74m/featurewise-library, MIT licence
- Packages: Featurewise.Core and Featurewise.Hosting on nuget.org
- The ideas behind it: the book