@@ -20,6 +20,7 @@ public sealed class SquidStdBootstrap : ISquidStdBootstrap
2020{
2121 private readonly Lock _syncRoot = new ( ) ;
2222 private readonly List < ISquidStdService > _startedServices = [ ] ;
23+ private readonly bool _ownsContainer ;
2324 private int _disposed ;
2425 private bool _loggerConfigured ;
2526 private BootstrapStateType _state ;
@@ -34,16 +35,20 @@ public sealed class SquidStdBootstrap : ISquidStdBootstrap
3435 /// Initializes a bootstrapper with default options.
3536 /// </summary>
3637 public SquidStdBootstrap ( )
37- : this ( new SquidStdOptions ( ) ) { }
38+ : this ( new SquidStdOptions ( ) )
39+ {
40+ }
3841
3942 /// <summary>
4043 /// Initializes a bootstrapper with the specified options.
4144 /// </summary>
4245 /// <param name="options">Bootstrap options used to register core services.</param>
4346 public SquidStdBootstrap ( SquidStdOptions options )
44- : this ( options , new Container ( ) ) { }
47+ : this ( options , new Container ( ) , true )
48+ {
49+ }
4550
46- private SquidStdBootstrap ( SquidStdOptions options , IContainer container )
51+ private SquidStdBootstrap ( SquidStdOptions options , IContainer container , bool ownsContainer )
4752 {
4853 ArgumentNullException . ThrowIfNull ( options ) ;
4954 ArgumentNullException . ThrowIfNull ( container ) ;
@@ -52,6 +57,7 @@ private SquidStdBootstrap(SquidStdOptions options, IContainer container)
5257
5358 Options = options ;
5459 Container = container ;
60+ _ownsContainer = ownsContainer ;
5561
5662 Container . RegisterInstance < ISquidStdBootstrap > ( this , IfAlreadyRegistered . Replace ) ;
5763 Container . RegisterInstance ( this , IfAlreadyRegistered . Replace ) ;
@@ -74,6 +80,15 @@ public static SquidStdBootstrap Create()
7480 public static SquidStdBootstrap Create ( SquidStdOptions options )
7581 => new ( options ) ;
7682
83+ /// <summary>
84+ /// Creates a bootstrapper using an externally owned DryIoc container.
85+ /// </summary>
86+ /// <param name="options">Bootstrap options used to register core services.</param>
87+ /// <param name="container">Externally owned container that receives SquidStd services.</param>
88+ /// <returns>The created bootstrapper.</returns>
89+ public static SquidStdBootstrap Create ( SquidStdOptions options , IContainer container )
90+ => new ( options , container , false ) ;
91+
7792 /// <inheritdoc />
7893 public ISquidStdBootstrap ConfigureService ( Func < IContainer , IContainer > configure )
7994 => ConfigureServices ( configure ) ;
@@ -323,7 +338,10 @@ public async ValueTask DisposeAsync()
323338 await Log . CloseAndFlushAsync ( ) ;
324339 }
325340
326- Container . Dispose ( ) ;
341+ if ( _ownsContainer )
342+ {
343+ Container . Dispose ( ) ;
344+ }
327345 }
328346 }
329347}
0 commit comments