Quantcast
Channel: Managed Extensibility Framework
Viewing all articles
Browse latest Browse all 265

New Post: Is there a way to tell if MEF created a instace for a Type I exported

$
0
0
My goal is to find any of my viewmodels that are dirty and when they exit the app , I should let them notify.

I can get to an instance based on type by below code but problem is its going to create instances for all view models as I am only interested in the ones which were already created by MEF container
List<Type> viewModelInterfaces = new List<Type>();
    viewModelInterfaces .Add(typeof(IAddressViewModel));
    viewModelInterfaces .Add(typeof(ICustomerNameViewModel));
    viewModelInterfaces .Add(typeof(IBudgetSummaryViewModel));

    foreach (var appInterface in viewModelInterfaces )
    {
        var obj = Container.GetExports(appInterface, ull,appInterface.FullName).FirstOrDefault();
        if (obj != null)
        {
            var viewModel = obj.Value as IViewModelBase;
            if (viewModel != null)
            {
                if (viewModel.IsDirty)
                {
                    Show Dialog
                }
            }
         }
     }

Viewing all articles
Browse latest Browse all 265

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>