CrowRx.Singleton
1.0.3
dotnet add package CrowRx.Singleton --version 1.0.3
NuGet\Install-Package CrowRx.Singleton -Version 1.0.3
<PackageReference Include="CrowRx.Singleton" Version="1.0.3" />
<PackageVersion Include="CrowRx.Singleton" Version="1.0.3" />
<PackageReference Include="CrowRx.Singleton" />
paket add CrowRx.Singleton --version 1.0.3
#r "nuget: CrowRx.Singleton, 1.0.3"
#:package CrowRx.Singleton@1.0.3
#addin nuget:?package=CrowRx.Singleton&version=1.0.3
#tool nuget:?package=CrowRx.Singleton&version=1.0.3
CrowRx.Singleton
A lightweight, interface-driven Singleton utility library for Native C# Objects (non-UnityEngine.Object types) in .NET and Unity.
Features
- Generic Singleton: Provide a simple way to implement the singleton pattern for standard C# classes.
- Native Object Only: Specifically designed for POCOs (Plain Old CLR Objects), not
MonoBehaviourorScriptableObject. - Lifecycle Management: Supports
Init()andRelease()methods through theIInstanceinterface. - Unity Editor Integration: When running in the Unity Editor, it automatically hooks into the
playModeStateChangedevent to callRelease()and clear the static instance when exiting Play Mode.
Requirements
- .NET Standard 2.1 compatible environment
- (Optional) Unity 6.0 or newer for automatic Editor lifecycle management
Installation
Install via NuGet.
Usage
1. Define your Singleton
Inherit from Native<T> and implement the IInstance interface.
using CrowRx.Singleton;
public class MySystem : Native<MySystem>, IInstance
{
public void Init()
{
// Called automatically when the instance is first created
}
public void Release()
{
// Cleanup logic
}
}
2. Access the Instance
The instance is lazily initialized on the first access to the Instance property.
// Access the singleton
MySystem.Instance.DoSomething();
// Check if the instance is currently active
if (MySystem.IsValid)
{
// ...
}
Unity Editor Specific Behavior
While this library works in any .NET environment, it includes specialized behavior for the Unity Editor:
- When
Instanceis first accessed in the Editor, it registers a callback toUnityEditor.EditorApplication.playModeStateChanged. - When you exit Play Mode,
Release()is automatically called on the instance, and the static reference is set tonull. - This ensures that your singleton state does not persist between Play Mode sessions, preventing common memory leaks and state bugs in Editor tools.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- CrowRx.Core (>= 1.0.6)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on CrowRx.Singleton:
| Package | Downloads |
|---|---|
|
CrowRx.SingleStream
A Single-Stream utility library for CrowRx. This package is intended for use with Unity3D 6.0 or newer only. |
GitHub repositories
This package is not used by any popular GitHub repositories.