// -------------------------------------------------------------------------------------------------------------------- // // This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. // // // The MEF Bootstrapper (Not Used) // // -------------------------------------------------------------------------------------------------------------------- namespace HandBrakeWPF.Startup { using System; using System.Collections.Generic; using System.ComponentModel.Composition; using System.ComponentModel.Composition.Hosting; using System.Linq; using Caliburn.Micro; using HandBrakeWPF.ViewModels.Interfaces; /// /// The MEF Bootstrapper (Not Used) /// public class MefBootstrapper : Bootstrapper { /// /// The Backing field for the container /// private CompositionContainer container; /// /// MEF Configure /// protected override void Configure() { container = new CompositionContainer( new AggregateCatalog(AssemblySource.Instance.Select(x => new AssemblyCatalog(x))) ); var batch = new CompositionBatch(); batch.AddExportedValue(new WindowManager()); batch.AddExportedValue(new EventAggregator()); batch.AddExportedValue(container); container.Compose(batch); } /// /// Get an Instance of a service /// /// /// The service. /// /// /// The key. /// /// /// The Service Requested /// protected override object GetInstance(Type serviceType, string key) { string contract = string.IsNullOrEmpty(key) ? AttributedModelServices.GetContractName(serviceType) : key; var exports = container.GetExportedValues(contract); if (exports.Count() > 0) return exports.First(); throw new Exception(string.Format("Could not locate any instances of contract {0}.", contract)); } /// /// Get all instances of a service /// /// /// The service. /// /// /// A collection of instances of the requested service type. /// protected override IEnumerable GetAllInstances(Type serviceType) { return container.GetExportedValues(AttributedModelServices.GetContractName(serviceType)); } /// /// Build Up /// /// /// The instance. /// protected override void BuildUp(object instance) { container.SatisfyImportsOnce(instance); } } }