Singleton class in C#

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I expose a Singleton C# class to COM?

I have implemented the singleton pattern for the C# class. The 'constructor'
of the class is protected. Now, I want to expose this class to a VB6 exe. But
COM expects the default constructor of the class to be available for
instantiating it through Interop. How can I create and access the
functionality of the C# Singleton class from VB6 Exe?
 
well, 1 easiest way probably is that *do not* expose the singleton, expose
another COM/c# classes wrap around it.

hope it helps
 
Hi,

Tim said:
How can I expose a Singleton C# class to COM?

Note that the singleton you implemented is bounded to the appdomain that
created it, if you create another process (or appdomain in the same
process) you will have another instance.

I have implemented the singleton pattern for the C# class. The
'constructor'
of the class is protected. Now, I want to expose this class to a VB6 exe.
But
COM expects the default constructor of the class to be available for
instantiating it through Interop. How can I create and access the
functionality of the C# Singleton class from VB6 Exe?

You can wrap it in another class, this second class do nothing, just expose
a property that is the singleton instance.

I'm not sure if you can expose a singleton directly to COM , I have never
had that case.
 
Back
Top