locked
Is it possible to load execute file(*.exe) by MEF RRS feed

  • Question

  • Dear Everyone.

    i have read MEF, but Is it possible to load exeute file?


    i have attached a  code below?

    when i usedAppDomain to load execute file, AppDomain can load exeute file, but not safety for thread.

    so i want to text that by MEF

    could you give me sample code for me?

    using System; using System.Linq; using System.ComponentModel.Composition; using System.Reflection; using System.Collections.Generic; using SharedLibrary; class Program { [Import] public IEnumerable<string> Messages { get; set; } [Import] public IEnumerable<IOutputString> OutputSet { get; set; } [Import("OutputMessages")] public Action<IEnumerable<IOutputString>, IEnumerable<string>> OutputMessages { get; set; } public void Run() { var catalog = new AggregatingComposablePartCatalog(); // catalog.Catalogs.Add (new DirectoryPartCatalog(@"..\..\..\ExternalMessages\bin\Debug")); catalog.Catalogs.Add(new DirectoryPartCatalog(@"..\..\..\ExtraMessages","*.exe",true)); catalog.Catalogs.Add (new AttributedAssemblyPartCatalog(Assembly.GetExecutingAssembly())); var container = new CompositionContainer(catalog.CreateResolver()); container.AddPart(this); container.Compose(); OutputMessages(OutputSet, Messages); } static void Main(string[] args) { Program p = new Program(); p.Run(); } } [Export(typeof(IOutputString))] public class ReverseOutputter : IOutputString { public void OutputByOutputType(IEnumerable<IOutputString> outputSet, IEnumerable<string> messages) { foreach (var Out in outputSet) { foreach (var s in messages) { Out.OutputString(s); } } Console.ReadKey(); } [Export("OutputMessages")] public void OutputByMessage(IEnumerable<IOutputString> outputSet, IEnumerable<string> messages) { foreach (var s in messages) { foreach (var Out in outputSet) { Out.OutputString(s); } } Console.ReadKey(); } public void OutputString(string value) { var saved = Console.ForegroundColor; foreach (var s in value.Split().Reverse()) { Console.ForegroundColor = (ConsoleColor)(s.Length % 10); Console.Write(s + " "); } Console.ForegroundColor = saved; Console.WriteLine(); } } public class SimpleHello { [Export] public string Message { get { return "hello world!!"; } } } public class MoreMessages { [Export] public string FunMessage { get { return "This is getting fun!"; } } }



    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using SharedLibrary;
    using System.ComponentModel.Composition;
    
    
    namespace ExternalMessageExe
    {
       
        class Program 
        {
            static void Main(string[] args)
            {
            }
    
           
        }
        [Export(typeof(IOutputString))]
        class ExternameMessageEx : IOutputString
        {
            public void OutputString(string value)
            {
                Console.WriteLine("[EXE] Output=" + value);
            }
    
            [Export]
            public string Message
            {
                get
                {
                    return "[EXE]I am starting to get it...";
                }
            }
        }
    }
    

    lightdoll
    Tuesday, March 9, 2010 7:46 AM

All replies