架构Q - 用于Web UI和Forms UI的BLL [英] Architecture Q - BLL for Web UI and Forms UI

查看:111
本文介绍了架构Q - 用于Web UI和Forms UI的BLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我有一个业务对象的类库,可以通过

ASP.Net前端和WinForms前端访问。

类库中的典型业务对象,让我们说Employee,有一个save方法。在保存方法中,成功保存员工记录后,
将在

历史记录表中创建记录,以记录何时保存对象。用户名,IP地址

(如果是网页),以及我想添加到

历史记录中的其他信息已经在ASP中.Net会话,但我不希望我的BLL

依赖于HTTPContext对象。我想避免将所有这些信息作为参数传递给Employee.Save方法(或者删除和

为此创建方法),并且我'我希望能够从网络或表单UI中使用对象

。我想在

共享类中设置字段,这对于表单UI来说没什么问题但是不会工作(我不会相信) Web UI因为每个用户都会在共享类中覆盖

特定于用户的信息。有没有人对此有任何想法?

TIA,

Monty

解决方案

< blockquote>

我建议使用Factory方法。


您创建一个自定义对象来存储信息。实际上,我创建了一个界面

和一个实现。


然后你创建一个工厂来返回一个对象(或者它的实现)

界面)基于你是否处于winforms或web环境。


在这里查看我的博客:

12/1/2005

了解简单工厂模式
http: //sholliday.spaces.live.com/blog/


你关心的是工厂环境

某处,你' '它必须参考System.Web

如果这是你的克鲁兹,那么明智地选择。如果你不想要你的商业层

引用它,那么你必须把它放在自己的组装中。


在这难得的照顾,我实际上让biz层引用了System.Web

namespace / dll,知道我不会在其他任何地方使用它。


但是你有一个想法。


" Monty" < mo *** @ community.nospamwrote in message

news:%2 **************** @ TK2MSFTNGP02.phx.gbl ...


您好,


我有一个业务对象的类库,可以通过
$ b $访问b ASP.Net前端和WinForms前端。

类库中的典型业务对象,让我们说Employee,有一个save方法。在保存



方法中,


成功保存员工记录后,创建记录





历史记录表,用于记录何时保存对象的人。用户名,IP



地址


(如果是网络),以及其他信息我想在

历史记录中添加已经在ASP.Net会话中,但我不希望我的BLL

依赖于HTTPContext对象。我想避免不得不



传递


所有这些信息作为员工的参数.Save方法(或删除和

为此创建方法),我希望能够从Web或表单UI使用对象

。我想在

共享类中设置字段,这对于表单UI来说没什么问题但是不会工作(我不会相信) Web UI因为每个用户都会在共享类中覆盖

特定于用户的信息。有没有人对



这个有什么想法吗?


TIA,

Monty



嗨Sloan(Ferris Bueller主题开始在我脑后开始玩),


感谢您的演示,我想我会使用这种方法。我不是一个原生的C#

用户,但我想我能把所有的东西弄清楚。我想知道为什么你这两个不同的持有者类,一个

IObjectHolder接口和一个ObjectHolderFactory,它似乎可以

都可以很容易地汇总成一个。我做了这个(下面),它似乎是

工作(只是从一个非常基本/快速的测试)。我错过了一些明显的东西吗?


公共类UserInfo

私有共享singletonInstance作为UserInfo

私有共享ReadOnly SESSION_OBJECT_GUID As String =

" 123503F8-6CBD-46F0-ACDC-98683A94360C"

Private _UserName As String =""

Private _UserID As String =" ;"

私有_WorkstationID As String =""


Private Sub New()''私有构造函数让其他人免受

创建这个

结束子


公共共享函数GetInstance()如UserInfo

如果singletonInstance什么都没有那么

如果System.Web.HttpContext.Current是Nothing那么''窗体表格

环境:

singletonInstance =新用户信息

Else''网络环境:

如果System.Web.HttpContext.Current.Session IsNot Nothing那么

如果

System.Web。 HttpContext.Current.Session(SESSION_O BJ ECT_GUID)IsNot Nothing

然后

singletonInstance =

TryCast(System.Web.HttpContext.Current.Session(SES SION_OBJECT_GUID),

UserInfo)

否则

singletonInstance =新用户信息

System.Web.HttpContext.Current.Session(SESSION_OBJ ECT_GUID)

= singletonInstance

结束如果

结束如果

结束如果

结束如果

返回singletonInstance

结束函数


公共属性UserID()As String

获取

返回_UserID

结束获取

设置(ByVal值为字符串)

_UserID = value

结束集

结束财产

公共财产UserName()作为字符串

获取

返回_UserName

结束获取

设置(ByVal值为字符串)

_UserName = value

结束集

结束物业

公共物业工作站ID()为字符串

获取

返回_WorkstationID

结束获取

设置(ByVal值为字符串)

_WorkstationID = value

结束集

结束财产

结束班级


我当然也可以添加Dispose方法进行清理。

再次感谢。


我稍微修改了GetInstance(以确保我们从

会话中获取它)当我们进入网络场景时):

公共共享函数GetInstance()如UserInfo

如果System.Web.HttpContext.Current是Nothing那么''窗体形式

环境:

如果singletonInstance什么都没有那么singletonInstance =新

UserInfo

返回singletonInstance

Else''网络环境:

如果System.Web.HttpContext.Current.Session IsNot Nothing那么

如果

System.Web .HttpContext.Current.Session(SESSION_OBJ ECT_GUID)什么都没有

System.Web.HttpContext.Current.Se ssion(SESSION_OBJ ECT_GUID)

=新用户信息

结束如果

返回

TryCast(System.Web.HttpContext .Current.Session(SES SION_OBJECT_GUID),

UserInfo)

否则

返回Nothing''抛出异常?

结束如果

结束如果

结束功能


Hello,

I have a class library of business objects that will accessed both by an
ASP.Net front end and a WinForms front-end. A typical business object in
class library, let''s say "Employee", has a save method. In the save method,
after the employee record is successfully saved, a record is created in the
history table to record who saved the object when. The user name, IP address
(if it''s web), and other information I would like to add to have in the
history record are already in the ASP.Net session, but I don''t want my BLL
to be dependent on the HTTPContext object. I''d like to avoid having to pass
all this info as parameters to the Employee.Save method (or Delete and
Create methods for that matter), and I''d like to be able to use the object
from either the web or form UI. I thought about setting the fields in a
shared class, which would be fine for the Forms UI but wouldn''t work (I
don''t believe) for the Web UI because each user would over-write the
user-specific info in the shared class. Does anyone have any ideas for this?
TIA,

Monty

解决方案


I suggest a Factory approach.

You create a custom object to store info. Actually, Id create an interface
and an implementation.

Then you create a factory to return an object (or an implementation of that
interface) based on whether you''re in a winforms or web environment.

Check out my blog here:
12/1/2005
Understanding the Simple Factory Pattern
http://sholliday.spaces.live.com/blog/

and you care about "Factory By Environment"
Somewhere, you''re gonna have to reference System.Web
If that''s your cruz, then pick wisely. If you don''t want you biz layer to
reference it, then you''ll have to put it in its own assembly.

In this rare care, I actually do let the biz layer reference the System.Web
namespace/dll, knowing I don''t use it anywhere else.

But there''s an idea for you.

"Monty" <mo***@community.nospamwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...

Hello,

I have a class library of business objects that will accessed both by an
ASP.Net front end and a WinForms front-end. A typical business object in
class library, let''s say "Employee", has a save method. In the save

method,

after the employee record is successfully saved, a record is created in

the

history table to record who saved the object when. The user name, IP

address

(if it''s web), and other information I would like to add to have in the
history record are already in the ASP.Net session, but I don''t want my BLL
to be dependent on the HTTPContext object. I''d like to avoid having to

pass

all this info as parameters to the Employee.Save method (or Delete and
Create methods for that matter), and I''d like to be able to use the object
from either the web or form UI. I thought about setting the fields in a
shared class, which would be fine for the Forms UI but wouldn''t work (I
don''t believe) for the Web UI because each user would over-write the
user-specific info in the shared class. Does anyone have any ideas for

this?

TIA,

Monty



Hi Sloan (Ferris Bueller theme starts playing in the back of my brain),

Thanks for the demo, I think I will use that method. I''m not a native C#
user but I think I was able to figure everything out. I''m wondering why you
went through the trouble to create two different holder classes, an
IObjectHolder interface, and an ObjectHolderFactory when it seems it could
all be rolled into one pretty easily. I did this (below) and it seems to be
working (just from a very basic/quick test). Am I missing something obvious?

Public Class UserInfo
Private Shared singletonInstance As UserInfo
Private Shared ReadOnly SESSION_OBJECT_GUID As String =
"123503F8-6CBD-46F0-ACDC-98683A94360C"
Private _UserName As String = ""
Private _UserID As String = ""
Private _WorkstationID As String = ""

Private Sub New() ''a private constructor keeps anyone else from
creating this
End Sub

Public Shared Function GetInstance() As UserInfo
If singletonInstance Is Nothing Then
If System.Web.HttpContext.Current Is Nothing Then ''windows forms
environment:
singletonInstance = New UserInfo
Else ''web environment:
If System.Web.HttpContext.Current.Session IsNot Nothing Then
If
System.Web.HttpContext.Current.Session(SESSION_OBJ ECT_GUID) IsNot Nothing
Then
singletonInstance =
TryCast(System.Web.HttpContext.Current.Session(SES SION_OBJECT_GUID),
UserInfo)
Else
singletonInstance = New UserInfo
System.Web.HttpContext.Current.Session(SESSION_OBJ ECT_GUID)
= singletonInstance
End If
End If
End If
End If
Return singletonInstance
End Function

Public Property UserID() As String
Get
Return _UserID
End Get
Set(ByVal value As String)
_UserID = value
End Set
End Property
Public Property UserName() As String
Get
Return _UserName
End Get
Set(ByVal value As String)
_UserName = value
End Set
End Property
Public Property WorkstationID() As String
Get
Return _WorkstationID
End Get
Set(ByVal value As String)
_WorkstationID = value
End Set
End Property
End Class

I could also add a Dispose method to clean up, of course.

Thanks again.


I revised that GetInstance a bit (to make sure we''re getting it from the
session when we''re in the web scenario):
Public Shared Function GetInstance() As UserInfo
If System.Web.HttpContext.Current Is Nothing Then ''windows forms
environment:
If singletonInstance Is Nothing Then singletonInstance = New
UserInfo
Return singletonInstance
Else ''web environment:
If System.Web.HttpContext.Current.Session IsNot Nothing Then
If
System.Web.HttpContext.Current.Session(SESSION_OBJ ECT_GUID) Is Nothing Then
System.Web.HttpContext.Current.Session(SESSION_OBJ ECT_GUID)
= New UserInfo
End If
Return
TryCast(System.Web.HttpContext.Current.Session(SES SION_OBJECT_GUID),
UserInfo)
Else
Return Nothing ''Throw exception?
End If
End If
End Function


这篇关于架构Q - 用于Web UI和Forms UI的BLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆