public MenuService([NotNull] IServiceProvider serviceProvider) { if (serviceProvider == null) { throw new ArgumentNullException("serviceProvider"); } var menuProviders = new ExtensionsCache <MenuProviderInfo, IMenuProvider>(serviceProvider); _menuProvidersLookup = menuProviders .GetAllExtensions() .ToLookup( menuProvider => menuProvider.MenuName, StringComparer.OrdinalIgnoreCase); // WTF? menuProviders .GetAllExtensions() .OfType <IDynamicMenuProvider>() .Select( dynamicMenuProvider => { _menuCache.Drop(dynamicMenuProvider.MenuName); return (dynamicMenuProvider.MenuChanged.Subscribe( arg => _menuChanged.OnNext(dynamicMenuProvider.MenuName))); }); _menuCache = new ElementsCache <string, IMenuRoot>(CreateMenu); }
public MenuService([NotNull] IServiceProvider serviceProvider) { if (serviceProvider == null) throw new ArgumentNullException("serviceProvider"); var menuProviders = new ExtensionsCache<MenuProviderInfo, IMenuProvider>(serviceProvider); _menuProvidersLookup = menuProviders .GetAllExtensions() .ToLookup( menuProvider => menuProvider.MenuName, StringComparer.OrdinalIgnoreCase); // WTF? menuProviders .GetAllExtensions() .OfType<IDynamicMenuProvider>() .Select( dynamicMenuProvider => { _menuCache.Drop(dynamicMenuProvider.MenuName); return dynamicMenuProvider.MenuChanged.Subscribe( arg => _menuChanged.OnNext(dynamicMenuProvider.MenuName)); }); _menuCache = new ElementsCache<string, IMenuRoot>(CreateMenu); }
public bool IsAvailable() { return (_syncProvidersCache .GetAllExtensions() .All(syncProv => syncProv.IsAvailable())); }
public MenuService([NotNull] IServiceProvider serviceProvider) { if (serviceProvider == null) throw new ArgumentNullException(nameof(serviceProvider)); var menuProviders = new ExtensionsCache<MenuProviderInfo, IMenuProvider>(serviceProvider); _menuProvidersLookup = menuProviders .GetAllExtensions() .ToLookup( menuProvider => menuProvider.MenuName, StringComparer.OrdinalIgnoreCase); // WTF? //menuProviders // .GetAllExtensions() // .OfType<IDynamicMenuProvider>() // .Select( // dynamicMenuProvider => // { // _menuCache.Drop(dynamicMenuProvider.MenuName); // return // dynamicMenuProvider.MenuChanged.Subscribe( // arg => _menuChanged.OnNext(dynamicMenuProvider.MenuName)); // }); _menuCache = LazyDictionary.Create<string, IMenuRoot>(CreateMenu, false); }
static void Main() { var root = new ServiceContainer(); var strategy = root.CreateStrategy <FruitInfo, FruitAttribute>(type => new FruitInfo(type)); root.ScanExtensions(strategy); var cache = new ExtensionsCache <FruitInfo, IFruit>(root); foreach (var fruit in cache.GetAllExtensions()) { Console.WriteLine(fruit.Name); } }