NeedlrBootstrapper
NexusLabs.Needlr.Hosting¶
NeedlrBootstrapper Class¶
Wraps an application entry point with bootstrap lifecycle management: a pre-DI logger, top-level exception handling, and guaranteed cleanup.
public sealed record NeedlrBootstrapper : System.IEquatable<NexusLabs.Needlr.Hosting.NeedlrBootstrapper>
Inheritance System.Object 🡒 NeedlrBootstrapper
Implements System.IEquatable<NeedlrBootstrapper>
Example¶
await new NeedlrBootstrapper().RunAsync(async (ctx, ct) =>
{
var host = new Syringe()
.UsingSourceGen()
.ForHost()
.UsingOptions(() => CreateHostOptions.Default.UsingCurrentProcessArgs())
.BuildHost();
await host.RunAsync(ct);
});
Remarks¶
By default a console logger is created automatically. Override with UsingLoggerFactory(this NeedlrBootstrapper, ILoggerFactory) to supply your own factory (e.g. a Serilog two-stage init factory).
Unhandled exceptions from the callback are caught, logged at Critical, and then
swallowed so the process exits cleanly after cleanup.
Methods¶
NeedlrBootstrapper.RunAsync(Func<NeedlrBootstrapContext,CancellationToken,Task>, CancellationToken) Method¶
Runs the application entry point with full bootstrap lifecycle management.
public System.Threading.Tasks.Task RunAsync(System.Func<NexusLabs.Needlr.Hosting.NeedlrBootstrapContext,System.Threading.CancellationToken,System.Threading.Tasks.Task> runAsync, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));
Parameters¶
runAsync System.Func<NeedlrBootstrapContext,System.Threading.CancellationToken,System.Threading.Tasks.Task>
The application callback. Receives a NeedlrBootstrapContext containing the bootstrap logger, and the System.Threading.CancellationToken passed to this method.
cancellationToken System.Threading.CancellationToken
Optional cancellation token forwarded to the callback.
Returns¶
System.Threading.Tasks.Task
A System.Threading.Tasks.Task that completes when the application exits.