Using active session group object.
The active session group object is created when the first active session object in the group is created and is disposed when the last active session object in the group ceases to exist. A reference to an active session group object is stored when processing a request in the context of this request. This reference is available via the GetActiveSessionGroup extension method for the context.
A reference to a session group object is an interface of the ILocalSession type. This interface is a stripped-down version of the active session object interface IActiveSession (technically, the IActiveSession interface type inherits from ILocalSession). The ILocalSession interface contains the following properties, common with IActiveSession interface: Id - the group identifier, IsAvailable - an indication that the active session group reference points to an actual, not a dummy group object, Properties - a dictionary containing references to objects associated with this group with string keys that allow you to find the desired object, a CompletionToken cancellation token, which is canceled when the group object is being disposed, allowing to clean up the objects associated with the group.
In addition, an active session group just like an active session has its own service scope with its own service container. The scope is created when the group object is created. This scope exists as long as the group object exists and is not disposed. The ILocalSession interface of the group object contains a reference to the scoped services container in the SessionServices property just like IActiveSession interface. Maintaining this specific to an active session group scope allows a code that uses the active session group object to use the same single copy of the services with a Scoped lifetime and to automatically clean them up when the group becomes disposed.
However, unlike the services in the active session container, the ActiveSession library does not provide convenient helper services for the services in the group container to inject dependencies on the services in the group container. This is because the active session group object is not intended to be used in endpoint request handlers in dependency injection frameworks - it is intended primarily for use in middleware handlers in the request processing pipeline.
Before working with an active session group object, as well as with an active session object, one should check that the IsAvailable property is set to true - that is, that the reference received from the GetActiveSessionGroup method points to a real, not a dummy object.