using Connected.Middleware; using Connected.Security.Authentication.Middleware; using Connected.Threading; namespace Connected.Security.Authentication; /// /// The implementation of the . /// internal sealed class AuthenticationService : IAuthenticationService { public AuthenticationService(IMiddlewareService middleware) { Provider = new AsyncLazy(middleware.First()); } private AsyncLazy Provider { get; } public async Task Authenticate(AuthenticationArgs args) { var provider = await Provider.Value; if (provider is null) throw new NullReferenceException(nameof(IAuthenticationMiddleware)); return await provider.Authenticate(args); } }