OS and system level abstractions that provide a way to decouple your logic from static system calls, making your code more testable.
When your code calls DateTimeOffset.UtcNow, Environment.UserInteractive, or Process.GetCurrentProcess(), it is difficult to unit test that code because these are static calls to the operating system. By using these abstractions, you can mock the system-level behavior in your tests.
dotnet add package Shuttle.Core.SystemRegister the services with your dependency injection container:
services.AddSingleton<ISystemClock, SystemClock>();
services.AddSingleton<IEnvironmentService, EnvironmentService>();
services.AddSingleton<IProcessService, ProcessService>();All types are in the Shuttle.Core.System namespace.
The default implementation is SystemClock.
DateTimeOffset UtcNow { get; }Returns the DateTimeOffset representing the current UTC date/time.
The default implementation is EnvironmentService.
bool UserInteractive { get; }Returns true if running as a console application; otherwise false.
The default implementation is ProcessService.
IProcess GetCurrentProcess();Returns an IProcess abstraction for the current system process.
Represents a system process. The default implementation is SystemProcess.
void Kill();Kills the process.