Singleton class in C#

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?
 
G

Guest

well, 1 easiest way probably is that *do not* expose the singleton, expose
another COM/c# classes wrap around it.

hope it helps
 
I

Ignacio Machin \( .NET/ C# MVP \)

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top