c# - MEF creation policy -
I'm trying to use building policy shared part of a MEF export. This, however, was thinking I did not seem to work the way I structure my application twice and every time I get a new copy of the object. I have proven this by adding an example counter for the object instanciation
constant int instount = 0; Public FakeAutocompleteRepository () {instcount ++; ...} And it is actually the second time running debug all I get a new copy of FakeAutocompleteRepository with having a composition instCount = 2. No export section
< pre> [PartCreationPolicy (CreationPolicy.Shared)] [export (typeof (IAutocompleteRepository))] [ExportMetadata ( "IsTesting", "true")] class FakeAutocompleteRepository: IAutocompleteRepository {...} < / Pre> Is there some trick to getting the same example for the subsiquent requests? If it is something that I have is that I do this if I'm in the structure
var catalog = new aggregateCatalog (); Catalog.Catalogs.Add (New Assembly (System. Reflection.Assembly.GetExecutingAssembly ())); Catalog.Catalogs.Add (new directory (".");); Var container = new composite (catalog); Var batch = new composition batch (); Batch.AddPart (this); Container.Compose (batch); If (null = ConfigurationSettings.AppSettings [ "IsTesting"] & amp ;! & amp; bool.Parse (ConfigurationSettings.AppSettings [ "IsTesting"])) stores = container.GetExports & LT; IAutocompleteRepository & gt; () Where (expDef = & gt ;. expDef. Metadata.Keys.Contains ( "IsTesting")) Single () GetExportedObject () .. Actually I am trying to implement a specific composition during the trial. If you have a better idea for testing these creations, then I am all ears
I have special As it was created in your code nothing is going to happen that would have more than one reason on your part. Are you making a separate container for each structure? If you are, that is why you are getting different examples.
As far as how to combine the structure and unit testing in general, there is some discussion of this.
Comments
Post a Comment