Model view controller 如何在MVC CF应用程序中添加会话数据日志记录?
起初,我想对服务进行子类化,并在其周围添加日志调用,但是如果不修改大量代码,就无法通过参数将“当前登录用户”传递给服务层。直接访问会话?似乎不对。会话外观 在控制器级别进行日志记录会更容易。我直接访问会话没有问题,但是如果该服务是由MVC应用程序以外的其他源(例如Ajax?Flex?)调用的,它将不会记录 AOP?不知道这会有什么帮助,但如果有,请告诉我Model view controller 如何在MVC CF应用程序中添加会话数据日志记录?,model-view-controller,logging,coldfusion,Model View Controller,Logging,Coldfusion,起初,我想对服务进行子类化,并在其周围添加日志调用,但是如果不修改大量代码,就无法通过参数将“当前登录用户”传递给服务层。直接访问会话?似乎不对。会话外观 在控制器级别进行日志记录会更容易。我直接访问会话没有问题,但是如果该服务是由MVC应用程序以外的其他源(例如Ajax?Flex?)调用的,它将不会记录 AOP?不知道这会有什么帮助,但如果有,请告诉我 思想?谢谢。中有一个使用ColdSpring的AOP功能实现日志记录功能的示例。日志记录是很好地使用AOP的一个很好的例子 就与会话范围的交互
思想?谢谢。中有一个使用ColdSpring的AOP功能实现日志记录功能的示例。日志记录是很好地使用AOP的一个很好的例子 就与会话范围的交互而言,我使用了一个。这将适用于任何范围
<cfcomponent output="false">
<cfset variables.instance = {} />
<cfset variables.instance.scopename = '' />
<cfset variables.instance.scope = '' />
<cffunction name="init" returntype="scopeFacade" output="false" access="public">
<cfargument name="scope" required="true" type="variablename" />
<cfset variables.instance.scopename = arguments.scope />
<cfreturn this />
</cffunction>
<cffunction name="getscope" returntype="struct" output="false" access="private">
<cfreturn structGet(variables.instance.scopename) />
</cffunction>
<cffunction name="get" returntype="any" output="false" access="public">
<cfargument name="key" required="true" type="string" />
<cfargument name="default" required="false" type="string" />
<cfset var scope = getscope() />
<cfif structKeyExists(arguments,"default") and not structKeyExists(scope,arguments.key)>
<cfreturn arguments.default />
</cfif>
<cfreturn scope[arguments.key] />
</cffunction>
<cffunction name="set" returntype="void" output="false" access="public">
<cfargument name="key" required="true" type="string" />
<cfargument name="value" required="true" type="any" />
<cfset var scope = getscope() />
<cfset scope[arguments.key] = arguments.value />
</cffunction>
<cffunction name="delete" returntype="void" output="false" access="public">
<cfargument name="key" required="true" type="string" />
<cfset var scope = getscope() />
<cfif exists(arguments.key)>
<cfset structDelete(scope,arguments.key) />
</cfif>
</cffunction>
<cffunction name="exists" returntype="boolean" output="false" access="public">
<cfargument name="key" required="true" type="string" />
<cfreturn structKeyExists(getScope(),arguments.key) />
</cffunction>
</cfcomponent>
中有一个使用ColdSpring的AOP功能实现日志记录功能的示例。日志记录是很好地使用AOP的一个很好的例子 就与会话范围的交互而言,我使用了一个。这将适用于任何范围
<cfcomponent output="false">
<cfset variables.instance = {} />
<cfset variables.instance.scopename = '' />
<cfset variables.instance.scope = '' />
<cffunction name="init" returntype="scopeFacade" output="false" access="public">
<cfargument name="scope" required="true" type="variablename" />
<cfset variables.instance.scopename = arguments.scope />
<cfreturn this />
</cffunction>
<cffunction name="getscope" returntype="struct" output="false" access="private">
<cfreturn structGet(variables.instance.scopename) />
</cffunction>
<cffunction name="get" returntype="any" output="false" access="public">
<cfargument name="key" required="true" type="string" />
<cfargument name="default" required="false" type="string" />
<cfset var scope = getscope() />
<cfif structKeyExists(arguments,"default") and not structKeyExists(scope,arguments.key)>
<cfreturn arguments.default />
</cfif>
<cfreturn scope[arguments.key] />
</cffunction>
<cffunction name="set" returntype="void" output="false" access="public">
<cfargument name="key" required="true" type="string" />
<cfargument name="value" required="true" type="any" />
<cfset var scope = getscope() />
<cfset scope[arguments.key] = arguments.value />
</cffunction>
<cffunction name="delete" returntype="void" output="false" access="public">
<cfargument name="key" required="true" type="string" />
<cfset var scope = getscope() />
<cfif exists(arguments.key)>
<cfset structDelete(scope,arguments.key) />
</cfif>
</cffunction>
<cffunction name="exists" returntype="boolean" output="false" access="public">
<cfargument name="key" required="true" type="string" />
<cfreturn structKeyExists(getScope(),arguments.key) />
</cffunction>
</cfcomponent>
我认为正确的锁定是在更高级别的某个地方完成的。否则,我建议将其添加到列出的方法中。我认为适当的锁定是在更高级别的某个地方完成的。否则,我建议将其添加到列出的方法中。