Ascentis.Infrastructure 2.4.8.5

Set of small low level utilitarian classes: Retrier, ConcurrentObjectAccessor, SolidComPlus, AsyncDisposer and BoundedParallel

There is a newer version of this package available.
See the version list below for details.
Install-Package Ascentis.Infrastructure -Version 2.4.8.5
dotnet add package Ascentis.Infrastructure --version 2.4.8.5
<PackageReference Include="Ascentis.Infrastructure" Version="2.4.8.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Ascentis.Infrastructure --version 2.4.8.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Ascentis.Infrastructure, 2.4.8.5"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Ascentis.Infrastructure as a Cake Addin
#addin nuget:?package=Ascentis.Infrastructure&version=2.4.8.5

// Install Ascentis.Infrastructure as a Cake Tool
#tool nuget:?package=Ascentis.Infrastructure&version=2.4.8.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Ascentis.Infrastructure Library

This library offers a a few general purpose components:

ComPlusCache

It provides functionality similar to what MemoryCache provides.

When to use this?
If you have a model where you run in one machine a farm of processes and want a drop-in easy way to implement a shared cache of data with functionality like the one provided by MemoryCache this class can help fulfill your needs.

Some details to consider:

Strongly recommended to store data using primitive types.
String supported more efficiently using the overloaded methods that receive string as parameter. The rest of primitives supported using the other overload that receives an object (OleVariant if pure COM calls are made) as parameter.
The class supports serialized COM objects but performance is about 10x slower than serializing your object as text (JSON o XML) and then caching the text.
When passing a COM object to store in cache, a shallow copy will be performed and the resulting copied object will be stored. Currently only public properties are copied over and there's no test to verify the behavior if within those properties there's a subobject.
Current tests cover only the case of a COM DTO containing only primitive public properties.

AsyncDisposer

Use this static class to dispose of IDisposable objects using async semantics.
When to use this?
If you use third party software which you can't modify that has caused you trouble when disposing objects on an event which later makes software beyond your control throw exceptions because somewhere in the call stack it tries to use the diposed object.
With this class you can enqueue the IDisposable instance in the AsyncDisposer queue and it will be guaranteed to stay in queue for a specified global period of time before being take for disposal.
Tune the timing in a way that gives time enough for the calling procedure in the stack to complete and return to the caller.

A second class part of this package is ConcurrentObjectAccessor<>. This class allows to wrap an object within it and allow for protected access
to execute functions within a readlock. This allows usage of method SwapAndExecute() which allow to swap safely the underlying reference wrapped.
When to use this? When dealing with COM, COM+ or DCOM objects prone to crashing or suffering from network partitions. With this class the COM
object can be isolated behing a wrapper relying on ConcurrentObjectAccessor and the low level object can be replaced transparently upon detection
of partition exception.

Retrier

This class allows to wrap function or procedure calls in a try-catch block that would retry operations based on on a delegate function returning
true or false. Can be combined with ConcurrentObjectAccessor to replace transparently a low level object upon certain conditions.

ConcurrentObjectAccessor

This class allows to control usage of an object reference permitting multiple concurrent threads using it for reading its value (and executing code with it),
while only one thread can write to the reference at the same time. The main purpose is to replace a failing object transparently upon detection of a faulty condition.
A concrete example is a COM+ object which crashed. The reference to this object is worthless until replaced by a new COM+ object instance.

SolidComPlus

This class encapsulates a COM+ object instance allowing the user to implement automatic swapping of a dead object.

SimpleMemoryCache

Replacement for standard .NET MemoryCache based on ConcurrentDictionary. After opening the hood on MemoryCache found it over-complicated for most uses compared with ConcurrentDictionary.
This class is based on ConcurrentDictionary and provides expiration like MemoryCache using an ancillary timer.

BoundedParallel

Use instead of standard static Parallel class to gain control of the number of concurrent calls that be executed using Parallel static class. This allows to control the number of threads
from the default .NET threadpool to avoid a runaway scenario where .NET has to keep trying to add more threads. If a high number of callers attempt multiple concurrent calls to Parallel methods
it can fall into what's called "Hill Climbing" algorithm causing high contention as .NET tries to add more threads slowly

Ascentis.Infrastructure Library

This library offers a a few general purpose components:

ComPlusCache

It provides functionality similar to what MemoryCache provides.

When to use this?
If you have a model where you run in one machine a farm of processes and want a drop-in easy way to implement a shared cache of data with functionality like the one provided by MemoryCache this class can help fulfill your needs.

Some details to consider:

Strongly recommended to store data using primitive types.
String supported more efficiently using the overloaded methods that receive string as parameter. The rest of primitives supported using the other overload that receives an object (OleVariant if pure COM calls are made) as parameter.
The class supports serialized COM objects but performance is about 10x slower than serializing your object as text (JSON o XML) and then caching the text.
When passing a COM object to store in cache, a shallow copy will be performed and the resulting copied object will be stored. Currently only public properties are copied over and there's no test to verify the behavior if within those properties there's a subobject.
Current tests cover only the case of a COM DTO containing only primitive public properties.

AsyncDisposer

Use this static class to dispose of IDisposable objects using async semantics.
When to use this?
If you use third party software which you can't modify that has caused you trouble when disposing objects on an event which later makes software beyond your control throw exceptions because somewhere in the call stack it tries to use the diposed object.
With this class you can enqueue the IDisposable instance in the AsyncDisposer queue and it will be guaranteed to stay in queue for a specified global period of time before being take for disposal.
Tune the timing in a way that gives time enough for the calling procedure in the stack to complete and return to the caller.

A second class part of this package is ConcurrentObjectAccessor<>. This class allows to wrap an object within it and allow for protected access
to execute functions within a readlock. This allows usage of method SwapAndExecute() which allow to swap safely the underlying reference wrapped.
When to use this? When dealing with COM, COM+ or DCOM objects prone to crashing or suffering from network partitions. With this class the COM
object can be isolated behing a wrapper relying on ConcurrentObjectAccessor and the low level object can be replaced transparently upon detection
of partition exception.

Retrier

This class allows to wrap function or procedure calls in a try-catch block that would retry operations based on on a delegate function returning
true or false. Can be combined with ConcurrentObjectAccessor to replace transparently a low level object upon certain conditions.

ConcurrentObjectAccessor

This class allows to control usage of an object reference permitting multiple concurrent threads using it for reading its value (and executing code with it),
while only one thread can write to the reference at the same time. The main purpose is to replace a failing object transparently upon detection of a faulty condition.
A concrete example is a COM+ object which crashed. The reference to this object is worthless until replaced by a new COM+ object instance.

SolidComPlus

This class encapsulates a COM+ object instance allowing the user to implement automatic swapping of a dead object.

SimpleMemoryCache

Replacement for standard .NET MemoryCache based on ConcurrentDictionary. After opening the hood on MemoryCache found it over-complicated for most uses compared with ConcurrentDictionary.
This class is based on ConcurrentDictionary and provides expiration like MemoryCache using an ancillary timer.

BoundedParallel

Use instead of standard static Parallel class to gain control of the number of concurrent calls that be executed using Parallel static class. This allows to control the number of threads
from the default .NET threadpool to avoid a runaway scenario where .NET has to keep trying to add more threads. If a high number of callers attempt multiple concurrent calls to Parallel methods
it can fall into what's called "Hill Climbing" algorithm causing high contention as .NET tries to add more threads slowly

Release Notes

Added support to use all possible and allowed threads by overriding the maximum number of parallel threads when possible

Dependencies

This package has no dependencies.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Ascentis.Infrastructure:

Package Downloads
Ascentis.SQLRewriteInterceptor
Utility class to use with ADO.NET that allows pre-processing any SQL used vua SqlCommand class in order to allow optimization/hinting in production environments without recompiling code
Ascentis.ExternalCache
External cache class using .NET COM+
Ascentis.Infrastructure.Sql
SqlClient and SQLite specific set of classes extending behavior of DataPipeline and DataReplicator classes provided in Ascentis.Infrastructure base package

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
2.13.2.29 226 9/18/2020
2.13.1.28 186 9/16/2020
2.13.0.27 211 9/16/2020
2.12.0.26 145 9/14/2020
2.11.0.25 153 9/14/2020
2.11.0.24 149 9/14/2020
2.10.0.23 267 9/7/2020
2.9.0.22 688 8/26/2020
2.8.3.21 151 8/25/2020
2.8.2.20 222 8/21/2020
2.8.0.19 170 8/21/2020
2.7.14.18 136 8/20/2020
2.7.13.17 150 8/18/2020
2.7.12.16 159 8/18/2020
2.7.11.15 166 8/17/2020
2.7.10.14 139 8/17/2020
2.7.9.13 250 8/17/2020
2.7.8.12 201 8/14/2020
2.7.7.11 200 8/14/2020
2.7.6.10 173 8/14/2020
2.7.5.9 148 8/13/2020
2.7.4.8 177 8/13/2020
2.7.3.7 165 8/13/2020
2.7.2.6 163 8/12/2020
2.7.1.5 148 8/12/2020
2.6.1.4 247 8/11/2020
2.6.0.3 270 8/11/2020
2.5.0.2 132 8/4/2020
2.4.12.1 227 8/1/2020
2.4.11 200 7/30/2020
2.4.10 200 7/28/2020
2.4.9 281 7/26/2020
2.4.8.7 306 7/25/2020
2.4.8.6 162 7/24/2020
2.4.8.5 223 7/23/2020
2.4.8.4 177 7/22/2020
2.4.8.3 191 7/22/2020
2.4.8.2 237 7/21/2020
2.4.8.1 181 7/21/2020
2.4.8 157 7/21/2020
2.4.7.1 177 7/21/2020
2.4.7 148 7/21/2020
2.4.6.1 156 7/21/2020
2.4.6 164 7/21/2020
2.4.5 223 7/20/2020
2.4.4.1 196 7/13/2020
2.4.4 193 7/7/2020
2.4.3.1 158 6/30/2020
2.4.3 159 6/30/2020
2.4.2 266 6/29/2020
2.4.1 186 6/29/2020
2.4.0 193 6/29/2020
2.3.0 411 6/22/2020
2.2.0 150 6/18/2020
2.1.0 164 6/16/2020
2.0.0 200 6/15/2020
Show less