C#ServicedComponent Singleton [英] C# ServicedComponent Singleton

查看:146
本文介绍了C#ServicedComponent Singleton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我正在编写一个C#类库,可以通过non.Net

应用程序调用。此类libray的主要类是ServicedComponent

,以便non.Net应用程序可以将此类称为标准COM +

组件。现在,我希望那个班级成为一个单身人士。一旦加载,

值永远不会改变。

我尝试使用这种模式:


公共密封类Singleton

{

private static readonly Singleton instance = new Singleton();


private Singleton(){}

>
public static Singleton Instance

{

get

{

return instance;

}

}

}


然而,它会抛出一个抱怨ServicedComponent的异常

那需要一个公共构造函数。

引发的错误是:


类型未处理的异常

''系统.EnterpriseServices.RegistrationException''发生在

system.enterpriseservices.dll


附加信息:无效的ServicedComponent派生类是

在程序集中找到。

(类必须是公共的,具体的,有一个公共默认构造函数,

并且满足所有其他的Co mVisibility要求)

***通过Developersdex http://www.developersdex发送.com ***

不要只是参加USENET ......获得奖励!

解决方案



" David" <无**** @ sympatico.ca>在消息中写道

news:OB ************** @ TK2MSFTNGP15.phx.gbl ...

你好,我正在编写一个可以由非.Net
应用程序调用的C#类库。此类libray的主类是ServicedComponent
,以便non.Net应用程序可以将此类称为标准COM +
组件。现在,我希望那个班级成为一个单身人士。一旦加载,
值就不会改变。
我尝试使用这种模式:

公共密封类Singleton
{
private static readonly Singleton instance =新的Singleton();

私有Singleton(){}
公共静态单例实例
{
获取
{
返回实例;
}
}


有两种不同的种类单身人士有一种类型的

单身

然而,它抛出一个异常抱怨ServicedComponent
需要一个公共构造函数。
引发的错误是:

系统中未处理的异常
''System.EnterpriseServices.RegistrationException''发生在
system.enterpriseservices.dll

附加信息:在程序集中找到了无效的ServicedComponent派生类。
(类必须是公共的,具体的,具有公共默认构造函数,
并满足所有其他ComVisibility要求)




对。单身人士不能作为COM组件公开。最简单的修复

这是为你的COM客户发布一个外观类。


公共密封类SingletonFacade

{

public SingletonFacade(){}

public void Foo()

{

Singleton.instance.Foo() ;

}

//等

}


David


将您的组件实现为一个池化对象,其中最多/最多为1个对象在池中,并启用JITA。

不要在通话结束后忘记将SetComplete设置为true,否则你将会阻止进一步的通话。


Willy。


大卫 <无**** @ sympatico.ca>在消息中写道

news:OB ************** @ TK2MSFTNGP15.phx.gbl ...

你好,我正在编写一个可以由非.Net
应用程序调用的C#类库。此类libray的主类是ServicedComponent
,以便non.Net应用程序可以将此类称为标准COM +
组件。现在,我希望那个班级成为一个单身人士。一旦加载,
值就不会改变。
我尝试使用这种模式:

公共密封类Singleton
{
private static readonly Singleton instance =新的Singleton();

私有Singleton(){}
公共静态单例实例
{
获取
{
返回实例;
}
}

然而,它引发了一个异常,抱怨ServicedComponent
需要一个公共构造函数。
引发的错误是:

'System.EnterpriseServices.RegistrationException''未处理的异常发生在
system.enterpriseservices.dll

附加信息:在程序集中找到无效的ServicedComponent派生类。
(类必须是公共的,具体的,具有公共默认构造函数,
并满足所有其他ComVisibility要求)

***通过Developersdex发送 http://www.developersdex.com ***
不要只是参加USENET ...获得奖励!



您好!

最简单的解决方法是为您的COM发布一个Facade类



客户。


难道没有人认​​为它也是适配器类吗? (我说的是模式

这里:-)

-

venlig hilsen /关心

anders borum

-


Hello,
I''m writing a C# class library that may be called by non-.Net
applications. The main class of this class libray is a ServicedComponent
so that non-.Net application can call this class as a standard COM+
component. Now, I want that class to be a singleton. Once loaded, the
values moslty never change.
I tried using this pattern:

public sealed class Singleton
{
private static readonly Singleton instance = new Singleton();

private Singleton(){}

public static Singleton Instance
{
get
{
return instance;
}
}
}

However, it throws an exception complaining about ServicedComponent
thats needs a public constructor.
The error raised is:

An unhandled exception of type
''System.EnterpriseServices.RegistrationException'' occurred in
system.enterpriseservices.dll

Additional information: Invalid ServicedComponent-derived classes were
found in the assembly.
(Classes must be public, concrete, have a public default constructor,
and meet all other ComVisibility requirements)
*** Sent via Developersdex http://www.developersdex.com ***
Don''t just participate in USENET...get rewarded for it!

解决方案


"David" <no****@sympatico.ca> wrote in message
news:OB**************@TK2MSFTNGP15.phx.gbl...

Hello,
I''m writing a C# class library that may be called by non-.Net
applications. The main class of this class libray is a ServicedComponent
so that non-.Net application can call this class as a standard COM+
component. Now, I want that class to be a singleton. Once loaded, the
values moslty never change.
I tried using this pattern:

public sealed class Singleton
{
private static readonly Singleton instance = new Singleton();

private Singleton(){}

public static Singleton Instance
{
get
{
return instance;
}
}
}

There are two different "kinds" of singletons. There''s the kind of
singleton
However, it throws an exception complaining about ServicedComponent
thats needs a public constructor.
The error raised is:

An unhandled exception of type
''System.EnterpriseServices.RegistrationException'' occurred in
system.enterpriseservices.dll

Additional information: Invalid ServicedComponent-derived classes were
found in the assembly.
(Classes must be public, concrete, have a public default constructor,
and meet all other ComVisibility requirements)



Right. Singletons cannot be exposed as COM components. The easiest fix for
this is to publish a facade class for your COM clients.

public sealed class SingletonFacade
{
public SingletonFacade() {}
public void Foo()
{
Singleton.instance.Foo();
}
//etc
}

David


Implement your component as a pooled object with a min/max of 1 objects in
the pool and enable JITA.
Don''t forget to SetComplete to true when returning after a call else you
will block further calls.

Willy.

"David" <no****@sympatico.ca> wrote in message
news:OB**************@TK2MSFTNGP15.phx.gbl...

Hello,
I''m writing a C# class library that may be called by non-.Net
applications. The main class of this class libray is a ServicedComponent
so that non-.Net application can call this class as a standard COM+
component. Now, I want that class to be a singleton. Once loaded, the
values moslty never change.
I tried using this pattern:

public sealed class Singleton
{
private static readonly Singleton instance = new Singleton();

private Singleton(){}

public static Singleton Instance
{
get
{
return instance;
}
}
}

However, it throws an exception complaining about ServicedComponent
thats needs a public constructor.
The error raised is:

An unhandled exception of type
''System.EnterpriseServices.RegistrationException'' occurred in
system.enterpriseservices.dll

Additional information: Invalid ServicedComponent-derived classes were
found in the assembly.
(Classes must be public, concrete, have a public default constructor,
and meet all other ComVisibility requirements)
*** Sent via Developersdex http://www.developersdex.com ***
Don''t just participate in USENET...get rewarded for it!



Hello!

The easiest fix for this is to publish a facade class for your COM


clients.

Couldn''t one argue that it''s an adapter class also? (I''m talking patterns
here :-)

--
venlig hilsen / with regards
anders borum
--


这篇关于C#ServicedComponent Singleton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆