Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8526875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:23:48+00:00 2026-06-11T08:23:48+00:00

Here’s the situation I have 2 singleton classes (ViewModels in fact). [Export] [PartCreationPolicy(CreationPolicy.Shared)] public

  • 0

Here’s the situation

I have 2 singleton classes (ViewModels in fact).

[Export]
[PartCreationPolicy(CreationPolicy.Shared)]
public class CompanyViewModel, INavigationAware
{
   private Model.Company _selected;

   [ImportingConstructor]
   public CompanyViewModel(Service.ICompany companyService)
   {
      Companies = companyService.Companies;       
   }

   [Export("SelectedCompany")]
   public Model.Company Selected
   {
      get
      {
         return _selected;
      }
      set
      {
         _selected = value;
      }
   }

   public ObservableCollection<Model.Company> Companies{get;set;}

   public void OnNavigatedTo(NavigationContext navigationContext)
   {
      _selected = Companies.First();
   }
   ~~~
}

The companyService returns with 2 companies “A” and “B”. “A” is set as the selected company when the class CompanyViewModel is navigated to. The user then selects company “B” and CompanyViewModel is updated via it’s binding.

[Export]
[PartCreationPolicy(CreationPolicy.Shared)]    
public class DepartmentViewModel, INavigationAware
{
   [Import("SelectedCompany")]
   private Model.Company _selectedCompany{get;set;};

   [ImportingConstructor]
   public DepartmentViewModel(Service.IDeparment departmentService)
   {
      Departments= departmentService.Departments;
   }

   public ObservableCollection<Model.Department> Departments{get;set;}

   public void OnNavigatedTo(NavigationContext navigationContext)
   {
      this.departmentService.Refresh(_selectedCompany);
   }
   ~~~
}

After the events described above the DepartmentViewModel is created. The problem is the company property in the DepartmentViewModel is set to company “A” not company “B” as I would of expected, as I thought MEF would import the last value Selected was set to (before creation of DepartmentViewModel) not the first value it was set to.

Can someone tell me what’s actually going on?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T08:23:50+00:00Added an answer on June 11, 2026 at 8:23 am

    I believe you use MEF not as it is designed. MEF is not for “bindings” as you try to use it. MEF is for creating composition applications.

    In your case the problem is that MEF doesn’t update part registration for SelectedCompany after creation of CompanyViewModel. This is why it returns A always.

    Use another approach – create separate DepartmentViewModel for each Company, or update it accordingly to selected company. Don’t use MEF for that – use MEF only as “container that initialize your application once, during its startup”.

    PS. Actually, I never saw before usage of Export attribute for properties.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's the view: @if (stream.StreamSourceId == 1) { <img class=source src=@Url.Content(~/Public/assets/images/own3dlogo.png) alt= /> }
Here is my class: public class A{ private void doIt(int[] X, int[] Y){ //change
Here is the Javascript I currently have <script type=text/javascript> $(function() { $('.slideshow').hover( function() {
Here's the basic setup: I have a thin bar at the top of a
Here is my problem : I have a post controller with the action create.
Here is an example: I have the generic type called Account. I wish to
Here is the problem that I am trying to solve. I have two folders
Here's the situation: void funct( unsigned u, double d, float f ) { u
Here's my button element: <button type=submit class=btn-submit><span><strong>Let Me In, please!</strong></span></button> and here's the CSS:
Here is my code...I have two dimensional matrices A,B. I want to develop the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.