本文整理汇总了C#中System.ComponentModel.Composition.Hosting.CompositionContainer.SatisfyImportsOnce方法的典型用法代码示例。如果您正苦于以下问题:C# CompositionContainer.SatisfyImportsOnce方法的具体用法?C# CompositionContainer.SatisfyImportsOnce怎么用?C# CompositionContainer.SatisfyImportsOnce使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.ComponentModel.Composition.Hosting.CompositionContainer
的用法示例。
在下文中一共展示了CompositionContainer.SatisfyImportsOnce方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadPlugins
void LoadPlugins() {
try{
var pluginsPath = Utils.MapPath("~/plugins");
if (!Directory.Exists(pluginsPath)) {
plugins = Enumerable.Empty<IPlugin>();
return;
}
var catalog = new DirectoryCatalog(pluginsPath);
var container = new CompositionContainer(catalog);
container.SatisfyImportsOnce(this);
} catch (Exception err) {
//swallow error
log.WriteError(String.Format("error during loading plugins: {0}", err.Message));
dbg.Break();
plugins = Enumerable.Empty<IPlugin>();
}
foreach (var p in plugins) {
try {
p.Init();
} catch (Exception err) {
//swallow error
log.WriteError(String.Format("error during plugin initialization: {0}", err.Message));
dbg.Break();
}
}
}
示例2: InitializePlugins
private void InitializePlugins()
{
// We look for plugins in our own assembly and in any DLLs that live next to our EXE.
// We could force all plugins to be in a "Plugins" directory, but it seems more straightforward
// to just leave everything in one directory
var builtinPlugins = new AssemblyCatalog(GetType().Assembly);
var externalPlugins = new DirectoryCatalog(AppDomain.CurrentDomain.BaseDirectory, "*.dll");
_catalog = new AggregateCatalog(builtinPlugins, externalPlugins);
_container = new CompositionContainer(_catalog);
try
{
_container.SatisfyImportsOnce(this);
}
catch (CompositionException ex)
{
if (_log.IsErrorEnabled)
{
_log.ErrorFormat("MEF Composition Exception: {0}", ex.Message);
var errors = String.Join("\n ", ex.Errors.Select(x => x.Description));
_log.ErrorFormat("Composition Errors: {0}", errors);
}
throw;
}
}
示例3: 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 ] );
}
}
示例4: Configure
/// <summary>
/// MEF Bootstrap (MEF comes from System.ComponentModel.Composition in the GAC).
/// <para>This will return a class containing all the application's aggregate roots.</para>
/// </summary>
public static ComposedDemoProgram Configure(params string[] pluginDirectories)
{
var catalogues =
pluginDirectories.Select<string, ComposablePartCatalog>(d=>new DirectoryCatalog(d)).
Concat(new []{new AssemblyCatalog(Assembly.GetExecutingAssembly())}).ToList();
var catalog = new AggregateCatalog(catalogues);
try
{
var container = new CompositionContainer(catalog);
var composedProgram = new ComposedDemoProgram();
container.SatisfyImportsOnce(composedProgram);
return composedProgram;
}
finally
{
catalog.Dispose();
foreach (var cat in catalogues)
{
cat.Dispose();
}
}
}
示例5: 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);
}
示例6: Compose
private void Compose()
{
var path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
var catalog = new DirectoryCatalog(path);
_container = new CompositionContainer(catalog);
_container.SatisfyImportsOnce(this);
}
示例7: DocumentCache
internal DocumentCache(string documentDirectoryPath, string templateDirectoryPath, TimeSpan documentLifespan)
{
if (!Directory.Exists(documentDirectoryPath))
{
throw new DirectoryNotFoundException("Could not find the document directory at \"" + documentDirectoryPath + "\".");
}
if (!Directory.Exists(templateDirectoryPath))
{
throw new DirectoryNotFoundException("Could not find the template directory at \"" + templateDirectoryPath + "\".");
}
this.documentDirectoryPath = documentDirectoryPath;
this.templateDirectoryPath = templateDirectoryPath;
this.DocumentLifespan = documentLifespan;
var catalog = new DirectoryCatalog(templateDirectoryPath);
var container = new CompositionContainer(catalog);
container.SatisfyImportsOnce(this);
if (this.DocumentTemplates.Length == 0)
{
throw new ArgumentException("Could not find any templates in the provided directory.", "templateDirectoryPath");
}
var pdfDocuments = Directory.GetFiles(documentDirectoryPath, "*.pdf");
foreach (var document in pdfDocuments)
{
var base64Hash = Path.GetFileNameWithoutExtension(document);
var hash = GetHashArray(base64Hash);
this.cachedDocuments.TryAdd(hash, new CachedDocument(document));
}
}
示例8: Initialize
public static IContainer Initialize(CompositionContainer container, bool resetSingleton)
{
Bootstrap bootStrap;
lock (_lockObject)
{ // only work on bootstrap instance in one thread at a time
if (resetSingleton || _instance == null)
{ // create and MEF initialize the bootstrap object
bootStrap = new Bootstrap();
container.SatisfyImportsOnce(bootStrap);
// store in singleton
_instance = bootStrap;
}
// use current instance
bootStrap = _instance;
}
// now initialize autofac
ContainerBuilder builder = new ContainerBuilder();
// add support for implicit collections
builder.RegisterModule(new Autofac.Modules.ImplicitCollectionSupportModule());
// add all MEF-ed modules
foreach (Module module in bootStrap.Modules)
builder.RegisterModule(module);
// create the container
return builder.Build();
}
示例9: ModuleService
public ModuleService()
{
var path = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var catalog = new DirectoryCatalog(path);
_container = new CompositionContainer(catalog);
_container.SatisfyImportsOnce(this);
}
示例10: InitializeMEF
private void InitializeMEF()
{
CompositionContainer container = new CompositionContainer(new AssemblyCatalog(GetType().Assembly));
CompositionBatch batch = new CompositionBatch();
batch.AddExportedValue(container);
container.Compose(batch);
container.SatisfyImportsOnce(this);
}
示例11: Application_Start
protected virtual void Application_Start(Object sender, EventArgs e)
{
DirectoryCatalog dirCatalog = new DirectoryCatalog(Server.MapPath("bin"),"*.dll");
AssemblyCatalog asCatalog = new AssemblyCatalog(this.GetType().Assembly);
AggregateCatalog catalog = new AggregateCatalog(dirCatalog,asCatalog);
CompositionContainer container = new CompositionContainer(catalog);
container.SatisfyImportsOnce(this);
}
示例12: DataManService
public DataManService()
{
var catalog = new AggregateCatalog();
catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
catalog.Catalogs.Add(new AssemblyCatalog(typeof(IData).Assembly));
_container = new CompositionContainer(catalog);
_container.SatisfyImportsOnce(this);
_data = Data;
}
示例13: Setup
public void Setup()
{
// See notes in TrailTest class about wiring up the repository
DirectoryCatalog repositoryCatalog = new DirectoryCatalog(@".\PlugIns");
_repositoryFactory = new RepositoryFactory();
// Now, set up the MEF container and use it to hydrate the _repositoryFactory object
_container = new CompositionContainer(repositoryCatalog);
_container.SatisfyImportsOnce(_repositoryFactory);
}
示例14: Translate
/// <summary>
/// Translate an expression.
/// </summary>
/// <param name="expr"></param>
/// <param name="cc"></param>
/// <returns></returns>
public static Expression Translate(Expression expr, IGeneratedQueryCode gc, ICodeContext cc, CompositionContainer container)
{
var tr = new ResolveToExpression() { CodeContext = cc, GeneratedCode = gc, MEFContainer = container };
if (container != null)
{
container.SatisfyImportsOnce(tr);
}
return tr.Visit(expr);
}
示例15: Initialize
public void Initialize()
{
if (Plugins == null)
{
// MEF loading of available plug-ins
var catalog = new DirectoryCatalog(".", "UUM.Plugin.*.dll");
var container = new CompositionContainer(catalog);
container.SatisfyImportsOnce(this);
}
}