SetNet.Services
1.2.0
dotnet add package SetNet.Services --version 1.2.0
NuGet\Install-Package SetNet.Services -Version 1.2.0
<PackageReference Include="SetNet.Services" Version="1.2.0" />
<PackageVersion Include="SetNet.Services" Version="1.2.0" />
<PackageReference Include="SetNet.Services" />
paket add SetNet.Services --version 1.2.0
#r "nuget: SetNet.Services, 1.2.0"
#:package SetNet.Services@1.2.0
#addin nuget:?package=SetNet.Services&version=1.2.0
#tool nuget:?package=SetNet.Services&version=1.2.0
SetNet.Services
A tiny service locator so you stop hand-storing every UseXxx() instance. Each server.UseInventory(), server.UseDialogue(), server.UseChat() returns a hub instance that you normally have to keep in a field and thread into every class that needs it. Register each once here and resolve it anywhere by type.
using SetNet.Services;
var hub = new ServiceHub().MakeCurrent(); // ambient — set once at startup
hub.Add(server.UseLocomotion(geo));
hub.Add(server.UseMobs(opts));
hub.Add(server.UseDialogue());
hub.Add(server.UseChat());
// …later, in ANY class (a handler, a mob brain, a helper) — no constructor plumbing:
var dialogue = Service.Get<DialogueServer>();
var loco = Service.Get<LocomotionSystem>();
Depends only on SetNet. Not a full DI container — it locates the singletons your modules already create; it constructs nothing.
Three ways to use it (mix freely)
Ambient (simplest)
One process-wide hub. new ServiceHub().MakeCurrent(), then Service.Get<T>() from anywhere.
new ServiceHub().MakeCurrent();
Service.Get<WalletServer>().DepositAsync(key, 100);
Per-server / per-client (isolated)
A hub bound to a specific BaseServer/BaseClient (handy when you run more than one in a process — tests, co-hosting). Created on first use, lives as long as the owner.
server.Services().Add(server.UseInventory());
// elsewhere with the same server:
var inv = server.Services().Get<InventoryServer>();
Explicit
Hold the ServiceHub yourself and pass it where you like — no ambient state at all.
Registering
Add<T> returns the instance, so you register and capture in one line:
var mobs = hub.Add(server.UseMobs(opts)); // registered AND captured
AddAll(params object[]) registers several at once (by runtime type):
hub.AddAll(server.UseInventory(), server.UseWallet(), server.UseTrade(inv));
A second Add of the same type replaces the first.
Resolving
| Call | Behaviour |
|---|---|
hub.Get<T>() / Service.Get<T>() |
Returns the instance; throws if none registered (message hints at the missing UseXxx). |
hub.TryGet<T>(out v) / Service.TryGet<T>(out v) |
false if none (no throw). |
hub.GetOrNull<T>() / Service.GetOrNull<T>() |
null if none. |
hub.Has<T>() |
Membership check. |
hub.Remove<T>() |
Unregister. |
hub.All |
Snapshot of everything registered. |
Service.* is a static shortcut over ServiceHub.Current. It throws (Get) or returns null/false (GetOrNull/TryGet) when no ambient hub is set.
Example
Instances are keyed by their static type, which is the UseXxx return type — so resolve by that concrete type (InventoryServer, LocomotionSystem, DialogueServer, …). See examples/MobBrains, where three mob brains each reach the (moving) player through the hub with zero constructor wiring.
Note vs. full DI
If you already use Microsoft.Extensions.DependencyInjection, keep using it — register the UseXxx() results as singletons there instead. SetNet.Services is the zero-dependency middle ground for projects (Unity, small servers) that just want "reach my systems from anywhere" without a container. It does not auto-register — you Add(...) each once; that's the one line that replaces a scattered field.
License
MIT
| 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
- SetNet (>= 1.2.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.2.0 | 90 | 8/5/2026 |