本文整理汇总了C#中System.ComponentModel.Composition.Hosting.CompositionContainer.ComposeParts方法的典型用法代码示例。如果您正苦于以下问题:C# CompositionContainer.ComposeParts方法的具体用法?C# CompositionContainer.ComposeParts怎么用?C# CompositionContainer.ComposeParts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.ComponentModel.Composition.Hosting.CompositionContainer
的用法示例。
在下文中一共展示了CompositionContainer.ComposeParts方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Application_Startup
private void Application_Startup(object sender, StartupEventArgs e)
{
var assembly =
new AssemblyCatalog(Assembly.GetEntryAssembly());
var catalog = new AggregateCatalog();
catalog.Catalogs.Add(assembly);
catalog.Catalogs.Add(new DirectoryCatalog("."));
var compositionContainer
= new CompositionContainer(catalog);
compositionContainer.ComposeParts(this);
var locator = new MefServiceLocator(compositionContainer);
ServiceLocator.SetLocatorProvider(() => locator);
ViewModelManager.ViewModelShowEvent
+= vm => ViewManager.ViewShow(vm);
ViewModelManager.ViewModelCloseEvent
+= vm => ViewManager.ViewClose(vm);
var mainWindowViewModel = new MainWindowViewModel();
compositionContainer.ComposeParts(mainWindowViewModel);
MainWindow mainWindow = new MainWindow {DataContext = mainWindowViewModel};
mainWindow.Show();
}
示例2: ExtensionContainer
/// <summary>
/// Default constructor. Creates a new extension container and registers all
/// exported objects.
/// </summary>
public ExtensionContainer()
{
var catalog = new AggregateCatalog() ;
catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly())) ;
Container = new CompositionContainer(catalog) ;
Container.ComposeParts(this) ;
}
示例3: AssembleComponents
/// <summary>
/// This method loads the plugins.
/// </summary>
private void AssembleComponents()
{
var catalog = new AggregateCatalog();
//Note: we load not only from the plugins folder, but from this assembly as well.
var executingAssemblyCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
if (Directory.Exists(Environment.CurrentDirectory + "\\Plugins"))
{
catalog.Catalogs.Add(new DirectoryCatalog("Plugins"));
}
catalog.Catalogs.Add(executingAssemblyCatalog);
var container = new CompositionContainer(catalog);
try
{
container.ComposeParts(this);
}
catch (CompositionException compositionException)
{
_dialogService.ShowMessageAsync(_mainVm, "Error", string.Format("There was an error loading plugins: {0}", compositionException)).Forget();
}
}
示例4: TestMefStatusReportable
public void TestMefStatusReportable()
{
string dir = AssemblyDirectory;
//Lets get the nlog status reportable from MEF directory..
CompositionContainer _container;
//An aggregate catalog that combines multiple catalogs
var catalog = new AggregateCatalog();
//Adds all the parts found in the same assembly as the Program class
catalog.Catalogs.Add(new AssemblyCatalog(typeof(TestMEF).Assembly));
catalog.Catalogs.Add(new DirectoryCatalog(AssemblyDirectory));
//Create the CompositionContainer with the parts in the catalog
_container = new CompositionContainer(catalog);
//Fill the imports of this object
try
{
_container.ComposeParts(this);
}
catch (CompositionException compositionException)
{
Console.WriteLine(compositionException.ToString());
}
reporter.Report(2,1,"Test Report");
}
示例5: ExtensionManager
/// <summary>
/// Default private constructor.
/// </summary>
private ExtensionManager()
{
if (!Config.DisableComposition)
{
// Let MEF scan for imports
var catalog = new AggregateCatalog();
catalog.Catalogs.Add(Config.DisableCatalogSearch ? new DirectoryCatalog("Bin", "Piranha*.dll") : new DirectoryCatalog("Bin"));
#if !NET40
if (!System.Web.Compilation.BuildManager.IsPrecompiledApp)
{
#endif
try
{
// This feature only exists for Web Pages
catalog.Catalogs.Add(new AssemblyCatalog(Assembly.Load("App_Code")));
}
catch { }
#if !NET40
}
#endif
Container = new CompositionContainer(catalog);
Container.ComposeParts(this);
}
}
示例6: Main
public static void Main (string[] args)
{
var bootStrapper = new Bootstrapper();
//An aggregate catalog that combines multiple catalogs
var catalog = new AggregateCatalog();
//Adds all the parts found in same directory where the application is running!
var currentPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(typeof(MainClass)).Location) ?? "./";
catalog.Catalogs.Add(new DirectoryCatalog(currentPath));
//Create the CompositionContainer with the parts in the catalog
var container = new CompositionContainer(catalog);
//Fill the imports of this object
try
{
container.ComposeParts(bootStrapper);
}
catch (CompositionException compositionException)
{
Console.WriteLine(compositionException.ToString());
}
//Prints all the languages that were found into the application directory
var i = 0;
foreach (var language in bootStrapper.Languages)
{
Console.WriteLine("[{0}] {1} by {2}.\n\t{3}\n", language.Version, language.Name, language.Author, language.Description);
i++;
}
Console.WriteLine("It has been found {0} supported languages",i);
Console.ReadKey();
}
示例7: Initialize
/// <summary>
/// Initializes the MEF Container.
/// </summary>
/// <param name="root">The root.</param>
public static void Initialize(object root)
{
if (root == null)
throw new NullReferenceException("MEF root");
if (_instance == null) {
lock (_syncRoot) {
if (_instance == null) {
string exePath = null;
string path = null;
if (Assembly.GetEntryAssembly() != null) {
exePath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
} else {
exePath = Path.GetDirectoryName(root.GetType().Assembly.Location);
}
path = Path.Combine(exePath, "\\plugins");
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
var catalog = new AggregateCatalog();
if (path != null)
catalog.Catalogs.Add(new DirectoryCatalog(path));
if (exePath != null)
catalog.Catalogs.Add(new DirectoryCatalog(exePath));
catalog.Catalogs.Add(new AssemblyCatalog(root.GetType().Assembly));
_instance = new CompositionContainer(catalog);
_instance.ComposeParts(root);
}
}
}
}
示例8: Start
public void Start()
{
var catalog = new AggregateCatalog();
catalog.Catalogs.Add(new AssemblyCatalog(typeof(SearchDemo).Assembly));
var container = new CompositionContainer(catalog);
container.ComposeParts();
try
{
var component = container.GetExport<ITestComponent>();
if (component != null)
Console.WriteLine(component.Value.Message);
}
catch (Exception exp)
{
//Why does our call to 'GetExport' throw an exception?
//Search for the string "Test" on the container variable
//You'll find 3 instances in the Catalog.
//Then search for ITestComponent.
//You'll need to click "Search Deeper" to expand the search.
//Another way to do this is to view "container.Catalog.Parts", right click it,
//select 'Edit Filter' and enter the following predicate:
// [obj].Exports(typoef(ITestComponent)
MessageBox.Show(exp.Message, "Exception caught!");
}
}
示例9: LinkThumbnailScreenFactory
public LinkThumbnailScreenFactory(CompositionContainer compositionContainer,
Factories.ImageThumbnailScreenFactory imageThumbnailScreenFactory)
{
_imageThumbnailScreenFactory = imageThumbnailScreenFactory;
compositionContainer.ComposeParts(this);
}
示例10: Setup
public void Setup()
{
aggregateCatalog = new AggregateCatalog();
container = new CompositionContainer(aggregateCatalog);
container.ComposeParts(this);
}
示例11: Bootstrap
private void Bootstrap()
{
_jobModelRegistry = new ConcurrentDictionary<string, JobModel>();
_compositionContainer = new CatalogConfigurator()
.AddAssembly(Assembly.GetExecutingAssembly())
.AddNestedDirectory(Config.JobsFolderName)
.BuildContainer();
_compositionContainer.ComposeParts(this);
InitTasksRegistry();
_appContainerBuilder = new ContainerBuilder();
_appContainerBuilder.RegisterModule<WorkerModule>();
_appContainerBuilder.RegisterModule<HostingModule>();
_appContainer = _appContainerBuilder.Build();
//TODO: make onchanged to an event
_fileSystemWatcher = new JobsWatcher { OnChanged = OnChanged };
_fileSystemWatcher.Watch(TasksFolderPath);
_logger = _appContainer.Resolve<ILogger>();
_logger.Info("[START] PanteonEngine");
Task.Run(() => MountApi());
}
示例12: compose
private bool compose()
{
try {
var catalog = new AggregateCatalog();
catalog.Catalogs.Add(new DirectoryCatalog(@".\plugins"));
catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
var container = new CompositionContainer(catalog);
container.ComposeParts(this);
var builder = new ContainerBuilder();
builder.Register((c, p) => new JsonGopherConfigReader(gopherRepositoryManager)).As<IConfigReader>();
Container = builder.Build(Autofac.Builder.ContainerBuildOptions.Default);
return true;
} catch (CompositionException ex) {
if (Logger != null) {
Logger.ErrorException("Unable to compose", ex);
}
System.Console.WriteLine(ex);
return false;
} catch (Exception ex) {
if (Logger != null) {
Logger.ErrorException("Unable to compose", ex);
}
System.Console.WriteLine(ex);
return false;
}
}
示例13: CodeProcessorProvider
#pragma warning restore 649
private CodeProcessorProvider() {
var catalog = new AggregateCatalog();
catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
catalog.Catalogs.Add(new DirectoryCatalog("."));
var container = new CompositionContainer(catalog);
container.ComposeParts(this);
}
示例14: MyClassInitialize
public static void MyClassInitialize(TestContext testContext)
{
// set uo IoC container to use MyRootFakeData
var container = new CompositionContainer();
container.ComposeParts(new MyRootFakeData());
CslaContrib.MEF.Ioc.InjectContainer(container);
}
示例15: Run
public void Run()
{
CompositionContainer _CompositionContainer = new CompositionContainer(new ConfigExportProvider());
_CompositionContainer.ComposeParts(this);
CodeCamp.DataServerInterface.IDataServer _DataServer = DataServer;// new DataServer();
Person _Person = new Person();
Sponsor _Sponsor = new Sponsor();
_DataServer.Add<Sponsor>(_Sponsor);
_DataServer.Add<Person>(_Person);
_DataServer.Commit();
IQueryable<Sponsor> _Sponsors = _DataServer.GetTable<Sponsor>();
Console.WriteLine(_Sponsors.ToList().Count().ToString());
//
IQueryable<Person> _Persons = _DataServer.GetTable<Person>();
Console.WriteLine(_Persons.ToList().Count().ToString());
//modify a persom
string _NewName = "Changed:" + DateTime.Now.ToString();
_Persons.First().Name = _NewName;
_DataServer.Commit();
_Person = _DataServer.GetTable<Person>().Where(x => x.Name == _NewName).FirstOrDefault();
if (_Person == null)
throw new Exception("Person name not changed");
Console.WriteLine(_Person.Name);
Console.ReadLine();
}