// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using Microsoft.Framework.DependencyInjection; namespace Microsoft.AspNet.Mvc { /// /// Default implementation for ActionDescriptors. /// This implementation caches the results at first call, and is not responsible for updates. /// public class DefaultActionDescriptorsCollectionProvider : IActionDescriptorsCollectionProvider { private readonly IServiceProvider _serviceProvider; private ActionDescriptorsCollection _collection; /// /// Initializes a new instance of the class. /// /// The application IServiceProvider. public DefaultActionDescriptorsCollectionProvider(IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; } /// /// Returns a cached collection of . /// public ActionDescriptorsCollection ActionDescriptors { get { if (_collection == null) { _collection = GetCollection(); } return _collection; } } private ActionDescriptorsCollection GetCollection() { var actionDescriptorProvider = _serviceProvider.GetRequiredService>(); var actionDescriptorProviderContext = new ActionDescriptorProviderContext(); actionDescriptorProvider.Invoke(actionDescriptorProviderContext); return new ActionDescriptorsCollection(actionDescriptorProviderContext.Results, 0); } } }