Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

MEF singleton problem

$
0
0

Hi there

Cannot accomplish the simple thing: import a singleton instance of the class to the places where it is needed.

Here is my export declaration:

[PartCreationPolicy(CreationPolicy.Shared)]
    [Export]
    public class SelfScheduleMainVM : BaseController, IBroadcasting
    {...

In the class which needs it, there is an import declaration:

[Import(RequiredCreationPolicy = CreationPolicy.Shared)]
        public SelfScheduleMainVM MainVM;

and constractor of that class instantiates it:

var catalog = new AggregateCatalog();
            catalog.Catalogs.Add(new AssemblyCatalog(typeof(SelfScheduleMainVM).Assembly));
            new CompositionContainer(catalog).ComposeParts(this);

I got the instance of MainVM, but! It is the new instance, not the class which I need to be shared as a singleton.

How to fix it?

Thanks.


Viewing all articles
Browse latest Browse all 8156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>