Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static int instCount = 0;
- public FakeAutocompleteRepository()
- {
- instCount++;
- ...
- }
- [PartCreationPolicy(CreationPolicy.Shared)]
- [Export(typeof(IAutocompleteRepository))]
- [ExportMetadata("IsTesting", "True")]
- class FakeAutocompleteRepository : IAutocompleteRepository
- { ... }
- var catalog = new AggregateCatalog();
- catalog.Catalogs.Add(new AssemblyCatalog(System.Reflection.Assembly.GetExecutingAssembly()));
- catalog.Catalogs.Add(new DirectoryCatalog("."));
- var container = new CompositionContainer(catalog);
- var batch = new CompositionBatch();
- batch.AddPart(this);
- container.Compose(batch);
- if (null != ConfigurationSettings.AppSettings["IsTesting"] && bool.Parse(ConfigurationSettings.AppSettings["IsTesting"]))
- repository = container.GetExports<IAutocompleteRepository>().Where(expDef => expDef.Metadata.Keys.Contains("IsTesting")).Single().GetExportedObject();
- [Export("/MyViewModel")]
- public class MyViewModel
- {
- [ImportingConstructor]
- public MyViewModel(
- [Import("/Services/LoggingService")] ILoggingService l)
- {
- logger = l;
- }
- private ILoggingService logger { get; set; }
- /* ... */
- }
- MyViewModel target = new MyViewModel(new MockLoggingService());
Add Comment
Please, Sign In to add comment