public void PluginLoader_Create_Static_AllParams_Test()
        {
            // Arrange
            string         appName                = "MyApp";
            AppPluginPaths paths                  = null;
            var            mockSettings           = _MockRepository.Create <IPluginLoaderSettings>();
            var            mockAssemblyCache      = _MockRepository.Create <IAssemblyCache>();
            var            mockAssemblyNameReader = _MockRepository.Create <IAssemblyNameReader>();
            var            mockPluginDependencyResolverObjectCreator = _MockRepository.Create <IPluginDependencyResolverObjectCreator>();
            var            mockPluginDependencyResolverFactory       = _MockRepository.Create <IPluginDependencyResolverCacheFactory>();
            var            mockPluginCacheFactory = _MockRepository.Create <IPluginCacheFactory <IOrg> >();
            var            mockLogger             = _MockRepository.Create <IPluginLoaderLogger>();

            // Act
            var result = PluginLoader <IOrg> .Create(
                appName,
                paths,
                _MockAppDomain.Object,
                mockSettings.Object,
                _MockTypeLoader.Object,
                mockAssemblyCache.Object,
                mockAssemblyNameReader.Object,
                _MockAssemblyLoader.Object,
                new Waiter(mockLogger.Object),
                mockPluginDependencyResolverObjectCreator.Object,
                mockPluginDependencyResolverFactory.Object,
                mockPluginCacheFactory.Object,
                mockLogger.Object);

            // Assert
            Assert.IsNotNull(result);
            _MockRepository.VerifyAll();
        }
예제 #2
0
        static void Main()
        {
            var tools = new List <ITool>
            {
                new Hammer()
            };

            // Common objects
            var appSettings = new AppSettings();
            var logger      = PluginLoaderLogger.Factory(appSettings);
            var appDomain   = new AppDomainWrapper(AppDomain.CurrentDomain, logger);

            PluginLoaderSettings.Default = new MyPluginLoaderSettings(appSettings);
            var settings             = PluginLoaderSettings.Default;
            var assemblyNameReader   = new AssemblyNameReader();
            var assemblyCache        = new AssemblyCache(appDomain, assemblyNameReader, logger);
            var assemblyLoader       = new AssemblyLoader(appDomain, settings, assemblyCache, assemblyNameReader, logger);
            var pluginPaths          = new AppPluginPaths(settings.AppName, settings.PluginFolder, appDomain, logger);
            var waiter               = new Waiter(logger);
            var assemblyResolveCache = new AssemblyResolveCache();
            var pluginDependencyResolverObjectCreator = new PluginDependencyResolverObjectCreator(appDomain, settings, assemblyLoader, waiter, assemblyResolveCache, logger);
            var pluginDependencyResolverFactory       = new PluginDependencyResolverCacheFactory(pluginDependencyResolverObjectCreator, logger);

            // ITool plugin loader objects
            var typeLoader              = new TypeLoader <ITool>(settings, logger);
            var objectCreator           = new ObjectCreator <ITool>();
            var pluginCacheFactory      = new PluginCacheFactory <ITool>(typeLoader, pluginDependencyResolverFactory, assemblyLoader, logger);
            var pluginLoader            = new PluginLoader <ITool>(pluginPaths, pluginCacheFactory);
            var plugins                 = pluginLoader.LoadPlugins();
            var toolPluginObjectCreator = new PluginObjectCreator <ITool>(settings, objectCreator, logger);

            tools.AddRange(plugins.CreatePluginObjects(toolPluginObjectCreator));

            // ICaveManTool<Hammer> plugin loader objects - using RuntimePluginLoader
            var caveManHammerRuntimePluginLoader = RuntimePluginLoaderFactory.Instance.Create <CavemanHammerRuntimePluginLoader, ICaveManTool <Hammer> >();
            var caveManObjectCreator             = new ObjectCreator <ICaveManTool <Hammer> >();
            var caveManToolPluginObjectCreator   = new PluginObjectCreator <ICaveManTool <Hammer> >(settings, caveManObjectCreator, logger);

            tools.AddRange(caveManHammerRuntimePluginLoader.PluginCollection.CreatePluginObjects(caveManToolPluginObjectCreator));

            ShowPrompt(tools);
            // Only 4 plugins will show as this doesn't support plugins with Constructor parameters
            int input = ReadLine(tools);

            while (input != 0)
            {
                if (input <= tools.Count)
                {
                    Console.WriteLine(tools[input - 1].DoWork());
                }
                ShowPrompt(tools);
                input = ReadLine(tools);
            }
        }
예제 #3
0
 public SingletonObjects()
 {
     Settings             = PluginLoaderSettings.Default;
     AppSettings          = new AppSettings();
     Logger               = PluginLoaderLogger.Factory(AppSettings);
     AppDomain            = new AppDomainWrapper(System.AppDomain.CurrentDomain, Logger);
     AssemblyNameReader   = new AssemblyNameReader();
     AssemblyCache        = new AssemblyCache(AppDomain, AssemblyNameReader, Logger);
     AssemblyLoader       = new AssemblyLoader(AppDomain, Settings, AssemblyCache, AssemblyNameReader, Logger);
     PluginPaths          = new AppPluginPaths(Settings.AppName, Settings.PluginFolder, AppDomain, Logger);
     Waiter               = new Waiter(Logger);
     AssemblyResolveCache = new AssemblyResolveCache();
     PluginDependencyResolverObjectCreator = new PluginDependencyResolverObjectCreator(AppDomain, Settings, AssemblyLoader, Waiter, AssemblyResolveCache, Logger);
     PluginDependencyResolverFactory       = new PluginDependencyResolverCacheFactory(PluginDependencyResolverObjectCreator, Logger);
 }