Is it possible to do something like:
[Export(typeof(Settings)]
public static class Settings
{
public string Name {get;set;}
public string Color {get;set;}
}
[Import(typeof(Settings)]
Settings s;
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
You can’t export a static class, as there is no instance to wire up. The second line:
Would be a compiler error, as you can’t instantiate a static class.
That being said, this is really not normally necessary. MEF will automatically create a single instance (by default) of your
Settingsclass (provided it’s not static), and set that same instance to anyImportspecified. This effectively gives you a “singleton-like” class, without any of the downsides of using a static class or a singleton.