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
{…}