[de] Singleton bei Verwendung von .RegisterComponents (solved)

Topics: Technical Support
May 16, 2013 at 9:51 AM
Ich verwende die Implementierung von MEF laut dem Vorschlag von https://zyan.codeplex.com/discussions/439268. Leider wird bei jedem Client-Zugriff scheinbar eine neue Server-Instanz erzeugt.

Wie kann ich das verhindern? Wie setze ich das "Singleton" Attribut?
Coordinator
May 16, 2013 at 4:13 PM
Edited May 16, 2013 at 4:16 PM
Hi!

MEF integration relies on standard MEF attributes, located in System.ComponentModel.Composition namespace.
PartCreationPolicyAttribute(CreationPolicy.Shared) will do the trick:
// this component will work as a singleton (one instance per composition container)
[ZyanComponent(typeof(ISampleService)), PartCreationPolicy(CreationPolicy.Shared)]
internal class MySampleService : ISampleService
May 17, 2013 at 6:23 AM
Edited May 17, 2013 at 7:52 AM
HI yallie

Thank you for you reply.

It works fine