I am trying to create a WPF application that will become a central point for other applications. The main application should be able to dynamically load other applications depending on the needs of the user. After some research, MEF seems to be the solution to this problem.
I am very new to MEF, so I wrote a test application and tried to get MEF to work. The test application defines a very simple ITool interface. I was able to easily import several classes from class libraries, but I was not able to import another WPF application. Is this possible with MEF?
My main WPF application instantiates a ToolContainer that creates and composes parts.
class ToolContainer
{
[ImportMany(typeof(ITool))]
IEnumerable<Lazy<ITool>> _tools;
private CompositionContainer _container;
public ToolContainer()
{
AggregateCatalog catalog = new AggregateCatalog();
catalog.Catalogs.Add(new DirectoryCatalog(
"C:\\Application Development\\Tool Center\\Tool Extensions"));
_container = new CompositionContainer(catalog);
try
{
_container.ComposeParts(this);
}
catch (CompositionException compositionException)
{
}
}
}
public interface ITool
{
String ToolName { get; }
void OpenTool();
}
, ITool . .
[Export(typeof(ITool))]
public class Class1 : ITool
{
public String ToolName
{
get { return "....."; }
}
public void OpenTool()
{
}
}
WPF, ITool. , WPF, WPF. ITool , , . WPF App.xaml.cs :
[Export(typeof(ITool))]
public partial class App : Application, ITool
{
public String ToolName
{
get { return "Tool Sample"; }
}
public void OpenTool()
{
}
}
, _tools WPF, Class1. , ? ? .