Shielded alternatives and similar packages
Based on the "Misc" category.
Alternatively, view Shielded alternatives based on common mentions on social networks and blogs.
-
Polly
Polly is a .NET resilience and transient-fault-handling library that allows developers to express policies such as Retry, Circuit Breaker, Timeout, Bulkhead Isolation, and Fallback in a fluent and thread-safe manner. From version 6.0.1, Polly targets .NET Standard 1.1 and 2.0+. -
FluentValidation
A popular .NET validation library for building strongly-typed validation rules. -
Humanizer
Humanizer meets all your .NET needs for manipulating and displaying strings, enums, dates, times, timespans, numbers and quantities -
Edge.js
Run .NET and Node.js code in-process on Windows, MacOS, and Linux -
ReactJS.NET
.NET library for JSX compilation and server-side rendering of React components -
ScriptCS
Write C# apps with a text editor, nuget and the power of Roslyn! -
Hashids.net
A small .NET package to generate YouTube-like hashes from one or many numbers. Use hashids when you do not want to expose your database ids to the user. -
Coravel
Near-zero config .NET library that makes advanced application features like Task Scheduling, Caching, Queuing, Event Broadcasting, and more a breeze! -
Enums.NET
Enums.NET is a high-performance type-safe .NET enum utility library -
Scientist.NET
A .NET library for carefully refactoring critical paths. It's a port of GitHub's Ruby Scientist library -
WorkflowEngine
WorkflowEngine.NET - component that adds workflow in your application. It can be fully integrated into your application, or be in the form of a specific service (such as a web service). -
HidLibrary
This library enables you to enumerate and communicate with Hid compatible USB devices in .NET. -
Warden
Define "health checks" for your applications, resources and infrastructure. Keep your Warden on the watch. -
DeviceId
A simple library providing functionality to generate a 'device ID' that can be used to uniquely identify a computer. -
Aeron.NET
Efficient reliable UDP unicast, UDP multicast, and IPC message transport - .NET port of Aeron -
ByteSize
ByteSize is a utility class that makes byte size representation in code easier by removing ambiguity of the value being represented. ByteSize is to bytes what System.TimeSpan is to time. -
Streams
A lightweight F#/C# library for efficient functional-style pipelines on streams of data. -
Jering.Javascript.NodeJS
Invoke Javascript in NodeJS, from C# -
LINQPad.QueryPlanVisualizer
SQL Server and PostgreSQL query execution plan visualizer for LINQPad -
Mediator.Net
A simple mediator for .Net for sending command, publishing event and request response with pipelines supported -
Valit
Valit is dead simple validation for .NET Core. No more if-statements all around your code. Write nice and clean fluent validators instead! -
DeviceDetector.NET
The Universal Device Detection library will parse any User Agent and detect the browser, operating system, device used (desktop, tablet, mobile, tv, cars, console, etc.), brand and model. -
https://github.com/minhhungit/ConsoleTableExt
A fluent library to print out a nicely formatted table in a console application C# -
FormHelper
ASP.NET Core - Transform server-side validations to client-side without writing any javascript code. (Compatible with Fluent Validation) -
SolidSoils4Arduino
C# .NET - Arduino library supporting simultaneous serial ASCII, Firmata and I2C communication -
Validot
Validot is a performance-first, compact library for advanced model validation. Using a simple declarative fluent interface, it efficiently handles classes, structs, nested members, collections, nullables, plus any relation or combination of them. It also supports translations, custom logic extensions with tests, and DI containers. -
Outcome.NET
Never write a result wrapper again! Outcome.NET is a simple, powerful helper for methods that return a value, but sometimes also need to return validation messages, warnings, or a success bit. -
NaturalSort.Extension
🔀 Extension method for StringComparison that adds support for natural sorting (e.g. "abc1", "abc2", "abc10" instead of "abc1", "abc10", "abc2"). -
FlatMapper
FlatMapper is a library to import and export data from and to plain text files. -
AzureCrawler
Take HTML Snapshots for your Angular, Ember, Durandal or any JavaScript applications -
SystemTextJson.JsonDiffPatch
High-performance, low-allocating JSON object diff and patch extension for System.Text.Json. Support generating patch document in RFC 6902 JSON Patch format. -
BerTlv.NET
A library for parsing BER TLV data (like EMV credit cards). -
trybot
A transient fault handling framework including such resiliency solutions as Retry, Timeout, Fallback, Rate Limit and Circuit Breaker. -
AdaskoTheBeAsT.FluentValidation.MediatR
FluentValidation behavior for MediatR
Static code analysis for 29 languages.
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of Shielded or a related project?
README
Shielded
Available on NuGet.
Shielded is a full-featured implementation of Software Transactional Memory in .NET. It provides a system (the Shield static class) for running in-memory transactions, and data structures which are aware of transactions. It can also generate transaction-aware proxy subclasses based on a POCO class type (only supported on the .NET Framework, not on .NET Standard). The implementation is strict, with strong guarantees on safety. It is mostly lock-free, using only one major lock which is held during the pre-commit check.
Here is a small example:
var n = new Shielded<int>();
int a = n;
Shield.InTransaction(() =>
n.Value = n + 5);
Shielded fields are thread-safe. You can read them out of transaction, but changes must be done inside. While inside, the library guarantees a consistent view of all shielded fields.
Another example, the STM version of "Hello world!" - parallel addition in an array. Here, in a dictionary:
var dict = new ShieldedDict<int, int>();
ParallelEnumerable.Range(0, 100000)
.ForAll(i => Shield.InTransaction(() =>
dict[i % 100] = dict.ContainsKey(i % 100) ? dict[i % 100] + 1 : 1));
Shielded works with value types, and the language automatically does the needed cloning. For ref types, it only makes the reference itself transactional. The class should then be immutable, or, if you're targetting the full .NET Framework, and if you have a class you want to make transactional:
public class TestClass {
public virtual Guid Id { get; set; }
public virtual string Name { get; set; }
}
Then you create instances like this:
using Shielded.ProxyGen;
...
var t = Factory.NewShielded<TestClass>();
The Factory creates a proxy sub-class, using CodeDom, which will have transactional overrides for all virtual properties of the base class that are public or protected. Due to CodeDom limitations, the getter and setter must have the same accessibility! The proxy objects are thread-safe (or, at least their virtual properties are), and can only be changed inside transactions.
Since CodeDom is not available on .NET Standard, this feature is currently not supported if you're not targeting the full .NET Framework.
Usage is simple:
var id = t.Id;
Shield.InTransaction(() =>
t.Name = "Test object");
It is safe to execute any number of concurrent transactions that are reading from or writing into the same shielded fields - each transaction will complete correctly. This is accomplished by:
- ensuring that in one transaction you read a consistent state of all shielded fields
- buffering writes into storage which is local for each thread
Your changes are commited and made visible to other threads only if all the shielded fields you read or wrote into have not changed since you started. If any have new changes, your transaction is retried from the beginning, but this time reading the new data. Though it may seem so, this cannot create an infinite loop since for any conflict to occur at least one transaction must successfully commit. Overall, the system must make progress.
This quality would place Shielded in the lock-free class of non-blocking concurrency mechanisms, according to academic classification. However, this is not accurate since the commit check gets done under a lock. Hence the word "mostly" in the short description.
Features
- MVCC: Each transaction reads a consistent snapshot of the state without
the need for locking, since updates just create new versions.
- Old versions are dropped soon after no one is capable of reading them any more.
- Read-only transactions always complete without any repetitions and without entering the global lock!
- Strictness: If a write is made anywhere, the system will insist that all touched locations, read or written, still contain the same version of data that they had when the transaction opened. This means it does not suffer from the Write Skew issue.
- Transactional collections: Included in the library are ShieldedDict<>
(dictionary), ShieldedSeq<> (singly linked list) and ShieldedTree<> (a
red-black tree implementation).
- It is possible to use this library with immutable collections from System.Collections.Immutable.
- Transaction-local storage: ShieldedLocal<> allows storing anything in the transaction context, visible only from within that transaction.
- To perform side-effects (IO, and most other operations which are not shielded) you use the SideEffect method of the Shield class, which takes optional onCommit and onRollback lambdas, or the SyncSideEffect method which allows you to execute code during a commit, while the changed fields are still locked.
- Conditional transactions: Method Shield.Conditional allows you
to define something similar to a database AFTER trigger. It receives a test, and
an action to perform, both lambdas. It runs the test, makes a note of
all shielded objects that the test had accessed, and later re-executes
the test when any of those objects is committed into. If test passes, the
action is called.
- Implemented transactionally, so can be called from transactions, and can be triggered by the transaction that created it.
- Returns an IDisposable for deactivating the subscription, also transactionally. It may even deactivate itself, e.g. to guarantee one-time execution.
- Pre-commit checks: Shield.PreCommit is very similar to Shield.Conditional,
but executes the test within a transaction that changes one of the fields it is
interested in, just before that transaction will commit.
- Can be used to ensure certain invariants are held, or to implement thread prioritization by allowing only some threads which access a field to commit into it.
- Custom commit operations: You can integrate your own code into the commit process,
to execute while the shielded fields, that are being written, are held locked.
- Already mentioned Shield.SyncSideEffect does this on the level of one transaction.
- Using Shield.WhenCommitting, you subscribe globally for any commit, or based on the type of field being written. These subscriptions should never throw!
- Shield.RunToCommit runs a transaction just up to commit, and allows you to commit/rollback later, or from another thread. This is useful for asynchronous programming.
Commutables: operations which can be performed without conflict, because they can be reordered in time and have the same net effect, i.e. they are commutable (name borrowed from Clojure). Incrementing an int is an example - if you don’t care what the int’s value is, you can increment it without conflict by simply incrementing whatever value you encounter there at commit time. Using commutes, when appropriate, reduces conflicts and improves concurrency. Incrementing an int, conflict-free:
n.Commute((ref int a) => a++);
- Commutes are not performed under any lock, but rather in a special commute subtransaction, which reads the latest data, and tries to commit with the same stamp as your main transaction. If only the commutes fail, then only the commutes get retried.
- If, in the example above, your main transaction has already (or perhaps will later) read the n field or written to it (non-commutatively), the commute “degenerates” - it gets executed in place, in your transaction, and you can see it’s effect. This means consistency - if you read it, it will stay as read when you commit. But, it is now a potential conflict.
- Shield has various commutable operations defined in it. Appending to a sequence is commutable - if you do not touch the seq, it never conflicts. Collection Count fields are comuted over, to avoid unnecessary conflicts.