The ChannelAdam Weak Events Library

Overview

An open source, .NET Standard 2.0 library for events that enforces a weak reference to the event handler.

You may need a Weak Event Pattern in specific circumstances to prevent memory leaks in your event listeners.

Below are the main features of the library. See the linked code for details.

Please contact me if you have any questions.

Getting Started

NuGet Package Installation

To install the ChannelAdam.WeakEvents NuGet package run the following command in the Package Manager Console:

1PM> Install-Package ChannelAdam.WeakEvents

Usage

 1using ChannelAdam.Events;
 2...
 3
 4public class ExampleEventOwner
 5{
 6    private WeakEvent<EventArgs> _myEvent = new WeakEvent<EventArgs>();
 7
 8    public IWeakEvent<EventArgs> MyEvent
 9    {
10        get { return _myEvent; }
11    }
12
13    ...
14
15    protected virtual void OnMyEvent()
16    {
17        _myEvent.Invoke(this, EventArgs.Empty);
18    }
19}
20
21
22public class ExampleEventSubscriber : ChannelAdam.Disposing.DisposableWithDestructor
23{
24    private ExampleEventOwner _eventOwner;
25
26    public ExampleEventSubscriber()
27    {
28        _eventOwner = new ExampleEventOwner()
29        _eventOwner.MyEvent.Subscribe(MyEventHandler);
30    }
31
32    private void MyEventHandler(object sender, EventArgs e)
33    {
34        // MyEvent occurred
35    }
36
37    protected override void DisposeManagedResources()
38    {
39        _eventOwner?.MyEvent?.Unsubscribe(MyEventHandler);
40    }
41}

Reference

The ChannelAdam Commands Library

Overview

An open source, .NET Standard 1.1 library implementation of the Command Pattern - including reversible commands.

Below are the main features of the library. See the linked code for details.

Please contact me if you have any questions.

Getting Started

NuGet Package Installation

To install the ChannelAdam.Commands NuGet package run the following command in the Package Manager Console:

1PM> Install-Package ChannelAdam.Commands

Usage

An example of the ReversibleCommandManager, using the ExecuteSetPropertyCommand and UndoPreviousCommand methods:

 1var testObject = new ClassWithProperty
 2{
 3    MyProperty = 1
 4};
 5
 6var commandManager = new ReversibleCommandManager();
 7
 8commandManager.ExecuteSetPropertyCommand(testObject, p => p.MyProperty, 100);
 9commandManager.ExecuteSetPropertyCommand(testObject, p => p.MyProperty, 200);
10
11commandManager.UndoPreviousCommand();
12// MyProperty is now back to 100

Reference

Command Action

A Command Action has an Execute method with a void return parameter.

Command Function

A Command Function has an Execute method with a specified return parameter.

Reversible Commands

Need to execute some commands and be able to undo them? This Reversible Command implementation is for you!

Use the Reversible Command Manager to manage the stack of commands that can be reversed.

Set Property - Command Implementation

A command implementation for setting a property on an object.

The ChannelAdam Dispatch Proxies Library

Overview

An open source, .NET Standard 1.3 library implementation of disposable and retry-enabled dispatch proxies.

Below are the main features of the library. See the linked code for details.

Please contact me if you have any questions.

Getting Started

NuGet Package Installation

To install the ChannelAdam.DispatchProxies NuGet package run the following command in the Package Manager Console:

1PM> Install-Package ChannelAdam.DispatchProxies

Usage

An example of the RetryEnabledObjectDisposableDispatchProxy and a custom SimpleRetryPolicyFunction class:

1int retriesCount = 3;
2
3var myService = new MyService();
4
5var retryEnabledProxyOfMyService = RetryEnabledObjectDisposableDispatchProxy.Create<IMyService>(
6    myService,
7    new SimpleRetryPolicyFunction(this.retriesCount));

See the Behaviour Specifications for more examples, such as the TestObjectDispatchProxy.

Reference

The ChannelAdam Disposing Library

Overview

Have you ever thought that the .NET disposable pattern was complicated to implement or understand? Inherit from one of these classes and it’s easy!

This is open source .NET Standard 1.3 library with a correct implementation of the dispose/finalize pattern that is easily used and extended.

Below are the main features of the library. See the linked code for details.

Please contact me if you have any questions.

Getting Started

NuGet Package Installation

To install the ChannelAdam.Disposing NuGet package run the following command in the Package Manager Console:

1PM> Install-Package ChannelAdam.Disposing

Usage

Simply inherit from Disposable or DisposableWithDestructor and override DisposeManagedResources() and/or DisposeUnmanagedResources().

Reference

The ChannelAdam Core Library

IMPORTANT: DEPRECATION NOTICE

This full .NET Framework library has been deprecated.

The functionality has been refactored out into the following ChannelAdam .NET Standard libraries.

Overview

The open source, full .NET Framework, ChannelAdam Core Library provides some helpful .NET functionality - such as the implementation of various design patterns. This functionality also just happens to be used in the other ChannelAdam code libraries…

Below are the main features of the library. See the linked code for details.

Please contact me if you have any questions.

Getting Started

NuGet Package Installation

To install the ChannelAdam.Core NuGet package run the following command in the Package Manager Console:

1PM> Install-Package ChannelAdam.Core

Features

Disposable Pattern

Have you ever thought that the disposable pattern was complicated to implement or understand? Inherit this and it’s easy!

Command Pattern

Have you ever needed to implement a Command Pattern?

Command Action

A Command Action has an Execute method with a void return parameter.

Command Function

A Command Function has an Execute method with a specified return parameter.

Reversible Commands

Need to execute some commands and be able to undo them? This Reversible Command implementation is for you!

Use the Reversible Command Manager to manage the stack of commands that can be reversed.

Set Property - Command Implementation

A command implementation for setting a property on an object.

Weak Event Pattern

Need a Weak Event in specific circumstances to prevent memory leaks in your event listeners?

Simple Logger

A very simple interface for logging or writing out to the console.

Embedded Resources

Easily retreive embedded resources from their manifest resource stream.

Real Proxies

Getting low-level with a Real Proxy? These are disposable and have retry capability!

Retry Policies (for Transient Fault Handling)

Some handy interfaces to describe retry policies.

XML

XML validation, serialisation and type conversion made easy.