本文整理汇总了C#中System.ComponentModel.Composition.Hosting.CompositionContainer.GetExportedValue方法的典型用法代码示例。如果您正苦于以下问题:C# CompositionContainer.GetExportedValue方法的具体用法?C# CompositionContainer.GetExportedValue怎么用?C# CompositionContainer.GetExportedValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.ComponentModel.Composition.Hosting.CompositionContainer
的用法示例。
在下文中一共展示了CompositionContainer.GetExportedValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Document
/// <summary>
/// Initializes a new instance.
/// </summary>
/// <param name="xml"></param>
/// <param name="catalog"></param>
/// <param name="exports"></param>
Document(
Func<Document, XDocument> xml,
ComposablePartCatalog catalog,
ExportProvider exports)
{
Contract.Requires<ArgumentNullException>(xml != null);
// configure composition
this.configuration = GetConfiguration(catalog, exports);
this.container = new CompositionContainer(configuration.HostCatalog, true, new CompositionContainer(configuration.GlobalCatalog, true, configuration.Exports));
this.container.GetExportedValue<DocumentEnvironment>().SetHost(this);
// required services
this.invoker = container.GetExportedValue<IInvoker>();
this.trace = container.GetExportedValue<ITraceService>();
// initialize xml
this.xml = xml(this);
this.xml.AddAnnotation(this);
// parallel initialization of common interfaces
Parallel.ForEach(this.xml.DescendantNodesAndSelf(), i =>
{
Enumerable.Empty<object>()
.Concat(i.Interfaces<IOnInit>())
.Concat(i.Interfaces<IOnLoad>())
.ToLinkedList();
});
// initial invocation entry
this.invoker.Invoke(() => { });
}
示例2: Prepare
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>();
}
示例3: ApplicationController
public ApplicationController(CompositionContainer container, IPresentationService presentationService,
IMessageService messageService, ShellService shellService, ProxyController proxyController, DataController dataController)
{
InitializeCultures();
presentationService.InitializeCultures();
this.container = container;
this.dataController = dataController;
this.proxyController = proxyController;
this.messageService = messageService;
this.dataService = container.GetExportedValue<IDataService>();
this.floatingViewModel = container.GetExportedValue<FloatingViewModel>();
this.mainViewModel = container.GetExportedValue<MainViewModel>();
this.userBugsViewModel = container.GetExportedValue<UserBugsViewModel>();
this.teamBugsViewModel = container.GetExportedValue<TeamBugsViewModel>();
shellService.MainView = mainViewModel.View;
shellService.UserBugsView = userBugsViewModel.View;
shellService.TeamBugsView = teamBugsViewModel.View;
this.floatingViewModel.Closing += FloatingViewModelClosing;
this.showMainWindowCommand = new DelegateCommand(ShowMainWindowCommandExcute);
this.englishCommand = new DelegateCommand(() => SelectLanguage(new CultureInfo("en-US")));
this.chineseCommand = new DelegateCommand(() => SelectLanguage(new CultureInfo("zh-CN")));
this.settingCommand = new DelegateCommand(SettingDialogCommandExcute, CanSettingDialogCommandExcute);
this.aboutCommand = new DelegateCommand(AboutDialogCommandExcute);
this.exitCommand = new DelegateCommand(ExitCommandExcute);
}
示例4: Initialize
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);
}
}
示例5: Main
static void Main()
{
try
{
programCatalog = new AggregateCatalog();
programCatalog.Catalogs.Add(new DirectoryCatalog(Directory.GetCurrentDirectory()));
programCatalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
programContainer = new CompositionContainer(programCatalog);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.ThreadException += new ThreadExceptionEventHandler(Program.otherException);
Application.Run(programContainer.GetExportedValue<FrmMain>());
}
catch (Exception e)
{
programContainer.GetExportedValue<FrmMain>().richTextBox1.AppendText("\n" + e.Message);
string logStr = string.Concat(new string[]
{
DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss"),
"\t",
e.Message,
"\t",
e.Source
});
FileLog.FileLogOut("Client.log", logStr);
}
}
示例6: WhenInitializingAModuleWithACatalogPendingToBeLoaded_ThenLoadsTheCatalogInitializesTheModule
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);
}
示例7: Main
static void Main(string[] args)
{
var container = new CompositionContainer();
ComposeBatchOne(container);
container.GetExportedValue<Bootstrapper>().Run();
ComposeBatchTwo(container);
container.GetExportedValue<Bootstrapper>().Run();
}
示例8: Initialize
public static void Initialize(TestContext context) {
_container = SetupServerMefContainer();
_registry = _container.GetExportedValue<IFileSystemProcessor>();
_searchEngine = _container.GetExportedValue<ISearchEngine>();
_searchEngine.FilesLoaded += (sender, result) => _serverReadyEvent.Set();
_testFile = Utils.GetChromiumTestEnlistmentFile();
_registry.RegisterFile(new FullPath(_testFile.FullName));
}
示例9: Test1
/// <summary>
/// 同一コントラクト名・別クラステスト
/// </summary>
/// <param name="container"></param>
private static void Test1(CompositionContainer container)
{
// インスタンスを取得する
var type1 = container.GetExportedValue<ITest1>("test");
var type2 = container.GetExportedValue<ITest2>("test");
type1.Execute();
type2.Execute();
}
示例10: CreateTextBuffer
public static ITextBuffer CreateTextBuffer(CompositionContainer container, string text)
{
var contentTypeRegistry = container.GetExportedValue<IContentTypeRegistryService>();
var contentType = contentTypeRegistry.GetContentType(HlslConstants.ContentTypeName)
?? contentTypeRegistry.AddContentType(HlslConstants.ContentTypeName, null);
var textBufferFactory = container.GetExportedValue<ITextBufferFactoryService>();
var textBuffer = textBufferFactory.CreateTextBuffer(text, contentType);
return textBuffer;
}
示例11: ContainerResolvesBothAbstractionAndConcreteType
public void ContainerResolvesBothAbstractionAndConcreteType()
{
var catalog = new TypeCatalog(typeof(Ploeh.Samples.Menu.Mef.Attributed.Unmodified.Abstract.SauceBéarnaise));
var container = new CompositionContainer(catalog);
var sauce = container.GetExportedValue<SauceBéarnaise>();
var ingredient = container.GetExportedValue<IIngredient>();
Assert.NotNull(sauce);
Assert.NotNull(ingredient);
}
示例12: WhenPartIsNonShared_ThenGetExportGetsDifferent
public void WhenPartIsNonShared_ThenGetExportGetsDifferent()
{
var catalog = new TypeCatalog(typeof(NonSharedFoo));
var filtered = new FilteringReflectionCatalog(catalog);
var container = new CompositionContainer(filtered);
var export1 = container.GetExportedValue<NonSharedFoo>();
var export2 = container.GetExportedValue<NonSharedFoo>();
Assert.NotSame(export1, export2);
}
示例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: RegisterInstancesAndResolveByName
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));
}
}
示例15: StateIsNotShared
public void StateIsNotShared()
{
var container =
new CompositionContainer(
new AggregateCatalog(
new AssemblyCatalog(typeof(ICurrentState<>).Assembly),
new TypeCatalog(typeof(TestCurrentState), typeof(TestState))));
var state = container.GetExportedValue<IState<string>>();
Assert.IsInstanceOfType(state, typeof(TestState));
Assert.AreNotSame(state, container.GetExportedValue<IState<string>>());
}