Skip to content

Usage.Native CSharp Projects

JuDelCo edited this page Apr 8, 2025 · 16 revisions

Install (Native C# projects)

Run the following command in the console of your .NET project to add the package:

dotnet add package JuDelCo.Lib.Core

In native C# applications, you need to ensure the lifecycle of the Service Container and fire some events.

Entry point

First, at some point in the entry point of the logic of your program, register the services using:

ServiceContainer.RegisterService<ITaskService, TaskService>();
ServiceContainer.RegisterService<ICoroutineService, CoroutineService>();
ServiceContainer.RegisterService<ICacheService, CacheService>();

// Note: You need to implement your custom C# native providers for these services if you need to use them
// ServiceContainer.RegisterService<ILogService, LogConsoleService>();
// ServiceContainer.RegisterService<IInputService, InputNativeService>();
// ServiceContainer.RegisterService<ITimeService, TimeNativeService>();

// Register your custom services

Note: The IEventBusService is core and therefore is registered automatically, you can't unload this service.

Update loop

During the update loop of your application you need to fire events so some Services that depends on them (like the Coroutine and Task services) work as intended:

// Update loop
ServiceContainer.Get<IEventBusService>().Fire(new TimePreUpdateEvent(deltaTime));
ServiceContainer.Get<IEventBusService>().Fire(new TimeUpdateEvent(deltaTime));
ServiceContainer.Get<IEventBusService>().Fire(new TimePostUpdateEvent(deltaTime));

// Fixed update loop
ServiceContainer.Get<IEventBusService>().Fire(new TimePreFixedUpdateEvent(fixedDeltaTime));
ServiceContainer.Get<IEventBusService>().Fire(new TimeFixedUpdateEvent(fixedDeltaTime));
ServiceContainer.Get<IEventBusService>().Fire(new TimePostFixedUpdateEvent(fixedDeltaTime));

// others ... (physics events)

Dispose

Before the program finalizes, you should dispose all the services using:

ServiceContainer.Dispose();

Next steps

Read how to use the Service Container and how to create your own Services.

After that, read about the Update Loop Events you can use, how to do logging and what LinkHandlers are.

Clone this wiki locally