Application Architecture Guide 2.0 学习笔记(一)前言 - Atchitecture Frame

 Architecture Frame

The following guidelines will help you to understand the fundamental cross-cutting factors you must consider when designing your chosen application type. Use these guidelines as a starting point toward understanding how to think about key functionality that cuts across layers and tiers. For example, your exception-management strategy should be designed to be consistent across your entire application, and not with just a single layer in mind.(下面的指导将帮助你理解一些你在设计选定的应用程序类型时必须考虑的跨域因素)


• How to design your exception-management strategy(如何设计异常管理策略)


Use structured exception handling to build robust code(使用结构化的异常处理来建立强壮的代码). Use exceptions instead of error codes where possible(在可能的情况下都使用异常处理而不是错误代码). Do not reveal internal system or application details, such as stack traces, SQL statement fragments, and so on(不要暴露内部系统或应用的细节,例如堆栈信息、SQL语句片段等). Ensure that this type of information is not allowed to propagate to the end user, or beyond your current trust boundary(确保这些类型的信息不允许被传递给最终用户). Fail securely in the event of an exception, and make sure that your application denies access and is not left in an insecure state(在发生异常时要能安全地失效,并要确保你的应用拒绝访问且不要停留在一个不安全的状态). Use finally blocks to guarantee that resources are cleaned up when exceptions occur(使用finally块,保证在发生异常时所用到的资源会被清理。); for example, close your database connections in a finally block(例如,在finally块中关闭数据库连接). Do not log sensitive or private data such as passwords, which could be compromised(不要记录敏感信息与私人信息,例如密码,这些信息不能受到危害). When the exception contains user input in the exception message, ensure that you sanitize and validate it(当异常信息包含用户输入的时候,确信你清理并验证过它); for example, if you return an HTML error message, you should encode the output to avoid script injection(例如,如果你返回一个HTML错误信息,你就应该将它编码来避免脚本注入).


For more information, see Chapter 3, “Architecture and Design Guidelines.”


• How to instrument your application(如何instrument 应用)


Instrumentation is used when you have a specific problem and you need additional information in order to solve that problem(当你有一个特殊的问题并需要额外的信息来解决这个问题是,可以使用Instrumentation ). This could be a debugging issue, a performance issue, a security issue, a manageability issue, and so on(这可能是一个调试问题、性能问题、安全问题、可管理性问题等等). This is different than logging in that logging is a general approach to pushing information into log files that might need to be audited in the future, versus a targeted approach to get information for a specific problem(与日志不同的是,日志是一种通用方法,它将信息存放到日志文件中以便将来需要用来审查,与此相对,Instrumentation 是一个为解决特定问题的针对性方法).  Options for instrumentation include event tracing for Microsoft® Windows®, trace and debug classes, custom performance counters, and Windows Management Instrumentation (WMI)(为instrumentation 做的选择包括Windows事件跟踪信息、跟踪调试类、自定义性能计数器和WMI). For logging, consider the Logging Application Block in the Enterprise Library(对于日志,考虑使用Enterprise Library里的Logging Application Block).

 

For more information, see Chapter 3, “Architecture and Design Guidelines.”


• How to design for transactions(如何设计事务)

 
Use connection-based transactions when accessing a single data source(在存取一个单一的数据源时,使用基于连接的事务). Where you cannot use transactions, implement compensating methods to revert the data store to its previous state(在不能使用事务的地方,实现一个可以恢复数据仓库到之前状态的补偿方法). Avoid holding locks for long periods(避免长时间保持锁定); for example, when using long-running atomic transactions(例如,当执行长时间运行的原子事务时). Consider using compensating locks for long-running transactions(考虑为长时间事务使用补偿的锁。。。). If the chance of a data conflict from concurrent users is low (如果并发用户发生数据冲突的几率很低)(for example, when users are generally adding data or editing different rows(例如:用户通常添加与编辑不同行的数据)), consider using optimistic locking during data access(考虑在数据存取是使用乐观锁定). If the chance of a data conflict from concurrent users is high(如果数据冲突的几率很高) (for example, when users are likely to be editing the same rows(例如,用户可能编辑同一行数据)), consider using pessimistic locking during data access(考虑使用悲观锁定). If transactions take a long time to complete, consider using asynchronous transactions that call back to the client when complete(如果事务需要一段很长的时间来完成,考虑使用异步事务,这样会在事务完成时回调客户端). You can perform transactions using T-SQL commands, ADO.NET, or System.Transaction(你可以使用T-SQL、ADO.net或者System.Transaction来执行事务). T-SQL transactions are most efficient for server-controlled transactions on a single data store(T-SQL在单数据仓库上的服务器控制事务中最高效). Keep transactions as short as possible, consider your isolation level, and keep read operations to a minimum inside a transaction(保持事务尽可能的短,考虑你的隔离级别,并保持在事务中的读取操作最小化).

 

For more information, see Chapter 3, “Architecture and Design Guidelines.”

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值