Vixen
02b45cc4
csharp
public sealed class ServiceRegistry

A flat, typed lookup from a service's compile-time type to its single instance. The bootstrapper fills it in by hand and subsystems read from it; that is the whole model.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

This is not a DI container. There is no constructor injection, no lifetime scope, no auto-wiring, and no reflection — a subsystem takes what it needs as constructor parameters, and whoever constructs it supplies them. The registry exists for the genuinely global handful (graphics device, content manager, input, time) that would otherwise be threaded through every signature. Under NativeAOT the alternative does not work at all, and on a frame budget it costs more than it is worth.

The service type is the *static* type argument, not the instance's type, so registering an implementation against its interface is the ordinary case: registry.Add<IGraphicsDevice>(vulkanDevice).

Reads are lock-free and safe against concurrent writes: a write clones the table and swaps it in, so a reader either sees the old table or the new one, never a torn one. Writes are expected at boot, and are not cheap enough to do per frame.

Fields and properties (2)

  • public int Count

    How many services are registered.

  • public IReadOnlyCollection<Type> ServiceTypes

    The registered service types, in no particular order.

Methods (9)

  • public void Add<T>(T service) where T : class

    Registers under .

  • public bool TryAdd<T>(T service) where T : class

    Registers unless is taken.

  • public T? AddOrReplace<T>(T service) where T : class

    Registers , displacing any current registration.

  • public T Get<T>() where T : class

    Looks up the service registered under .

  • public bool TryGet<T>(out T? service) where T : class

    Looks up the service registered under , if there is one.

  • public T? GetOrDefault<T>() where T : class

    Looks up the service registered under , or null.

  • public bool Contains<T>() where T : class

    Whether anything is registered under .

  • public bool Remove<T>() where T : class

    Unregisters . Does not dispose the instance.

  • public void Clear()

    Unregisters everything. Does not dispose the instances.

Used by (5)

  • AppServicesVixen.App.Hosting
  • ServiceRegistryTestsVixen.Core.Tests
  • HostedEngineTestsVixen.App.Tests
  • HostedRendererTestsVixen.App.Tests
  • VixenApplicationTestsVixen.App.Tests