Giter Site home page Giter Site logo

stijnmoreels / fprimitive Goto Github PK

View Code? Open in Web Editor NEW
31.0 2.0 2.0 14.31 MB

.NET project to help developers to build a correct and more safe domain model

Home Page: https://stijnmoreels.github.io/FPrimitive/

License: The Unlicense

Batchfile 0.04% F# 75.97% Shell 0.47% C# 23.52%
fsharp domain model trust boundaries secure primitive types ddd untrusted

fprimitive's Introduction

NuGet Badge codecov

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.

logo

Build Status

Mono .NET
Build Status .NET Build status

Documentation

The project has a wiki page with further information and some additional resources are also listed here:

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));
	}
}

fprimitive's People

Contributors

64j0 avatar stijnmoreels avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

64j0

fprimitive's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.