本文整理汇总了C#中System.ComponentModel.Composition.Hosting.CompositionBatch.AddExportedValue方法的典型用法代码示例。如果您正苦于以下问题:C# CompositionBatch.AddExportedValue方法的具体用法?C# CompositionBatch.AddExportedValue怎么用?C# CompositionBatch.AddExportedValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.ComponentModel.Composition.Hosting.CompositionBatch
的用法示例。
在下文中一共展示了CompositionBatch.AddExportedValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BindServices
protected virtual void BindServices(CompositionBatch batch)
{
batch.AddExportedValue<IWindowManager>(new WindowManager());
batch.AddExportedValue<IEventAggregator>(new EventAggregator());
batch.AddExportedValue(Container);
batch.AddExportedValue(this);
}
示例2: Compose
private bool Compose()
{
var catalog = new AggregateCatalog();
catalog.Catalogs.Add(new AssemblyCatalog(typeof(IMefShapesGame).Assembly));
catalog.Catalogs.Add(new AssemblyCatalog(typeof(DefaultDimensions).Assembly));
var partCreatorEP = new DynamicInstantiationExportProvider();
this._container = new CompositionContainer(catalog, partCreatorEP);
partCreatorEP.SourceProvider = this._container;
CompositionBatch batch = new CompositionBatch();
batch.AddPart(this);
batch.AddExportedValue<ICompositionService>(this._container);
batch.AddExportedValue<AggregateCatalog>(catalog);
try
{
this._container.Compose(batch);
}
catch (CompositionException compositionException)
{
MessageBox.Show(compositionException.ToString());
Shutdown(1);
return false;
}
return true;
}
示例3: Configure
protected override void Configure()
{
_container = new CompositionContainer(
new AggregateCatalog(
AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType<ComposablePartCatalog>()
)
);
MessageBinder.SpecialValues.Add("$orignalsourcecontext", context =>
{
var args = context.EventArgs as RoutedEventArgs;
if (args == null)
{
return null;
}
var fe = args.OriginalSource as FrameworkElement;
if (fe == null)
{
return null;
}
return fe.DataContext;
});
var batch = new CompositionBatch();
batch.AddExportedValue<IWindowManager>(new WindowManager());
batch.AddExportedValue<IEventAggregator>(new EventAggregator());
batch.AddExportedValue(_container);
_container.Compose(batch);
}
示例4: Configure
/// <summary>Override to configure the framework and setup your IoC container.</summary>
protected override void Configure()
{
// Add the assembly source to the catalog.
// ReSharper disable once RedundantEnumerableCastCall
var catalog = new AggregateCatalog(AssemblySource.Instance.Select(i => new AssemblyCatalog(i)).OfType<ComposablePartCatalog>());
// Create a new composition container.
// ReSharper disable once RedundantEnumerableCastCall
this.container = new CompositionContainer();
// Create a new composition container.
this.container = new CompositionContainer(catalog);
CompositionBatch compositionBatch = new CompositionBatch();
// Add EventAggregator to composition batch.
compositionBatch.AddExportedValue<IEventAggregator>(new EventAggregator());
compositionBatch.AddExportedValue<IWindowManager>(new WindowManager());
compositionBatch.AddExportedValue<ISettingsRepository>(new SettingsRepository());
compositionBatch.AddExportedValue<ISolutionRepository>(new SolutionRepository());
compositionBatch.AddExportedValue(new LogWriter(this.BuildLoggingConfiguration()));
// Add the container itself.
compositionBatch.AddExportedValue(this.container);
// Compose the container.
this.container.Compose(compositionBatch);
}
示例5: GetServiceLocator
internal static IServiceLocator GetServiceLocator(Assembly assembly, CompositionBatch batch)
{
var assemblyLocation = assembly.Location;
var file = new FileInfo(assemblyLocation);
var catalogs = new List<ComposablePartCatalog>
{
new AssemblyCatalog(assembly),
new DirectoryCatalog(file.DirectoryName ?? ".")
};
var catalog = new AggregateCatalog(catalogs);
var container = new CompositionContainer(catalog,
CompositionOptions.DisableSilentRejection |
CompositionOptions.IsThreadSafe );
var serviceLocator = new MefServiceLocator(container);
batch.AddExportedValue(container);
batch.AddExportedValue<IServiceLocator>(serviceLocator);
container.Compose(batch);
return serviceLocator;
}
示例6: SingleContainerPartReplacement
public void SingleContainerPartReplacement()
{
var container = ContainerFactory.Create();
var importPart = PartFactory.CreateImporter(true, "value1", "value2");
CompositionBatch batch = new CompositionBatch();
var export1Key = batch.AddExportedValue("value1", "Hello");
batch.AddExportedValue("value2", "World");
batch.AddPart(importPart);
container.Compose(batch);
Assert.AreEqual(2, importPart.ImportSatisfiedCount);
Assert.AreEqual("Hello", importPart.GetImport("value1"));
Assert.AreEqual("World", importPart.GetImport("value2"));
importPart.ResetImportSatisfiedCount();
batch = new CompositionBatch();
batch.RemovePart(export1Key);
batch.AddExportedValue("value1", "Goodbye");
container.Compose(batch);
Assert.AreEqual(1, importPart.ImportSatisfiedCount);
Assert.AreEqual("Goodbye", importPart.GetImport("value1"));
Assert.AreEqual("World", importPart.GetImport("value2"));
}
示例7: Init
public Runner Init(IFeedbackProvider feedbackProvider, string[] args)
{
var catalog = new AggregateCatalog(new AssemblyCatalog(typeof(Bootstrapper).Assembly));
var currentDir = Environment.CurrentDirectory;
var assemblyDir = new FileInfo(new Uri(Assembly.GetExecutingAssembly().CodeBase).AbsolutePath).Directory.FullName;
var paths = new string[]
{
assemblyDir,
Path.Combine(assemblyDir, "Tasks"),
currentDir,
Path.Combine(currentDir, "Tasks")
}.Unique();
var dirCatalogs = paths.Where(x => Directory.Exists(x))
.Select(x => new DirectoryCatalog(x, "*.Tasks.dll"));
dirCatalogs.Apply(x => catalog.Catalogs.Add(x));
var container = new CompositionContainer(catalog);
var parsed = new ArgumentParser().Parse(args);
var runner = new Runner(parsed.ActualArgs.ToArray());
var batch = new CompositionBatch();
batch.AddExportedValue<IFeedbackProvider>(feedbackProvider);
parsed.Options.Apply(x => batch.AddExportedValue<string>(x.Item1, x.Item2));
parsed.Switches.Apply(x => batch.AddExportedValue<bool>(x, true));
batch.AddPart(runner);
container.Compose(batch);
return runner;
}
示例8: Configure
protected override void Configure()
{
_container = new CompositionContainer(new AggregateCatalog(AssemblySource
.Instance
.Select(x => new AssemblyCatalog(x))
.OfType<ComposablePartCatalog>()
)
);
var batch = new CompositionBatch();
_portName = SerialPort.GetPortNames()[0];
_ecr = new Dp25(_portName);
var messenger = new MessageAggregator();
messenger.GetStream<SelectedPortChangedEvent>()
.Subscribe(e => _ecr.ChangePort(e.PortName));
batch.AddExportedValue<IWindowManager>(new WindowManager());
batch.AddExportedValue<IMessageAggregator>(messenger);
batch.AddExportedValue<Dp25>(_ecr);
batch.AddExportedValue(_container);
_container.Compose(batch);
}
示例9: Configure
protected override void Configure()
{
_container = new CompositionContainer(
new AggregateCatalog(AssemblySource.Instance.Select(x => new AssemblyCatalog(x)))
);
var batch = new CompositionBatch();
var fileStream = new FileStream(LocalSettings.ClientXmlFilePath, FileMode.OpenOrCreate, FileAccess.Read);
_settings = SettingsManager.LoadSettings<LocalSettings>(fileStream);
if (_settings == null)
{
_settings = new LocalSettings { FirstRun = true };
}
else
{
_settings.FirstRun = false;
}
batch.AddExportedValue(_settings);
batch.AddExportedValue<IWindowManager>(new WindowManager());
batch.AddExportedValue<IEventAggregator>(new EventAggregator());
batch.AddExportedValue(_container);
_container.Compose(batch);
}
示例10: BatchMultipleAdds_ShouldFireEvents
public void BatchMultipleAdds_ShouldFireEvents()
{
var container = ContainerFactory.Create();
var eventListener = new ExportProviderListener(container, container);
var batch = new CompositionBatch();
batch.AddExportedValue<object>("MyExport", new object());
batch.AddExportedValue<object>("MyExport2", new object());
batch.AddExportedValue<object>("MyExport3", new object());
eventListener.VerifyCompose(batch);
}
示例11: Compose
public void Compose()
{
var first = new AssemblyCatalog(Assembly.GetExecutingAssembly());
var container = new CompositionContainer(first);
var batch = new CompositionBatch();
batch.AddExportedValue<IFileSystem>(new FileSystem());
batch.AddExportedValue<IContentTransform>(new WebSequenceDiagrams());
batch.AddPart(this);
container.Compose(batch);
}
示例12: Configure
/* Managed Extensibility Framework
* A lot of this is just copy paste code, from http://caliburnmicro.com/documentation/bootstrapper
* This is used to make whatever we store in our CompositionContainer available across the application.
* In this example we have put the windowmanager and the evenAggregator in it.
* The WindowManager manages creation and showing of windows/dialogs/stuff like that.
* The EventAggregator is a service that provides us with the ability to publish objects from one entity to another, in a loose fashion. http://caliburnmicro.com/documentation/event-aggregator
* Once the configure part of this is setup, you can go to your respective classes, and mark them with the [Export] attribute, and then if you for example
* wanted to get a local instance of the windowmanager, mark the constructor with the [ImportingConstructor], like this:
* [ImportingConstructor]
* public AppViewModel(IWindowManager windowManager)
* which will make the framework put in the applications instance of the windowmanager, for use in whatever you want to.
*/
protected override void Configure()
{
_container = new CompositionContainer(new AggregateCatalog(AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType<ComposablePartCatalog>()));
//Collects values/stuff that has to go in our container
CompositionBatch batch = new CompositionBatch();
batch.AddExportedValue<IWindowManager>(new WindowManager());
batch.AddExportedValue<IEventAggregator>(new EventAggregator());
batch.AddExportedValue(_container);
_container.Compose(batch);
}
示例13: Configure
protected override void Configure()
{
InitializeApplicationDataDirectory();
var composeTask = Task.Factory.StartNew(() =>
{
// var aggregateCatalog = new AggregateCatalog(AssemblySource.Instance.Select(x => new AssemblyCatalog(x)));
var aggregateCatalog = new AggregateCatalog(new AssemblyCatalog(GetType().Assembly), new AssemblyCatalog(typeof(AutoCaptureEngine).Assembly), new AssemblyCatalog(typeof(IRepository<>).Assembly));
Container = new CompositionContainer(aggregateCatalog);
var batch = new CompositionBatch();
batch.AddExportedValue(Container);
batch.AddExportedValue<IEventAggregator>(new EventAggregator());
batch.AddExportedValue<IWindowManager>(new CustomWindowManager());
batch.AddExportedValue<Func<IMessageBox>>(() => Container.GetExportedValue<IMessageBox>());
batch.AddExportedValue<Func<HearthStatsDbContext>>(() => new HearthStatsDbContext());
// batch.AddExportedValue<IWindowManager>(new AppWindowManager());
// batch.AddExportedValue(MessageBus.Current);
var compose = Container.GetExportedValue<CompositionBuilder>();
compose.Compose(batch);
// var composeTasks = this.GetAllInstances<ICompositionTask>();
// composeTasks.Apply(s => s.Compose(batch));
Container.Compose(batch);
});
var initDbTask = Task.Factory.StartNew(InitializeDatabase);
Task.WaitAll(composeTask, initDbTask);
var logPath = Path.Combine((string)AppDomain.CurrentDomain.GetData("DataDirectory"), "logs");
_logManager = Container.GetExportedValue<IAppLogManager>();
_logManager.Initialize(logPath);
Container.GetExportedValue<CrashManager>().WireUp();
// Apply xaml/wpf fixes
var currentUICult = Thread.CurrentThread.CurrentUICulture.Name;
var currentCult = Thread.CurrentThread.CurrentCulture.Name;
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(currentUICult);
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(currentCult);
FrameworkElement.LanguageProperty.OverrideMetadata(
typeof(FrameworkElement),
new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
// Hook caliburn filter
FilterFrameworkCoreCustomization.Hook();
// Hook application events
Application.Activated += (s, e) => Container.GetExportedValue<IEventAggregator>().PublishOnCurrentThread(new ApplicationActivatedEvent());
Application.Deactivated += (s, e) => Container.GetExportedValue<IEventAggregator>().PublishOnCurrentThread(new ApplicationDeActivatedEvent());
}
示例14: Configure
protected override void Configure()
{
var catalog = new AggregateCatalog(AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType<ComposablePartCatalog>());
container = new CompositionContainer(catalog);
var batch = new CompositionBatch();
batch.AddExportedValue<IWindowManager>(new WindowManager());
batch.AddExportedValue<IEventAggregator>(new EventAggregator());
batch.AddExportedValue(container);
container.Compose(batch);
}
示例15: Configure
protected override void Configure()
{
container = new CompositionContainer(new AssemblyCatalog(Assembly.GetAssembly(typeof(ShellViewModel))));
var batch = new CompositionBatch();
batch.AddExportedValue<IWindowManager>(new WindowManager());
batch.AddExportedValue<IEventAggregator>(new EventAggregator());
batch.AddExportedValue(container);
container.Compose(batch);
}