首页 > 开发 > 综合 > 正文

IDesign C#编码规范(之十一)

2024-07-21 02:18:56
字体:
来源:转载
供稿:网友

4.7企业服务enterprise service
1.在事务方法里不要捕捉异常。要用autocomplete属性。
do not catch exceptions in a transactional method. use the autocomplete attribute.
a) see chapter 4 in com and .net component services.
2.不要调用setcomplete(), setabort(),以及相关方法。要用autocomplete属性。
do not call setcomplete(), setabort(), and the like. use the autocomplete attribute.
[transaction]
public class mycomponent : servicedcomponent
{
[autocomplete]
public void mymethod(long objectidentifier)
{
getstate(objectidentifier);
dowork();
savestate(objectidentifier);
}
}
3.总是覆写canbepooled方法并且返回true(除非你有更好的原因不用返回值到池)。
always override canbepooled and return true(unless you have a good reason not to return to pool).
public class mycomponent : servicedcomponent
{
protected override bool canbepooled()
{
return true;
}
}
4.总是在对象池里显示地调用dispose(),除非该组件已被配置为使用jita。
always call dispose() explicitly on a pooled objects unless the component is configured to use jita as well.
5.当组建使用jita时不可调用dispose()。
never call dispose() when the components uses jita.
6.总是为应用程序和组件设置权限水平。
always set authorization level to application and component.
7.将所有应用程序的检证水平设置为私有。
set authentication level to privacy on all applications.
[assembly: applicationactivation(activationoption.server)]
[assembly: applicationaccesscontrol(
true, //authorization
accesscheckslevel = accesschecksleveloption.applicationcomponent,
authentication = authenticationoption.privacy,
impersonationlevel = impersonationleveloption.identify)]
8.将客户端程序集的角色水平设置为identity。
set impersonation level on client assemblies to identity.
9.总是将可服务组件的componentaccesscontrol属性设置为true。
always set componentaccesscontrol attribute on serviced components to true.
a)the default is true
[componentaccesscontrol]
public class mycomponent : servicedcomponent
{…}
10.总是将每一个用户角色设置为marshaler。
always add to the marshaler role the everyone user.
[assembly: securerole(“marshaler”, seteveryoneaccess = true)]
11.应用securemethod属性于所有的要求检证的类。
apply securemethod attribute to all classes requiring authentication.
[securitymethod]
public class mycomponent : servicedcomponent
{…}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表