Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: WPF C#4.0 MVVM MEF
Hi everyone,
 
I've been trying to use MEF within my applications and it's been awesome, so far. Right now, I am trying to understand how to do constructor dependency injection and I'm lost.
Let's say, I created a class called Clinic and another class called ConfigService. I use the config service to bring down some values that is required within the constructor of the Clinic class.
public Clinic([Import(typeof(IConfigService))] IConfigService configService)
{
  if (configService != null)
    Settings = new ConfigSettings(configService.GetSettings());
}
That's the constructor of the Clinic and below is the export of the ConfigService
[Export(typeof(IConfigService))]
class ConfigSettingsService : IConfigService
I have catalog defined in the App.xaml and I know if I created a property to import the an instance of Clinic, things would work smoothly.
 
My question is that, if I want to manually create an instance of Clinic in a different class (i.e. a class other than App.xaml and it's instance is not instantiated by MEF) in which I don't have a catalog. How can I do that?
 
I hope I explained the question well and please, let me know if further clarifications are needed
 
Regards
Posted 27-Sep-12 0:26am
Edited 27-Sep-12 0:29am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi guys, like the previous question I asked on CP, I solved this myself Big Grin | :-D Thanks
  Permalink  
Comments
Thomas G. Mayfield at 27-Jan-14 8:54am
   
You are creating a vacuum of information on the Internet by posting a question and then saying "there's an answer, but I'm not going to share it". Take the time. Do it right. Set aside a day or a few hours, find all your answers like this on the Internet, and fix them (either by deleting or by adding your actual solution).
CodeHawkz at 28-Jan-14 6:06am
   
How many criticisms or answers or suggestions do you see for my question? Do you see a "fool, it's not possible" or "try this way" or "your question makes no sense" or "I face the same problem. What did you do?"? I don't. So all I wanted to was to close the solution.
 
Anyways, thank you for saying this. I do agree that I did something stupid :) Thank you. I'll delete this right away. The solution is not worth the trouble

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 363
1 Sergey Alexandrovich Kryukov 286
2 RyanDev 75
3 nv3 60
4 PhilLenoir 60
0 Sergey Alexandrovich Kryukov 6,691
1 OriginalGriff 6,119
2 CPallini 2,473
3 Richard MacCutchan 1,697
4 Abhinav S 1,560


Advertise | Privacy | Mobile
Web03 | 2.8.140821.2 | Last Updated 30 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100