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);
        }
示例#2
0
        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);
        }
示例#3
0
 public bool IsAvailable()
 {
     return
         (_syncProvidersCache
          .GetAllExtensions()
          .All(syncProv => syncProv.IsAvailable()));
 }
示例#4
0
文件: MenuService.cs 项目: rsdn/janus
		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);
            }
        }