Exemplo n.º 1
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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 3
0
 public bool IsAvailable()
 {
     return
         (_syncProvidersCache
          .GetAllExtensions()
          .All(syncProv => syncProv.IsAvailable()));
 }
Exemplo n.º 4
0
		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);
            }
        }