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

编码|规范

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

时间: 2024-10-31 21:25:59

IDesign C#编码规范(之十一)的相关文章

IDesign C#编码规范(之三)

编码|规范 续之二,IDesign C#编码规范之三. 34. 避免使用new继承修饰符,而是使用override. Avoid using the new inheritance qualifier. Use override instead. 35. 对非密封类总是将public和protected方法标记为virtual. Always mark public and protected methods as virtual in a non sealed class. 36. 除非涉及到

IDesign C#编码规范(总结)

编码|规范 5资源 Resource5.1 Programming .NET Components By Juval Lowy, O'Reilly 2003 ISBN: 05960034715.2 The .NET Master Class Authored by Juval Lowy, this world acclaimed intense class covers everything, from .NET essentials to the application frameworks

IDesign C#编码规范(之五)

编码|规范 续四,休息天翻得很少,不过总算在keep doing,:-) 4 Framework特别指导 Framework Specific Guidelines 4.1 数据访问 Data Access 1. 总是使用类型安全的数据集或者数据表.避免使用原始的ADO.NET. Always use type-safe data sets or data tables . Avoid raw ADO.NET. 2. 访问数据库时总是使用事务. Always use transactions w

IDesign C#编码规范(之九)

编码|规范 4.5远程操作 Remoting1.宁可使用管理配置(配置文件)而不使用程序自动配置.Prefer administrator configuration to programmatic configation.2.总是在单独调用对象里完成IDisposable.Always implement IDisposable on single call objects.3.远程操作时总是选用TCP信道和二进制格式Always prefer TCP channel and binary f

IDesign C#编码规范(之十)

编码|规范 4.6安全 Security1.总是使用强名称发布代码,该名称对于该应用程序而言是私有的,对于你是公有的.Always demand your own strong name on assemblies and components that are private to the application, but are public(so that only you use them).public class PublicKeys{public const string MyCo

IDesign C#编码规范(之六)

编码|规范 大家中秋好,首先非常感谢xiaxia翻译的资料.由于我对这个文档也是兴趣浓厚,所以就把下面的部分给翻译了.希望大家多多指教. 4.2ASP.NET and Web Services1.避免将代码放入ASP.NET的ASPX文件中. 所有的代码都应该放在相关代码的Partial类中.Avoid putting code in ASPX files of ASP.NET. All code should be in the code beside partial class.2.放在相关

IDesign C#编码规范(之七)

编码|规范 4.3序列化 Serialization1.总是标记未封装的类为[Serializable]Always mark non-sealed classes as serializable.2.总是标记未序列化的成员变量为[non-serializable]Always mark un-serializable member variables as non-serializable.3.总是标记序列化类中的委托为[NonSerialized]Always mark delegates

IDesign C#编码规范(之八)

编码|规范 4.4多线程 Multithreading1.应用同步机制空间.Use Synchronization Domains. See Chapter 8 in Programming .NET Components.避免手工的同步机制,应为这样容易导致死锁和竞态条件.a) Avoid manual synchronization because that often leads to deadlocks and race conditions.2.永远不要在外部调用你的同步机制空间.Ne

VB.NET/ASP.NET编码规范(ZT)

asp.net|编码|规范 在开发中保持良好的编码规范是十分重要的.我所采用的新的VB.NET/ASP.NET编码规范,是一种被证明能明显改善代码可读性,并有助于代码管理.分类的编码规范.采用这种编码规范,能避免如匈牙利命名法带来的繁长前缀,便于记忆变量的用途.下面的介绍这种编码规范. 一.类型级单位的命名 1.类 □以Class声明的类,都必须以名词或名词短语命名,体现类的作用.如: Class Indicator□当类是一个特性(Attribute)时,以Attribute结尾,当类是一个异