/// <summary> /// Instructs MEF to satisfy all imports, against the current /// collection of catalogs,for the provided part. /// </summary> /// <param name="part">The object (MEF part) that should be composed</param> public static void ComposeParts(Object part) { try { // The logger is used before configruation and initialization // so we want to handle it in a special way. We just want to // compose it using a single filtered catalog to find the default // logger. Everything will be rebuilt and recomposed after // configruation. if (part is Logging.LoggerManager) { // Create a Berico.LinkAnalysis. FilteredCatalog loggerCatalog = BuildLoggerProviderCatalog(new AssemblyCatalog(System.Reflection.Assembly.GetExecutingAssembly())); primaryCatalog.Catalogs.Add(loggerCatalog); CompositionHost.Initialize(new CompositionContainer(primaryCatalog)); } // Now we compose and satisfy the imports for the provided Part CompositionInitializer.SatisfyImports(part); } catch (Exception ex) { if (logger != null) { logger.WriteLogEntry(Logging.LogLevel.ERROR, "An error occurred trying to compose the parts for the provided object.", ex, null); } else { // This is only for testing. We don't really want to // do this in the long run. MessageBox.Show(ex.Message); } } }
private void Application_Startup(object sender, StartupEventArgs e) { Container = new CompositionContainer(new DeploymentCatalog()); CompositionHost.Initialize(Container); CompositionInitializer.SatisfyImports(this); RootVisual = new Commodities(); }
/// <summary> /// Called by an application in order to initialize the application extension service. /// </summary> /// <param name="context">Provides information about the application state. </param> public void StartService(ApplicationServiceContext context) { var logLevel = LogSeverityLevel; if (context.ApplicationInitParams.ContainsKey(Constants.INIT_PARAM_LOGLEVEL)) { logLevel = (LogSeverity) Enum.Parse(typeof(LogSeverity), context.ApplicationInitParams[Constants.INIT_PARAM_LOGLEVEL], true); } _mainCatalog = new AggregateCatalog(new DeploymentCatalog()); // empty one adds current deployment (xap) _container = new CompositionContainer(_mainCatalog); CompositionHost.Initialize(_container); CompositionInitializer.SatisfyImports(this); if (Logger == null) { ILogger defaultLogger = new DefaultLogger(logLevel); _container.ComposeExportedValue(defaultLogger); } else { Logger.SetSeverity(logLevel); } DeploymentService.Catalog = _mainCatalog; DeploymentService.Container = _container; _mefDebugger = new MefDebugger(_container, Logger); }
private void OnAppStartup(object sender, StartupEventArgs e) { if (!String.IsNullOrEmpty(ApplicationStartupParameters.Current.Language) && !ApplicationStartupParameters.Current.Language.StartsWith("EN", StringComparison.InvariantCultureIgnoreCase)) { var culture = new CultureInfo(ApplicationStartupParameters.Current.Language); var catalog = new DeploymentCatalog( new Uri(String.Format("{0}.{1}.xap", "Silverlight", culture.TwoLetterISOLanguageName), UriKind.Relative)); CompositionHost.Initialize(catalog); catalog.DownloadCompleted += (s, args) => { if (null == args.Error) { Thread.CurrentThread.CurrentCulture = culture; Thread.CurrentThread.CurrentUICulture = culture; Start(); } else { // cannot download resources for specific language, continue with default language Start(); } }; catalog.DownloadAsync(); } else { Start(); } }
public static void Initialize() { _aggregateCatalog = new AggregateCatalog(); _aggregateCatalog.Catalogs.Add(new DeploymentCatalog()); var container = new CompositionContainer(_aggregateCatalog); CompositionHost.Initialize(_aggregateCatalog); }
public App() { InitializeComponent(); _mainCatalog = new AggregateCatalog(new DeploymentCatalog()); _container = new CompositionContainer(_mainCatalog); _container.ComposeExportedValue <IApplicationHost>(this); CompositionHost.Initialize(_container); CompositionInitializer.SatisfyImports(this); }
public void StartService(ApplicationServiceContext context) { CompositionHost.Initialize( new AssemblyCatalog( Application.Current.GetType().Assembly), new AssemblyCatalog(typeof(AnalyticsEvent).Assembly), new AssemblyCatalog(typeof(TrackAction).Assembly)); _innerService.StartService(context); }
private void InitializerContainer() { var catalog = new AggregateCatalog(); catalog.Catalogs.Add(CreateCatalog("HelloMEF.Extensions.xap")); CompositionHost.Initialize(new DeploymentCatalog(), catalog); CompositionInitializer.SatisfyImports(this); }
private static void initCatalogIfRequired() { if (initComplete) { return; } CompositionHost.Initialize(partCatalogs); initComplete = true; }
protected override IServiceLocator CreateContainer() { var catalog = new AggregateCatalog( SelectAssemblies().Select(x => new AssemblyCatalog(x)).ToArray() ); var container = CompositionHost.Initialize(catalog); return(new MEFAdapter(container)); }
public void When_initialize_is_called_passing_in_catalogs_then_container_is_created_with_those_catalogs() { var catalog = new AssemblyCatalog(typeof(CompositionHostTests).Assembly); CompositionHost.Initialize(catalog); var container = CompositionHost._container; var aggregate = (AggregateCatalog)container.Catalog; Assert.AreEqual(catalog, aggregate.Catalogs.First()); }
public void When_initialize_called_passing_in_a_container_is_set_to_that_container() { var catalog = new AssemblyCatalog(typeof(CompositionHostTests).Assembly); var container = new CompositionContainer(catalog); CompositionHost.Initialize(container); var overridenContainer = CompositionHost._container; Assert.AreEqual(container, overridenContainer); }
protected override IServiceLocator CreateContainer() { var container = CompositionHost.Initialize( new AggregateCatalog( SelectAssemblies().Select(x => new AssemblyCatalog(x)).OfType <ComposablePartCatalog>() ) ); return(new MEFAdapter(container)); }
private void Application_Startup(object sender, StartupEventArgs e) { var catalog = new AggregateCatalog(new DeploymentCatalog()); _extension = new DeploymentCatalog("SilverlightMEF.Extensions.xap"); catalog.Catalogs.Add(_extension); var container = new CompositionContainer(catalog); CompositionHost.Initialize(container); container.ComposeExportedValue <ILaunchInterface>(this); CompositionInitializer.SatisfyImports(this); }
private void InitMef() { var catalog = new AggregateCatalog(); catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly())); catalog.Catalogs.Add(new AssemblyCatalog(typeof(IApplicationController).Assembly)); catalog.Catalogs.Add(new AssemblyCatalog(typeof(WsQueueManagerFactory).Assembly)); var container = new CompositionContainer(catalog, CompositionOptions.DisableSilentRejection); CompositionHost.Initialize(container); }
protected override IServiceLocator CreateContainer() { var catalog = new AggregateCatalog(SelectAssemblies().Select(x => new AssemblyCatalog(x)).OfType <ComposablePartCatalog>()); container = CompositionHost.Initialize(catalog); var batch = new CompositionBatch(); batch.AddExportedValue(catalog); container.Compose(batch); return(new MEFAdapter(container)); }
protected override void Configure() { container = CompositionHost.Initialize( new AggregateCatalog(AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType <ComposablePartCatalog>())); var batch = new CompositionBatch(); batch.AddExportedValue <IWindowManager>(new WindowManager()); batch.AddExportedValue <IEventAggregator>(new EventAggregator()); batch.AddExportedValue(container); container.Compose(batch); }
public ExportExample() { // Create a Windsor container and add a type. var container = new WindsorContainer(); container.Register(Component.For <IMyComponent>().ImplementedBy <MyComponent>().LifeStyle.Singleton); // Add the Export Provider, in addition to the DeploymentCatalog var compContainer = new CompositionContainer(new DeploymentCatalog(), new CastleExportProvider(container)); // Should only be called once, before any attempt to SatisfyImports. CompositionHost.Initialize(compContainer); CompositionInitializer.SatisfyImports(this); Test = string.Join(", ", Components.Select(c => c.DoSomething)); }
protected override IServiceLocator CreateContainer() { var container = CompositionHost.Initialize( new AggregateCatalog( SelectAssemblies().Select(x => new AssemblyCatalog(x)).OfType <ComposablePartCatalog>() ) ); var batch = new CompositionBatch(); batch.AddExportedValue <Func <IMessageBox> >(() => container.GetExportedValue <IMessageBox>()); batch.AddExportedValue <Func <CustomerViewModel> >(() => container.GetExportedValue <CustomerViewModel>()); batch.AddExportedValue <Func <OrderViewModel> >(() => container.GetExportedValue <OrderViewModel>()); container.Compose(batch); return(new MEFAdapter(container)); }
protected override void Configure() { container = CompositionHost.Initialize(new AggregateCatalog(AssemblySource.Instance.Select(x => new AssemblyCatalog(x)) .OfType <ComposablePartCatalog>())); var batch = new CompositionBatch(); // manually extend the MEF container with caliburn types batch.AddExportedValue <IWindowManager>(new WindowManager()); batch.AddExportedValue <IEventAggregator>(new EventAggregator()); batch.AddExportedValue <Func <IMessageBox> >(() => container.GetExportedValue <IMessageBox>()); batch.AddExportedValue <Func <CarbonFootprintViewModel> >(() => container.GetExportedValue <CarbonFootprintViewModel>()); batch.AddExportedValue(container); container.Compose(batch); }
/// <summary> /// By default, we are configured to use MEF /// </summary> protected override void Configure() { var catalog = new AggregateCatalog( AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType <ComposablePartCatalog>() ); container = CompositionHost.Initialize(catalog); var batch = new CompositionBatch(); batch.AddExportedValue <IWindowManager>(new Caliburn.Micro.TelerikWindowManager()); batch.AddExportedValue <IEventAggregator>(new EventAggregator()); batch.AddExportedValue(container); batch.AddExportedValue(catalog); StyleManager.ApplicationTheme = ThemeManager.FromName("Metro"); container.Compose(batch); }
/// <summary> /// Initialize MEF Container and load specified plugin xap file. /// </summary> private void InitializeContainer() { var catalog = new AggregateCatalog(); // Add this assembly to list of catalogs catalog.Catalogs.Add(new DeploymentCatalog()); // Add charting assembly to list of catalogs var uri = new Uri("SilverlightCharts.xap", UriKind.Relative); var chartCatalog = new DeploymentCatalog(uri); chartCatalog.DownloadCompleted += catalog_DownloadCompleted; catalog.Catalogs.Add(chartCatalog); // Perform part composition. CompositionHost.Initialize(catalog); // Asynchronously download charts imports chartCatalog.DownloadAsync(); }
/// <summary> /// By default, we are configured to use MEF /// </summary> protected override void Configure() { FrameworkExtensions.Message.Attach.AllowExtraSyntax(MessageSyntaxes.SpecialValueProperty | MessageSyntaxes.XamlBinding); FrameworkExtensions.ActionMessage.EnableFilters(); FrameworkExtensions.ViewLocator.EnableContextFallback(); Localizer.CustomResourceManager = Properties.Demo.ResourceManager; // Return a generic sample view if the sample doesn't provide a custom view var baseLocate = ViewLocator.LocateTypeForModelType; ViewLocator.LocateTypeForModelType = (type, dependencyObject, context) => { var baseView = baseLocate(type, dependencyObject, context); if (baseView == null && type.GetInterfaces().Contains(typeof(ISample))) { return(typeof(GenericSampleView)); } return(baseView); }; // Namespace mapping for custom dialog view ViewLocator.AddSubNamespaceMapping("Dialogs", "Demo.Views"); // or alternatively // ViewLocator.AddNamespaceMapping("Caliburn.Micro.Contrib.Dialogs", "Caliburn.Micro.Contrib.Demo.Views"); var catalog = new AggregateCatalog( AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType <ComposablePartCatalog>() ); container = CompositionHost.Initialize(catalog); var batch = new CompositionBatch(); batch.AddExportedValue <IWindowManager>(new WindowManager()); batch.AddExportedValue <IEventAggregator>(new EventAggregator()); batch.AddExportedValue(container); batch.AddExportedValue(catalog); container.Compose(batch); }
protected override void Configure() { var catalog = new AggregateCatalog( AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType <ComposablePartCatalog>() ); container = CompositionHost.Initialize(catalog); var batch = new CompositionBatch(); batch.AddExportedValue <IWindowManager>(new WindowManager()); batch.AddExportedValue <IEventAggregator>(new EventAggregator()); batch.AddExportedValue <INavigationService>(new CaliburnNavigationService()); batch.AddExportedValue(container); batch.AddExportedValue(catalog); // builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly()).Where(x => typeof(Screen).IsAssignableFrom(x)).Named<Screen>(x => x.GetNavigationName()); //NavigationConvention.AddNavigationConventions(); container.Compose(batch); }
protected override void Configure() { var catalog = new AggregateCatalog(AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType <ComposablePartCatalog>()); container = CompositionHost.Initialize(catalog); var batch = new CompositionBatch(); batch.AddExportedValue <IWindowManager>(new WindowManager()); batch.AddExportedValue <IEventAggregator>(new EventAggregator()); batch.AddExportedValue(container); batch.AddExportedValue(catalog); container.Compose(batch); Coroutine.Completed += (s, e) => { if (e.Error != null) { MessageBox.Show(e.Error.Message); } }; }
protected override void Configure() { ConfigureConventions(); var catalog = new AggregateCatalog( AssemblySource.Instance.Select(assembly => new AssemblyCatalog(assembly)) .Cast <ComposablePartCatalog>()); RegisterTypesByConvention(catalog); container = CompositionHost.Initialize(catalog); var batch = new CompositionBatch(); batch.AddExportedValue <IWindowManager>(new WindowManager()); batch.AddExportedValue <IEventAggregator>(new EventAggregator()); batch.AddExportedValue <ShowMessageBox>(ShowMessageBox); batch.AddExportedValue(container); batch.AddExportedValue(catalog); container.Compose(batch); }
protected override void Configure() { var composablePartCatalogs = AssemblySource.Instance.Select(x => new AssemblyCatalog(x)) .OfType <ComposablePartCatalog>(); var aggregateCatalog = new AggregateCatalog(composablePartCatalogs); container = CompositionHost.Initialize(aggregateCatalog); var batch = new CompositionBatch(); batch.AddExportedValue <IWindowManager>(new WindowManager()); batch.AddExportedValue <IEventAggregator>(new EventAggregator()); batch.AddExportedValue <Func <IMessageBox> >(() => container.GetExportedValue <IMessageBox>()); batch.AddExportedValue <Func <IModule> >(() => container.GetExportedValue <IModule>()); batch.AddExportedValue <Func <IAccountsRepository> >(() => container.GetExportedValue <IAccountsRepository>()); batch.AddExportedValue <Func <ICategoriesRepository> >(() => container.GetExportedValue <ICategoriesRepository>()); batch.AddExportedValue(container); container.Compose(batch); FilterFramework.Configure(); }
protected override void Configure() { AggregateCatalog catalog = new AggregateCatalog( AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType <ComposablePartCatalog>() ); #if SILVERLIGHT container = CompositionHost.Initialize(catalog); #else container = new CompositionContainer(catalog); #endif var batch = new CompositionBatch(); batch.AddExportedValue <IWindowManager>(new WindowManager()); batch.AddExportedValue <IEventAggregator>(new EventAggregator()); batch.AddExportedValue <Func <IMessageBox> >(() => container.GetExportedValue <IMessageBox>()); batch.AddExportedValue <Func <CustomerViewModel> >(() => container.GetExportedValue <CustomerViewModel>()); batch.AddExportedValue <Func <OrderViewModel> >(() => container.GetExportedValue <OrderViewModel>()); batch.AddExportedValue(container); container.Compose(batch); }
protected override void ConfigureContainer(ContainerBuilder builder) { base.ConfigureContainer(builder); var assemblyDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var catalogs = new List <ComposablePartCatalog> { new AggregateCatalog(AssemblySource.Instance.Select(x => new AssemblyCatalog(x))), new DirectoryCatalog(assemblyDirectory, "Plugins.*.dll"), new DirectoryCatalog(assemblyDirectory, "Plugins.dll"), new AssemblyCatalog(typeof(IItem).Assembly) }; var pluginsPath = Path.Combine(assemblyDirectory, "Plugins"); if (Directory.Exists(pluginsPath)) { catalogs.Add(new DirectoryCatalog(pluginsPath, "Plugins.*.dll")); catalogs.Add(new DirectoryCatalog(pluginsPath, "Plugins.dll")); } else { pluginsPath = assemblyDirectory; } MefContainer = CompositionHost.Initialize(catalogs.ToArray()); var loadConfiguration = new LoadConfiguration(new DirectoryInfo(Path.Combine(assemblyDirectory, "Configuration")), MefContainer); var localConfigurationDirectory = new DirectoryInfo(Path.Combine(assemblyDirectory, "Local.Configuration")); if (localConfigurationDirectory.Exists) { loadConfiguration.AddConfigurationLocation(localConfigurationDirectory); } loadConfiguration.Load(); var dataDirectory = Path.Combine(assemblyDirectory, "Data"); var coreConfiguration = new CoreConfiguration(dataDirectory, pluginsPath); var learningStorageLocation = new DirectoryInfo(Path.Combine(coreConfiguration.DataDirectory, "Learnings")); var indexStorageLocation = new DirectoryInfo(Path.Combine(coreConfiguration.DataDirectory, "Index")); var updateManagerAdapter = new UpdateManagerAdapter(); var scheduler = new StdSchedulerFactory().GetScheduler(); scheduler.JobFactory = new MefJobFactory(new SimpleJobFactory(), MefContainer); var batch = new CompositionBatch(); batch.AddExportedValue(MefContainer); batch.AddExportedValue <ILoadConfiguration>(loadConfiguration); batch.AddExportedValue <ILog>(new NLogAdapterToCoreILog(NLog.LogManager.GetLogger("mef"))); batch.AddExportedValue(coreConfiguration); batch.AddExportedValue(updateManagerAdapter); batch.AddExportedValue <IScheduler>(scheduler); MefContainer.Compose(batch); MefContainer.SatisfyImportsOnce(updateManagerAdapter); builder.RegisterInstance(MefContainer).AsSelf(); builder.RegisterInstance(coreConfiguration).AsSelf(); builder.RegisterInstance(updateManagerAdapter).AsSelf(); builder.RegisterInstance(scheduler).As <IScheduler>(); builder.RegisterInstance <IWindowManager>(new WindowManager()); builder.RegisterInstance <IEventAggregator>(new EventAggregator()); builder.RegisterModule(new LoggingModule(t => new NLogAdapterToCoreILog(NLog.LogManager.GetLogger(t.FullName)), t => NLog.LogManager.GetLogger(t.FullName))); builder.RegisterModule(new SatisfyMefImports(MefContainer)); builder.RegisterType <MainWindowViewModel>().AsSelf(); builder.RegisterType <AutoCompleteBasedOnLucene>().AsSelf(); builder.RegisterType <GetActionsForItem>().As <IGetActionsForItem>(); builder.RegisterType <ConverterRepository>().As <IConverterRepository>(); builder.RegisterType <SourceStorageFactory>().AsSelf().SingleInstance(); builder.RegisterType <FileSystemLearningRepository>().As <ILearningRepository>().WithParameter("input", learningStorageLocation); builder.RegisterType <ScheduleIndexJobs>().As <IStartupTask>(); builder.RegisterType <ScheduleUpdateCheckJob>().As <IStartupTask>(); builder.RegisterType <IronPythonCommandsMefExport>().As <IStartupTask>(); builder.RegisterType <LogScheduledJobs>().As <IStartupTask>(); builder.RegisterType <ProcessMonitor>().As <IStartupTask>(); builder.RegisterType <Shutdown>().AsSelf(); builder.RegisterType <SeparateIndexesDirectoryFactory>() .As <IDirectoryFactory>().WithParameter("root", indexStorageLocation) .SingleInstance(); }