public void WhenInitializingAModuleWithNoCatalogPendingToBeLoaded_ThenInitializesTheModule()
        {
            var aggregateCatalog = new AggregateCatalog(new AssemblyCatalog(typeof(MefModuleInitializer).Assembly));
            var compositionContainer = new CompositionContainer(aggregateCatalog);
            compositionContainer.ComposeExportedValue(aggregateCatalog);

            var serviceLocatorMock = new Mock<IServiceLocator>();
            var loggerFacadeMock = new Mock<ILoggerFacade>();

            var serviceLocator = serviceLocatorMock.Object;
            var loggerFacade = loggerFacadeMock.Object;

            compositionContainer.ComposeExportedValue(serviceLocator);
            compositionContainer.ComposeExportedValue(loggerFacade);

            aggregateCatalog.Catalogs.Add(new TypeCatalog(typeof(TestModuleForInitializer)));

            var moduleInitializer = compositionContainer.GetExportedValue<IModuleInitializer>();

            var moduleInfo = new ModuleInfo("TestModuleForInitializer", typeof(TestModuleForInitializer).AssemblyQualifiedName);

            var module = compositionContainer.GetExportedValues<IModule>().OfType<TestModuleForInitializer>().First();

            Assert.IsFalse(module.Initialized);

            moduleInitializer.Initialize(moduleInfo);

            Assert.IsTrue(module.Initialized);
        }
        public void ModuleInUnreferencedAssemblyInitializedByModuleInitializer()
        {
            AssemblyCatalog assemblyCatalog = new AssemblyCatalog(GetPathToModuleDll());
            CompositionContainer compositionContainer = new CompositionContainer(assemblyCatalog);

            ModuleCatalog moduleCatalog = new ModuleCatalog();

            Mock<MefFileModuleTypeLoader> mockFileTypeLoader = new Mock<MefFileModuleTypeLoader>();

            compositionContainer.ComposeExportedValue<IModuleCatalog>(moduleCatalog);
            compositionContainer.ComposeExportedValue<MefFileModuleTypeLoader>(mockFileTypeLoader.Object);

            bool wasInit = false;
            var mockModuleInitializer = new Mock<IModuleInitializer>();
            mockModuleInitializer.Setup(x => x.Initialize(It.IsAny<ModuleInfo>())).Callback(() => wasInit = true);

            var mockLoggerFacade = new Mock<ILoggerFacade>();

            MefModuleManager moduleManager = new MefModuleManager(
                mockModuleInitializer.Object,
                moduleCatalog,
                mockLoggerFacade.Object);

            compositionContainer.SatisfyImportsOnce(moduleManager);

            moduleManager.Run();

            Assert.IsTrue(wasInit);
        }
    protected override void Initialize()
    {
        base.Initialize();

        var exceptionDialog = new ExceptionDialog("http://code.google.com/p/notifypropertyweaver/issues/list", "NotifyPropertyWeaver");
        try
        {
            using (var catalog = new AssemblyCatalog(GetType().Assembly))
            using (var container = new CompositionContainer(catalog))
            {
                var menuCommandService = (IMenuCommandService) GetService(typeof (IMenuCommandService));
                var errorListProvider = new ErrorListProvider(ServiceProvider.GlobalProvider);

                container.ComposeExportedValue(exceptionDialog);
                container.ComposeExportedValue(menuCommandService);
                container.ComposeExportedValue(errorListProvider);

                container.GetExportedValue<MenuConfigure>().RegisterMenus();
                container.GetExportedValue<SolutionEvents>().RegisterSolutionEvents();
                container.GetExportedValue<TaskFileReplacer>().CheckForFilesToUpdate();
            }
        }
        catch (Exception exception)
        {
            exceptionDialog.HandleException(exception);
        }
    }
        public void WhenInitializingAModuleWithACatalogPendingToBeLoaded_ThenLoadsTheCatalogInitializesTheModule()
        {
            var aggregateCatalog = new AggregateCatalog(new AssemblyCatalog(typeof(MefModuleInitializer).Assembly));
            var compositionContainer = new CompositionContainer(aggregateCatalog);
            compositionContainer.ComposeExportedValue(aggregateCatalog);

            var serviceLocatorMock = new Mock<IServiceLocator>();
            var loggerFacadeMock = new Mock<ILoggerFacade>();

            var serviceLocator = serviceLocatorMock.Object;
            var loggerFacade = loggerFacadeMock.Object;

            compositionContainer.ComposeExportedValue(serviceLocator);
            compositionContainer.ComposeExportedValue(loggerFacade);

            var moduleInitializer = compositionContainer.GetExportedValue<IModuleInitializer>();
            var repository = compositionContainer.GetExportedValue<DownloadedPartCatalogCollection>();

            var moduleInfo = new ModuleInfo("TestModuleForInitializer", typeof(TestModuleForInitializer).AssemblyQualifiedName);

            repository.Add(moduleInfo, new TypeCatalog(typeof(TestModuleForInitializer)));

            moduleInitializer.Initialize(moduleInfo);

            ComposablePartCatalog existingCatalog;
            Assert.IsFalse(repository.TryGet(moduleInfo, out existingCatalog));

            var module = compositionContainer.GetExportedValues<IModule>().OfType<TestModuleForInitializer>().First();

            Assert.IsTrue(module.Initialized);
        }
Exemple #5
0
		static void Main()
		{
            var engine = new GUILayer.EngineDevice();
            GC.KeepAlive(engine);

            var catalog = new TypeCatalog(
                typeof(ShaderPatcherLayer.Manager),
                typeof(ShaderFragmentArchive.Archive),
                typeof(NodeEditorCore.ShaderFragmentArchiveModel),
                typeof(NodeEditorCore.ModelConversion),
                typeof(NodeEditorCore.ShaderFragmentNodeCreator),
                typeof(NodeEditorCore.DiagramDocument),
                typeof(ExampleForm)
            );

            using (var container = new CompositionContainer(catalog))
            {
                container.ComposeExportedValue<ExportProvider>(container);
                container.ComposeExportedValue<CompositionContainer>(container);

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(container.GetExport<ExampleForm>().Value);
            }

            engine.Dispose();
		}
 public void Start()
 {
     _documentStore = new EmbeddableDocumentStore
     {
         DataDirectory = "./continuity.db",
         UseEmbeddedHttpServer = true,
     };
     _documentStore.Initialize();
     var container = new CompositionContainer(
                  new AggregateCatalog(
                      new AssemblyCatalog(GetType().Assembly),
                     new AssemblyCatalog(typeof(IBus).Assembly),
                     new DirectoryCatalog("extensions")
                  ));
     container.ComposeExportedValue<IDocumentStore>(_documentStore);
     container.ComposeExportedValue<IDocumentSession>(_documentStore.OpenSession());
     container.ComposeExportedValue<IBus>(new StandardBus());
     container.ComposeParts(this);
     _kernel.Bind<IDocumentStore>().ToConstant(_documentStore);
     _kernel.Bind<IDocumentSession>().ToMethod(c => _documentStore.OpenSession());
     //var startupTasks = _kernel.GetAll<INeedToRunAtStartup>();
     foreach (var task in StartupItems)
         task.Run();
     HttpServer.Start();
     var config = _kernel.Get<ContinuityConfiguration>();
     _serverAddress = "localhost";
     _serverPort = config.Port.ToString();
 }
Exemple #7
0
 public void Prepare()
 {
     container = new CompositionContainer(
         new AggregateCatalog(
             new AssemblyCatalog(
                 typeof (ITypedPool).Assembly
                 ),
             new TypeCatalog(typeof (Registrator)),
             new TypeCatalog(typeof(ResourcePool)),
             new TypeCatalog(typeof (NotifiedElementGetter)),
             new TypeCatalog(typeof (UnnotifiedElementGetter)),
             new TypeCatalog(typeof (NotifiedElementPoster)),
             new TypeCatalog(typeof (UnnotifiedElementPoster))));
     _uplink = _mockRepository.DynamicMock<AnnouncerUplink>();
     _downlink = _mockRepository.DynamicMock<AnnouncerDownlink>(); 
     _downlink.Expect(k => k.Subscribe(null))                   
            .IgnoreArguments()
            .Repeat.Once();
     _downlink.Replay();
     
     container.ComposeExportedValue(_uplink);
     container.ComposeExportedValue(_downlink);
     var service = container.GetExportedValue<ICacheServicing>(); 
     service.Initialize(new Settings
                            {
                                AutoSubscription = (TestContext.Properties["AutoSubscription"] as string)== "true"                                      
                            }, container);
     _pool = container.GetExportedValue<ITypedPool>();
     _subscriptor = container.GetExportedValue<IAnnouncerSubscriptor>();                        
 }
        public void UnknownExportedModuleIsAddedAndInitializedByModuleInitializer()
        {
            var aggregateCatalog = new AggregateCatalog();
            var compositionContainer = new CompositionContainer(aggregateCatalog);

            var moduleCatalog = new ModuleCatalog();

            var mockModuleTypeLoader = new Mock<MefXapModuleTypeLoader>(new DownloadedPartCatalogCollection());

            compositionContainer.ComposeExportedValue<IModuleCatalog>(moduleCatalog);
            compositionContainer.ComposeExportedValue<MefXapModuleTypeLoader>(mockModuleTypeLoader.Object);

            bool wasInit = false;
            var mockModuleInitializer = new Mock<IModuleInitializer>();
            mockModuleInitializer.Setup(x => x.Initialize(It.IsAny<ModuleInfo>())).Callback(() => wasInit = true);

            var mockLoggerFacade = new Mock<ILoggerFacade>();

            var moduleManager =
                new MefModuleManager(mockModuleInitializer.Object, moduleCatalog, mockLoggerFacade.Object);

            aggregateCatalog.Catalogs.Add(new TypeCatalog(typeof(TestMefModule)));

            compositionContainer.SatisfyImportsOnce(moduleManager);

            moduleManager.Run();

            Assert.IsTrue(wasInit);
            Assert.IsTrue(moduleCatalog.Modules.Any(mi => mi.ModuleName == "TestMefModule"));
        }
Exemple #9
0
 public void Preparation()
 {
     container = MockHelper.InitializeContainer(new[] { typeof(IProjectionsCollector).Assembly, typeof(Element).Assembly }, new Type[0]);           
     var pool = new ResourcePool();           
     container.ComposeExportedValue(pool);
     container.ComposeExportedValue(container);
     Settings.NoCacheGarbageChecking = true;
 }
 public virtual void Run()
 {
     Container = new CompositionContainer(new AggregateCatalog(Catalogs));
     var mefServiceLocator = new MEFServiceLocator(Container);
     ServiceLocator.SetProvider(() => mefServiceLocator);
     Container.ComposeExportedValue(Container);
     Container.ComposeExportedValue(ServiceLocator.Current);
     ApplicationLoaded();
 }
		private CompositionContainer SetupCompositionContainer()
		{
			var catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
			var container = new CompositionContainer(catalog);
			container.ComposeExportedValue<BootstrapperApplication>(this);
			container.ComposeExportedValue<Engine>(this.Engine);
			container.ComposeExportedValue<IUIInteractionService>(this);
			return container;
		}
 /// <summary>
 /// Initializes a new instance of the <see cref="CompositionHost" /> class.
 /// </summary>
 /// <param name="isThreadSafe">if set to <c>true</c> if the container is thread safe.</param>
 public CompositionHost(bool isThreadSafe)
 {
     var catalog = new AggregateCatalog();
     Contract.Assume(catalog.Catalogs != null);
     _container = new CompositionContainer(catalog, isThreadSafe);
     _container.ComposeExportedValue((ICompositionHost)this);
     _container.ComposeExportedValue((IServiceProvider)this);
     _container.ComposeExportedValue((ExportProvider)Container);
 }
Exemple #13
0
        protected virtual void ApplicationStartup(object sender, StartupEventArgs e)
        {
            Catalog = new AggregateCatalog(
                new AssemblyCatalog(typeof(AppBase).Assembly)
                );
            Container = new CompositionContainer(Catalog);

            Container.ComposeExportedValue(new ViewFactory(Container));
            Container.ComposeExportedValue(new StateHandler(Container));
        }
Exemple #14
0
 public void Preparation()
 {
     container = MockHelper.InitializeContainer(new[] { typeof(IProjectionsCollector).Assembly, typeof(Element).Assembly }, new Type[0]);
     var pool = new ResourcePool();
     var writer = new TestWriter();
     container.ComposeExportedValue(container);
     container.ComposeExportedValue(pool);
     container.ComposeExportedValue(writer);
     container.GetExportedValue<ICacheServicing>().Initialize();
 }
 protected void Application_Start(object sender, EventArgs e)
 {
     var assembly = new AssemblyCatalog(typeof(Global).Assembly); //this is how to add curent assembly
     var catalog = new AggregateCatalog();
     catalog.Catalogs.Add(assembly);
     catalog.Catalogs.Add(new DirectoryCatalog("bin")); //this is where our DLLs are located. "." is for WPF app, "bin" is for WEB app
     var container = new CompositionContainer(catalog);
     var mefServiceLocator = new MefServiceLocator(container);
     ServiceLocator.SetLocatorProvider(() => mefServiceLocator);
     container.ComposeExportedValue<IServiceLocator>(mefServiceLocator);
     container.ComposeExportedValue(container);
 }
Exemple #16
0
        public void ServiceProvidesAMainView()
        {
            var container =
                new CompositionContainer(
                        new TypeCatalog(typeof(TestUIService)));
            container.ComposeExportedValue(new ViewFactory(container));
            container.ComposeExportedValue(new StateHandler(container));

            var service = container.GetExportedValue<ISingleViewUIService>();

            Assert.IsNotNull(service.MainWindow);
        }
        public static CompositionContainer RegisterCompositionService([NotNull] this Startup startup, [NotNull] IConfiguration configuration, [NotNull] string projectDirectory, [NotNull] Assembly callingAssembly, [NotNull] [ItemNotNull] IEnumerable<string> additionalAssemblyFileNames, CompositionOptions options)
        {
            var toolsDirectory = configuration.GetString(Constants.Configuration.ToolsDirectory);

            if (options.HasFlag(CompositionOptions.AddWebsiteAssemblyResolver))
            {
                // add an assembly resolver that points to the website/bin directory - this will load files like Sitecore.Kernel.dll
                AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => ResolveAssembly(args, configuration);
            }

            // add application assemblies
            var coreAssembly = typeof(Constants).Assembly;

            var catalogs = new List<ComposablePartCatalog>
            {
                new AssemblyCatalog(coreAssembly),
                new AssemblyCatalog(callingAssembly)
            };

            var disableExtensions = configuration.GetBool("disable-extensions");
            if (!disableExtensions && !options.HasFlag(CompositionOptions.DisableExtensions))
            {
                // add assemblies from the tools directory
                AddFeatureAssemblies(catalogs, toolsDirectory);

                // add additional assemblies - this is used in Sitecore.Pathfinder.Server to load assemblies from the /bin folder
                AddAdditionalAssemblies(catalogs, additionalAssemblyFileNames);

                // add core extensions
                var coreExtensionsDirectory = Path.Combine(toolsDirectory, "files\\extensions");
                var coreAssemblyFileName = Path.Combine(coreExtensionsDirectory, "Sitecore.Pathfinder.Core.Extensions.dll");
                AddAssembliesFromDirectory(catalogs, coreAssemblyFileName, coreExtensionsDirectory);
                AddDynamicAssembly(catalogs, toolsDirectory, coreAssemblyFileName, coreExtensionsDirectory);

                // add projects extensions
                var projectExtensionsDirectory = PathHelper.Combine(projectDirectory, configuration.GetString(Constants.Configuration.ProjectExtensionsDirectory));
                var projectAssemblyFileName = Path.Combine(projectExtensionsDirectory, configuration.GetString(Constants.Configuration.ProjectExtensionsAssemblyFileName));
                AddAssembliesFromDirectory(catalogs, projectAssemblyFileName, projectExtensionsDirectory);
                AddDynamicAssembly(catalogs, toolsDirectory, projectAssemblyFileName, projectExtensionsDirectory);
            }

            // build composition graph
            var exportProvider = new CatalogExportProvider(new AggregateCatalog(catalogs));
            var compositionContainer = new CompositionContainer(exportProvider);
            exportProvider.SourceProvider = compositionContainer;

            // register the composition service itself for DI
            compositionContainer.ComposeExportedValue<ICompositionService>(compositionContainer);
            compositionContainer.ComposeExportedValue(configuration);

            return compositionContainer;
        }
        public void RegisterInstancesAndResolveByName()
        {
            using (CompositionContainer mefContainer = new CompositionContainer())
            {
                mefContainer.ComposeExportedValue<IService>("add", new ServiceAdd());
                mefContainer.ComposeExportedValue<IService>("sub", new ServiceSub());

                IService serviceAdd = mefContainer.GetExportedValue<IService>("add");
                IService serviceSub = mefContainer.GetExportedValue<IService>("sub");
                Assert.That(serviceAdd.Calc(1, 2), Is.EqualTo(3));
                Assert.That(serviceSub.Calc(5, 2), Is.EqualTo(3));
            }
        }
        public void ShouldForwardResolveAllToInnerContainer()
        {
            object objectOne = new object();
            object objectTwo = new object();

            CompositionContainer compositionContainer = new CompositionContainer();
            compositionContainer.ComposeExportedValue<object>(objectOne);
            compositionContainer.ComposeExportedValue<object>(objectTwo);

            IServiceLocator containerAdapter = new MefServiceLocatorAdapter(compositionContainer);
            IList<object> returnedList = containerAdapter.GetAllInstances(typeof(object)).ToList();
            Assert.AreSame(returnedList[0], objectOne);
            Assert.AreSame(returnedList[1], objectTwo);
        }
Exemple #20
0
 private static IList<IContentProvider> GetContentProviders(IKernel kernel)
 {
     // Use MEF to locate the content providers in this assembly
     var compositionContainer = new CompositionContainer(new AssemblyCatalog(typeof(ResourceProcessor).Assembly));
     compositionContainer.ComposeExportedValue(kernel);
     return compositionContainer.GetExportedValues<IContentProvider>().ToList();
 }
        public void Initialize()
        {
            container = new CompositionContainer(
                new AggregateCatalog(
                    new AssemblyCatalog(
                        typeof (ITypedPool).Assembly
                        ),
                    new TypeCatalog(typeof (Registrator)),
                    new TypeCatalog(typeof (ResourcePool)),
                    new TypeCatalog(typeof (NotifiedElementGetter)),
                    new TypeCatalog(typeof(NotifiedElementPoster)),
                    new TypeCatalog(typeof (UnnotifiedElementGetter)),
                    new TypeCatalog(typeof (UnnotifiedElementPoster))));
            _uplink = _mockRepository.DynamicMock<AnnouncerUplink>();
            _downlink = _mockRepository.DynamicMock<AnnouncerDownlink>();
            _downlink.Expect(k => k.Subscribe(null))
                   .IgnoreArguments()
                   .Repeat.Once();
            _downlink.Replay();

            container.ComposeExportedValue(_uplink);
            container.ComposeExportedValue(_downlink);
            //_poster = _mockRepository.DynamicMock<NotifiedElementPoster>();
            //_posterFactory = _mockRepository.DynamicMock<IPacketResourcePoster>();
        //    container.ComposeExportedValue<ResourcePoster>(_poster);
            container.ComposeExportedValue(_posterFactory);
            _pool = container.GetExportedValue<ITypedPool>();
            _subscriptor = container.GetExportedValue<IAnnouncerSubscriptor>();
            var service = container.GetExportedValue<ICacheServicing>();
            service.Initialize(new Settings
            {
                
            }, container);
        }
Exemple #22
0
        private static IRun CreateRun()
        {
            ThreadPool.SetMinThreads(32, 32);

            var args = ParseArguments();

            var compositionContainer = new CompositionContainer(new AssemblyCatalog(typeof(Program).Assembly));

            compositionContainer.ComposeExportedValue(new RunData
            {
                SampleRate = args.SampleRate,
                Warmup = args.Warmup,
                Duration = args.Duration,
                Connections = args.Connections,
                Payload = GetPayload(args.PayloadSize),
                Senders = args.Senders,
                Transport = args.Transport,
                Host = args.Host,
                Url = args.Url,
                SendDelay = args.SendDelay,

                // Scaleout
                RedisServer = args.RedisServer,
                RedisPort = args.RedisPort,
                RedisPassword = args.RedisPassword,
                ServiceBusConnectionString = args.ServiceBusConnectionString,
                SqlConnectionString = args.SqlConnectionString,
                SqlTableCount = args.SqlTableCount,
            });

            return compositionContainer.GetExportedValue<IRun>(args.RunName);
        }
Exemple #23
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            var catalog = new AggregateCatalog();

            catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
            catalog.Catalogs.Add(new DirectoryCatalog("."));

            var container = new CompositionContainer(catalog);

            try
            {
                container.ComposeParts(this);
                container.ComposeExportedValue("container", container);

                Lazy<IModuleController> controller = container.GetExport<IModuleController>();
                if (controller == null) return;

                controller.Value.CompositionContainer = container;
                controller.Value.Run();
            }
            catch (CompositionException exception)
            {
                MessageBox.Show(exception.ToString());
            }
        }
Exemple #24
0
        /// <summary>
        /// Initializes a new instance.
        /// </summary>
        /// <param name="bus"></param>
        /// <param name="baseUri"></param>
        /// <param name="exports"></param>
        public RnetHost(RnetBus bus, string baseUri, CompositionContainer exports)
        {
            Contract.Requires<ArgumentNullException>(bus != null);
            Contract.Requires<ArgumentNullException>(baseUri != null);
            Contract.Requires<ArgumentNullException>(exports != null);
            Contract.Requires<ArgumentException>(baseUri.EndsWith("/"));

            this.bus = bus;
            this.baseUri = baseUri;
            this.container = exports;

            // export initial values
            exports.ComposeExportedValue<ICompositionService>(new CompositionService(exports));
            exports.ComposeExportedValue(this);
            exports.ComposeExportedValue(bus);
        }
 private static IList<IUploadHandler> GetUploadHandlers(IApplicationSettings settings)
 {
     // Use MEF to locate the content providers in this assembly
     var compositionContainer = new CompositionContainer(new AssemblyCatalog(typeof(UploadProcessor).Assembly));
     compositionContainer.ComposeExportedValue<IApplicationSettings>(settings);
     return compositionContainer.GetExportedValues<IUploadHandler>().ToList();
 }
Exemple #26
0
        private void Init(string connectionString, CloudProvider provider)
        {
            var catalog = new DirectoryCatalog(".");
            var container = new CompositionContainer(catalog);
            container.ComposeExportedValue<string>(connectionString);
            _provider = container.GetExportedValue<IStorageProvider>(provider.ToString());

        }
        public static CompositionContainer Create(ComposablePartCatalog catalog)
        {
            var container = new CompositionContainer(new AggregateCatalog(catalog,
                new TypeCatalog(typeof(CompositionContainer))));

            container.ComposeExportedValue<CompositionContainer>(container);

            return container;
        }
        public Host()
        {
            container = new CompositionContainer(
                catalog = new AggregateCatalog(new AssemblyCatalog(typeof(Host).Assembly)),
                CompositionOptions.DisableSilentRejection | CompositionOptions.IsThreadSafe | CompositionOptions.ExportCompositionService);

            // export initial values
            container.ComposeExportedValue(this);
        }
Exemple #29
0
 void Application_Start(object sender, EventArgs e)
 {
     var agg = new AggregateCatalog();
     var catalog =new DirectoryCatalog(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin"));
     agg.Catalogs.Add(catalog);
     CompositionContainer container=new CompositionContainer(agg);
     ServiceLocator.SetLocatorProvider(() => new MefAdapter(container));
     DomainService.Factory = new MefServiceFactory();
     container.ComposeExportedValue<IServiceLocator>(ServiceLocator.Current);
 }
Exemple #30
0
 private void InitializeContainer()
 {
     var catalog = new AggregateCatalog();
     var packageCatalog = new PackageCatalog();
     catalog.Catalogs.Add(packageCatalog);
     packageCatalog.AddPackage(Package.Current);
     var container = new CompositionContainer(catalog);
     container.ComposeExportedValue(packageCatalog);
     CompositionHost.InitializeContainer(container);
 }