本文整理汇总了C#中System.ComponentModel.Composition.Hosting.CompositionContainer.Compose方法的典型用法代码示例。如果您正苦于以下问题:C# CompositionContainer.Compose方法的具体用法?C# CompositionContainer.Compose怎么用?C# CompositionContainer.Compose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.ComponentModel.Composition.Hosting.CompositionContainer
的用法示例。
在下文中一共展示了CompositionContainer.Compose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnStartup
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
#if (DEBUG != true)
// Don't handle the exceptions in Debug mode because otherwise the Debugger wouldn't
// jump into the code when an exception occurs.
DispatcherUnhandledException += AppDispatcherUnhandledException;
AppDomain.CurrentDomain.UnhandledException += AppDomainUnhandledException;
#endif
XmlConfigurator.Configure();
_log.Debug("OnStartup called");
var catalog = new AggregateCatalog();
catalog.Catalogs.Add(new AssemblyCatalog(typeof(Controller).Assembly));
catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
catalog.Catalogs.Add(new AssemblyCatalog(typeof(IApplicationController).Assembly));
catalog.Catalogs.Add(new AssemblyCatalog(typeof(ValidationModel).Assembly));
_container = new CompositionContainer(catalog);
var batch = new CompositionBatch();
batch.AddExportedValue(_container);
_container.Compose(batch);
_controller = _container.GetExportedValue<IApplicationController>();
_controller.Initialize();
_controller.Run();
}
示例2: Compose
private bool Compose()
{
var catalog = new AggregateCatalog();
catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
//catalog.Catalogs.Add(new AssemblyCatalog(typeof(IEmailService).Assembly));
_container = new CompositionContainer(catalog);
var batch = new CompositionBatch();
batch.AddPart(this);
#if DEBUG
_container.Compose(batch);
#else
try
{
_container.Compose(batch);
}
catch (CompositionException compositionException)
{
MessageBox.Show(compositionException.ToString());
Shutdown(1);
return false;
}
#endif
return true;
}
示例3: 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);
}
示例4: ComposeWithTypesExportedFromPythonAndCSharp
public void ComposeWithTypesExportedFromPythonAndCSharp(
object compositionTarget,
string scriptsToImport,
params Type[] typesToImport)
{
ScriptSource script;
var engine = Python.CreateEngine();
using (var scriptStream = GetType().Assembly.
GetManifestResourceStream(GetType(), scriptsToImport))
using (var scriptText = new StreamReader(scriptStream))
{
script = engine.CreateScriptSourceFromString(scriptText.ReadToEnd());
}
var typeExtractor = new ExtractTypesFromScript(engine);
var exports = typeExtractor.GetPartsFromScript(script, typesToImport).ToList();
var catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
var container = new CompositionContainer(catalog);
var batch = new CompositionBatch(exports, new ComposablePart[] { });
container.Compose(batch);
container.SatisfyImportsOnce(compositionTarget);
}
示例5: GetMefContainer
public static CompositionContainer GetMefContainer(string binDirPath, CompositionBatch batch = null, RegistrationBuilder builder = null)
{
if (builder == null)
builder = new RegistrationBuilder();
builder.ForTypesDerivedFrom<Controller>()
.SetCreationPolicy(CreationPolicy.NonShared).Export();
builder.ForTypesDerivedFrom<ApiController>()
.SetCreationPolicy(CreationPolicy.NonShared).Export();
var catalogs = new DirectoryCatalog(binDirPath, builder);
var container = new CompositionContainer(catalogs, CompositionOptions.DisableSilentRejection |
CompositionOptions.IsThreadSafe);
if (batch == null)
batch = new CompositionBatch();
// make container availalbe for di
batch.AddExportedValue(container);
container.Compose(batch);
return container;
}
示例6: OnStartup
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
DispatcherUnhandledException += AppDispatcherUnhandledException;
AppDomain.CurrentDomain.UnhandledException += AppDomainUnhandledException;
catalog = new AggregateCatalog();
// Add the WpfApplicationFramework assembly to the catalog
catalog.Catalogs.Add(new AssemblyCatalog(typeof(IMessageService).Assembly));
// Load module assemblies as well. See App.config file.
foreach (string moduleAssembly in Settings.Default.ModuleAssemblies)
{
catalog.Catalogs.Add(new AssemblyCatalog(moduleAssembly));
}
container = new CompositionContainer(catalog, CompositionOptions.DisableSilentRejection);
CompositionBatch batch = new CompositionBatch();
batch.AddExportedValue(container);
container.Compose(batch);
// Initialize all presentation services
var presentationServices = container.GetExportedValues<IPresentationService>();
foreach (var presentationService in presentationServices) { presentationService.Initialize(); }
// Initialize and run all module controllers
moduleControllers = container.GetExportedValues<IModuleController>();
foreach (var moduleController in moduleControllers) { moduleController.Initialize(); }
foreach (var moduleController in moduleControllers) { moduleController.Run(); }
}
示例7: 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);
}
示例8: OnStartup
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
#if (DEBUG != true)
// Don't handle the exceptions in Debug mode because otherwise the Debugger wouldn't
// jump into the code when an exception occurs.
DispatcherUnhandledException += AppDispatcherUnhandledException;
AppDomain.CurrentDomain.UnhandledException += AppDomainUnhandledException;
#endif
catalog = new AggregateCatalog();
// Add the WpfApplicationFramework assembly to the catalog
catalog.Catalogs.Add(new AssemblyCatalog(typeof(Controller).Assembly));
// Load module assemblies as well. See App.config file.
foreach (string moduleAssembly in Settings.Default.ModuleAssemblies)
{
catalog.Catalogs.Add(new AssemblyCatalog(moduleAssembly));
}
container = new CompositionContainer(catalog);
CompositionBatch batch = new CompositionBatch();
batch.AddExportedValue(container);
container.Compose(batch);
// Initialize all presentation services
var presentationServices = container.GetExportedValues<IPresentationService>();
foreach (var presentationService in presentationServices) { presentationService.Initialize(); }
// Initialize and run all module controllers
moduleControllers = container.GetExportedValues<IModuleController>();
foreach (var moduleController in moduleControllers) { moduleController.Initialize(); }
foreach (var moduleController in moduleControllers) { moduleController.Run(); }
}
示例9: OnStartup
protected override void OnStartup( StartupEventArgs e )
{
base.OnStartup( e );
new UnhandledExceptionHook( this );
Application.Current.Exit += OnShutdown;
var catalog = new AssemblyCatalog( GetType().Assembly );
myContainer = new CompositionContainer( catalog, CompositionOptions.DisableSilentRejection );
myContainer.Compose( new CompositionBatch() );
var shell = myContainer.GetExportedValue<Shell>();
myContainer.SatisfyImportsOnce( shell.myDesigner );
( ( Shell )MainWindow ).myProperties.DataContext = shell.myDesigner.SelectionService;
Application.Current.MainWindow = shell;
Application.Current.MainWindow.Show();
var args = Environment.GetCommandLineArgs();
if( args.Length == 2 )
{
shell.myDesigner.Open( args[ 1 ] );
}
}
示例10: ConventionCatalog_should_support_type_exports
public void ConventionCatalog_should_support_type_exports()
{
var registry = new PartRegistry();
registry.TypeScanner = new AssemblyTypeScanner(Assembly.GetExecutingAssembly());
registry
.Part()
.ForType<SampleExport>()
.Export();
var catalog =
new ConventionCatalog(registry);
var instance =
new ConventionPart<SampleExport>();
var batch =
new CompositionBatch();
batch.AddPart(instance);
var container =
new CompositionContainer(catalog);
container.Compose(batch);
instance.Imports.Count().ShouldEqual(1);
}
示例11: DualContainers
public void DualContainers()
{
var container1 = new CompositionContainer();
TypeDescriptorServices dat1 = new TypeDescriptorServices();
CompositionBatch batch = new CompositionBatch();
batch.AddPart(dat1);
container1.Compose(batch);
MetadataStore.AddAttribute(
typeof(DynamicMetadataTestClass),
( type, attributes) =>
Enumerable.Concat(
attributes,
new Attribute[] { new TypeConverterAttribute(typeof(DynamicMetadataTestClassConverter)) }
),
container1
);
var container2 = new CompositionContainer();
CompositionBatch batch2 = new CompositionBatch();
TypeDescriptorServices dat2 = new TypeDescriptorServices();
batch2.AddPart(dat2);
container2.Compose(batch2);
DynamicMetadataTestClass val = DynamicMetadataTestClass.Get("42");
var attached1 = dat1.GetConverter(val.GetType());
Assert.IsTrue(attached1.CanConvertFrom(typeof(string)), "The new type converter for DynamicMetadataTestClass should support round tripping");
var attached2 = dat2.GetConverter(val.GetType());
Assert.IsFalse(attached2.CanConvertFrom(typeof(string)), "The default type converter for DynamicMetadataTestClass shouldn't support round tripping");
}
示例12: Compose
private void Compose()
{
var container = new CompositionContainer(directories);
var batch = new CompositionBatch();
batch.AddPart(this);
container.Compose(batch);
}
示例13: Compose
public void Compose(BaseParameters parameters)
{
try
{
var catalog = new AggregateCatalog(new AssemblyCatalog(Assembly.GetExecutingAssembly()),
new AssemblyCatalog(typeof(Logic.SanityCheck).Assembly));
LoadPlugins(catalog, parameters);
var container = new CompositionContainer(catalog);
var batch = new CompositionBatch();
batch.AddPart(this);
batch.AddPart(parameters);
var config = new Configuration(parameters.FileSystem, parameters.Path);
config.ReadFromFile();
batch.AddExportedValue((IConfiguration)config);
container.Compose(batch);
}
catch (ReflectionTypeLoadException ex)
{
Console.WriteLine(@"Unable to load: \r\n{0}",
string.Join("\r\n", ex.LoaderExceptions.Select(e => e.Message)));
throw;
}
}
示例14: Compose
public void Compose()
{
AssemblyCatalog assemblyCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
string executionPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string generatorsPath = Path.Combine(executionPath, "Generators");
CreatePathIfRequied(generatorsPath);
generatorsCatalog = new DirectoryCatalog(generatorsPath);
string uiPath = Path.Combine(executionPath, "UI");
CreatePathIfRequied(uiPath);
UICatalog = new DirectoryCatalog(uiPath);
AggregateCatalog catalog = new AggregateCatalog();
catalog.Catalogs.Add(generatorsCatalog);
catalog.Catalogs.Add(UICatalog);
//Set the defaults....
CatalogExportProvider mainProvider = new CatalogExportProvider(assemblyCatalog);
CompositionContainer container = new CompositionContainer(catalog, mainProvider);
mainProvider.SourceProvider = container;
var batch = new CompositionBatch();
batch.AddPart(this);
RefreshCatalog refreshCatalog = new RefreshCatalog(generatorsCatalog, UICatalog);
container.ComposeParts(refreshCatalog);
container.Compose(batch);
Logger.Write("Compose complete");
}
示例15: Compose
private bool Compose()
{
var catalog = new System.ComponentModel.Composition.Hosting.AggregateCatalog();
// var catalog = new AggregatingComposablePartCatalog();
catalog.Catalogs.Add(
new RubyCatalog(new RubyPartFile("calculator_ops.rb")));
catalog.Catalogs.Add(
new AssemblyCatalog(Assembly.GetExecutingAssembly()));
_container = new System.ComponentModel.Composition.Hosting.CompositionContainer(catalog);
//_container. AddPart(this);
var batch = new System.ComponentModel.Composition.Hosting.CompositionBatch();
batch.AddPart(this);
//_container.AddPart(this);
//_container.Compose(this);
try
{
_container.Compose(batch);
}
catch (CompositionException compositionException)
{
MessageBox.Show(compositionException.ToString());
return false;
}
return true;
}