File tree Expand file tree Collapse file tree
src/Immediate.Cache.Shared Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -195,11 +195,11 @@ private async Task RunHandler(CancellationTokenSource tokenSource)
195195 try
196196 {
197197 var token = tokenSource . Token ;
198- var scope = handler . GetScope ( ) ;
198+ var scope = handler . GetScope ( out var service ) ;
199199
200200 await using ( scope . ConfigureAwait ( false ) )
201201 {
202- var response = await scope . Service
202+ var response = await service
203203 . HandleAsync (
204204 request ,
205205 token
Original file line number Diff line number Diff line change @@ -22,12 +22,30 @@ IServiceScopeFactory serviceScopeFactory
2222 /// An <see cref="OwnedScope{T}"/> containing both the scope and the service, so that the scope can be disposed
2323 /// at the appropriate time.
2424 /// </returns>
25- public OwnedScope < T > GetScope ( )
25+ public OwnedScope < T > GetScope ( ) => GetScope ( out _ ) ;
26+
27+ /// <summary>
28+ /// Creates a temporary scope and gets an instance of the service from that scope.
29+ /// </summary>
30+ /// <param name="service">
31+ /// The instance of the service created from the scope.
32+ /// </param>
33+ /// <returns>
34+ /// An <see cref="OwnedScope{T}"/> containing both the scope and the service, so that the scope can be disposed
35+ /// at the appropriate time.
36+ /// </returns>
37+ public OwnedScope < T > GetScope ( out T service )
2638 {
2739 var scope = serviceScopeFactory . CreateAsyncScope ( ) ;
28- return new (
29- scope . ServiceProvider . GetRequiredService < T > ( ) ,
30- scope
31- ) ;
40+ try
41+ {
42+ service = scope . ServiceProvider . GetRequiredService < T > ( ) ;
43+ return new ( service , scope ) ;
44+ }
45+ catch
46+ {
47+ scope . Dispose ( ) ;
48+ throw ;
49+ }
3250 }
3351}
You can’t perform that action at this time.
0 commit comments