MEF and MVVM - way to add conventions?
Is there a way to hook into the internals of CompositionContainer?
For example, let's say any time an import is called on a export ending with the word "View" I might want to inject an export ending with "ViewModel" into its DataContext.
Is there a 开发者_高级运维way to do that? I'm trying to avoid code like this in every View:
[Export("MainView")]
public partial class MainView : Window
{
[ImportingConstructor]
public MainView([Import("MainViewModel")] dynamic viewModel)
{
InitializeComponent();
DataContext = viewModel;
}
}
Would be nice to simplify to just this, and use conventions:
[Export("MainView")]
public partial class MainView : Window
{
public MainView()
{
InitializeComponent();
}
}
There are some folks working on this, including the Mef team apparently :) Here is a blog post you might find interesting:
http://thecodejunkie.com/2010/03/bringing-convention-based-registration.html
And here is another slightly less detailed one:
http://blogs.msdn.com/b/hammett/archive/2011/03/08/mef-s-convention-model.aspx
I Guess you are looking for a library or framework which can reduce your effort.
Please have a look at library WPF Application framework. I am using it very well.
精彩评论