Importing from referenced assembly - MEF
Posted
by cmaduro
on Stack Overflow
See other posts from Stack Overflow
or by cmaduro
Published on 2010-05-14T20:03:03Z
Indexed on
2010/05/14
20:34 UTC
Read the original article
Hit count: 314
MEF
|Silverlight
I have the following simplified code:
namespace Silverbits.Applications
{
public partial class SilverbitsApplication : Application
{
[Import("MainPage")]
public UserControl MainPage
{
get { return RootVisual as UserControl; }
set { RootVisual = value; }
}
public SilverbitsApplication()
{
this.Startup += this.SilverbitsApplication_StartUp;
this.Exit += new EventHandler(SilverbitsApplication_Exit);
this.UnhandledException += this.SilverbitsApplication_UnhandledException;
InitializeComponent();
}
private void SilverbitsApplication_StartUp(object sender, StartupEventArgs e)
{
CompositionInitializer.SatisfyImports(this);
}
}
namespace Manpower4U
{
public class App : SilverbitsApplication
{
public App() : base()
{
}
}
}
namespace Manpower4U
{
[Export("MainPage")]
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
}
}
}
The idea is that I have a Silverbits Library which is a completely different solution. And I have Manpower4U silverlight application that references my Silverbits library.
I want to export MainPage from Manpower4U and set it to the RootVisual in my SilverbitsApplication class.
SilverbitsApplication class is basically App.xaml/App.cs from the silverlight application, only I put it in a class library and subclassed App.cs file in Manpower4U, which is now the entry point of Manpower4U.
MEF cannot resolve the import. How do I get this to work?
© Stack Overflow or respective owner