Skip to content

Commit

Permalink
为 ControllerActivator 添加异步释放方法的实现。 ⚾
Browse files Browse the repository at this point in the history
  • Loading branch information
PopeyeZhong committed Apr 7, 2024
1 parent 31693e5 commit e336dfe
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion Zongsoft.Web/src/ControllerActivator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
*/

using System;
using System.Threading;
using System.Threading.Tasks;
using System.Collections.Concurrent;

using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -61,12 +63,25 @@ public void Release(ControllerContext context, object controller)
{
if(context == null)
throw new ArgumentNullException(nameof(context));

if(controller == null)
throw new ArgumentNullException(nameof(controller));

if(controller is IDisposable disposable)
disposable.Dispose();
}

public ValueTask ReleaseAsync(ControllerContext context, object controller)
{
if(context == null)
throw new ArgumentNullException(nameof(context));
if(controller == null)
throw new ArgumentNullException(nameof(controller));

if(controller is IAsyncDisposable disposable)
return disposable.DisposeAsync();

this.Release(context, controller);
return default;
}
}
}

0 comments on commit e336dfe

Please sign in to comment.