using System;
using System.Threading.Tasks;
namespace FastGithub.Scanner
{
///
/// 中间件创建者扩展
///
static class GithubScanBuilderExtensions
{
///
/// 使用中间件
///
///
///
///
public static IGithubScanBuilder Use(this IGithubScanBuilder builder) where TMiddleware : class, IGithubScanMiddleware
{
return builder.AppServices.GetService(typeof(TMiddleware)) is TMiddleware middleware
? builder.Use(middleware.InvokeAsync)
: throw new InvalidOperationException($"无法获取服务{typeof(TMiddleware)}");
}
///
/// 使用中间件
///
///
///
///
///
public static IGithubScanBuilder Use(this IGithubScanBuilder builder, Func, Task> middleware)
{
return builder.Use(next => context => middleware(context, () => next(context)));
}
}
}