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 7070697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:35:52+00:00 2026-05-28T05:35:52+00:00

I am trying to instance a view model from my catalog when I use

  • 0

I am trying to instance a view model from my catalog

when I use Container.GetExportedValue and then initialise the properties all instances have their properties set to the value of the final value of ‘p’. but when I use a standard initialiser they are fine.

so in my example FormViewModel’s Name property in the MEF instancing example has these values

C
C
C

but in the normal instance example has these values

A
B
C

It is behaving like there is some shared reference between all instances coming from the MEF container.

      var worker = new BackgroundWorker();
        worker.DoWork += (o, ea) =>
                         {
                             _forms = new ObservableCollection<FormViewModel>(
                                 FormsExplorerRepository.GetForms()
                                     .Select(p =>
                                             {
 // This way of instancing does strange stuff 
                                                 var fvm = Container.GetExportedValue<FormViewModel>();

// This is fine but of course I'm not getting the importing constructor called
                                                 var fvm = new FormViewModel();

                                                 fvm.Workspace = this;
                                                 fvm.FormId = p.FormId;
                                                 fvm.Label = p.Label;
                                                 fvm.Name = p.Name;
                                                 fvm.Disclaimer = p.Disclaimer;
                                                 fvm.CertificationText = p.CertificationText;
                                                 fvm.Schemes = FormViewModelExtensions.InitialiseSchemes(p);
                                                 return fvm;
                                             })
                                     .ToList());
                         };

here are the view model’s constructors

    public FormViewModel()
        : base(null, true)
    {

    }

    [ImportingConstructor]
    public FormViewModel(
        IDialogManager dialogs,
        IEventAggregator events)
        : base(null, true)
    {
        _events = events;
        _events.Subscribe(this);

        _dialogs = dialogs;
    }

and I have an export attribute on the class definition

 [Export(typeof(FormViewModel)), PartCreationPolicy(CreationPolicy.NonShared)]
public class FormViewModel 

I hope there is enough info here for someone to help

  • 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-05-28T05:35:52+00:00Added an answer on May 28, 2026 at 5:35 am

    I found my error

    I wasn’t using the right syntax in my AddExportedValue (the one I commented out here was the wrong way)

    (container, batch) =>
    {
        // batch.AddExportedValue(new FormViewModel());
        batch.AddExportedValue<Func<FormViewModel>>container.GetExportedValue<FormViewModel>);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use instance variable in Perl OO -
In my MVC application I have a problem with passing data from view to
I have recently started learning wpf and am trying to use mvvm. My understanding
I am trying to create a multi step form using model classes: my view:
I am trying to use a textarea form entry which I have some javascript
I'm trying to pass my View an instance of the following ViewModel: public class
I have a view model sent to the edit action of my controller. The
I'm still on this view. Now I have a ValidationError while trying to save
I am trying to figure out how to pass the model object from controller
I’m trying to create an instance of: java.awt.geom.Point2D.Double in ColdFusion. Point2D.Double is a nested

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.