Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stevenmhunt/tls-helper
Provides a convenient mechanism for creating Thread Local Storage objects in .NET based on what type of application you are creating.
https://github.com/stevenmhunt/tls-helper
Last synced: about 1 month ago
JSON representation
Provides a convenient mechanism for creating Thread Local Storage objects in .NET based on what type of application you are creating.
- Host: GitHub
- URL: https://github.com/stevenmhunt/tls-helper
- Owner: stevenmhunt
- Created: 2013-03-03T13:50:36.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2013-03-05T06:43:25.000Z (almost 12 years ago)
- Last Synced: 2023-03-29T04:16:46.633Z (over 1 year ago)
- Language: C#
- Size: 113 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
TLS Helper
==========Provides a convenient mechanism for creating Thread Local Storage objects in .NET based on what type of application you are creating.
The library uses a provider model implemented using the ITlsProvider interface. The code ships with two implementations, ThreadStaticProvider which wraps a conventional [ThreadStatic] TLS implementation, and HttpContextProvider which handles TLS in an ASP .NET environment.
The advantage of this library over hand-coding these scenarios is that the library can determine which provider to use based on the environment of the application your code runs in. For instance, if there is a current http context, the HttpContextProvider will be used. The library will fall back on ThreadStaticProvider if no other providers are valid. Also, you can also implement your own version of ITlsProvider and register it using the static method TlsHelper.AddProvider(ITlsProvider).
How To Use
----------Here is a sample on how to use the code.
```C#
using System;
using StevenHunt.Tls;
...
var myvar = new TlsHelper("myvar", () => "initial value");
Console.WriteLine(myvar.HasValue);
Console.WriteLine(myvar.Value);myvar.Value = "new value";
Console.WriteLine(myvar.HasValue);
Console.WriteLine(myvar.Value);```
TlsHelper is a generic class, so tell it what data type your variable should contain. The constructor takes two parameters: a unique name to identify your object by, and an initializer function which provides your object with a lazily-loaded value.
To get or set the value, use the Value property.