This project is read-only.

Unable to use property import

Jun 30, 2011 at 5:50 PM

I am using MefedMVVM in my application, but I have problem with the Import.

    [Import (typeof(IUserServices ))]
public IUserServices UserService { get; private set; }

This does not work and UserService is always null.

But using the ImportContstructor in the same class works perfectly:

    [ImportingConstructor ]
public MainWindowVM(
IUIVisualizerService uiVisualizer,
IViewAwareStatus viewAwareStatus,
IMessageBoxService messageBoxService,
IManager mwManager,
TagItemModel tagModel,
ILibraryModel  documentModel,
ILibraryServices libraryServices,
ILogServices logServices ,
IUserServices userServices)

I'm using the following code for export:
    [ExportService(ServiceType.Both, typeof(IUserServices))]
    public class TestUserServices:IUserServices 
        public void GetSettings(Action<HubSettingsException> callback)
            var dPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase).Remove(0, 6),"DataContainer");
            callback(new HubSettings {DataPath = dPath}, null);

Can anybody help me in the issue. I already spend hours, but did not find any solution. Thanks!!!

Jul 22, 2011 at 2:21 PM
Edited Jul 22, 2011 at 2:25 PM

There are multiple paths to try...

If you have a decompiler, you can skip steps 1 & 2.

  1. Download MefedMVVM source.
  2. Reference the MefedMVVM project (not the built DLL).
  3. Put a debug breakpoint where the MEF container is being built. (I'd start in ViewModelRepoitory.cs, in TrySatisfyImports().)
  4. Drill down to see the container's imports/exports.

Try MEF diagnostics.

Isolate the issue...

  1. Create a basic Console project.
  2. Create a class named "MainWindowVM" with only the IUserServices userServices parameter.
  3. Create a a TestUserServices:IUserServices class with same signatures (just don't do anything in the method).
  4. Ensure and test that the [ImportingConstructor] still works.
  5. Now test the property import.  Try different combinations of [ImportAttribute] constructors.
Aug 15, 2011 at 4:59 PM
Edited Aug 15, 2011 at 5:02 PM

I have the same problem as mrskynavi

property import doesnt work.

Does somobody know why?

Aug 16, 2011 at 2:35 PM

Can you please check your output winodw to see if you have any composition errors... are there any exceptions ?