FPrimitive
.NET project to help developers to build a correct and more safe domain model
Install / Use
/learn @stijnmoreels/FPrimitiveREADME
FPrimitive
FPrimitive is a .NET project to help developers build a correct and more secure domain model by providing building blocks, standard types and trust boundaries.
<img src="/docs/img/logo.png" width=100 height=100 alt="logo" />Build Status
| Mono | .NET |
| --------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| |
|
Documentation
The project has a wiki page with further information and some additional resources are also listed here:
- Library Documentation Page
- Domain-Driven Security w/ F# FPrimitive & C# Interop
- From Untrusted Input to Strict Model w/ Layered JSON Parsing in F# FPrimitive
Examples
The project contains several reusable building blocks to make your domain model more correct and therefore more secure.
open FPrimitive
/// Composible specifications for your domain types:
type NonEmptyString =
private NonEmptyString of string with
static member create x : Result<NonEmptyString, Map<string, string list>> =
Spec.def<string>
|> Spec.notNull "should not be null"
|> Spec.notEmpty "should not be empty"
|> Spec.createModel NonEmptyString x
/// ...also available as computation expression.
type NonEmptyList<'a> =
private NonEmptyList of 'a list with
static member create xs : Result<NonEmptyList<'a>, Map<string, string list>> =
specModel NonEmptyList xs {
nonEmpty "list should not be empty"
lengthBetween 1 10 "list length should be between 1-10" }
/// Access controllers for your critical application resources:
let uncontrolled_critical = ignore
let critical =
Access.func uncontrolled_critical
|> Access.once
|> Access.duringHours 9 17
|> Access.revokable
/// Try to evaluate
Access.eval () critical
/// Revoke when neccessary
Access.revoke critical
With full C# support!
using FPrimitive;
public class PositiveInt
{
private PrositiveInt(int value) { Value = int; }
public int value { get; }
public static ValidationResult<PositiveInt> Create(int value)
{
return Spec.Of<int>()
.GreaterThan(0, "Positive integer should be greater than zero")
.CreateModel(value, validated => new PositiveInt(validated));
}
}
Related Skills
node-connect
351.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
110.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
351.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
351.2kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
