如何通过当前用户的信息在DDD的所有图层 [英] How to pass Current User Information to all Layers in DDD

查看:158
本文介绍了如何通过当前用户的信息在DDD的所有图层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

类似的问题已经被问过,但不完全一样(除非我错过了它)

Similar questions have been asked before but not quite the same (unless I missed it)

我想通过我的服务,域,域事件通过IUserInfo类的实例,域名事件处理程序...

I want to pass IUserInfo class instance through my Service, Domain , Domain Events, Domain Event Handlers...

请告诉我是这样做的最佳方式。

Whats is the best way to do it.

我应该

  • 通过注册它注入它使用的IoC 对Httpcontext.Current.session [的currentUser]的实例;

  • Inject it using IoC by registering it against instance of Httpcontext.Current.session["CurrentUser"];

将数据添加到当前线程。

Add the data to Current Thread.

任何其他方式

我停留在域名事件处理程序,我想使用的审计数据,以及发送电子邮件。

I am stuck at Domain Event Handlers where I want to use the data for auditing as well as sending emails.

我希望能够从几乎任何地方使用的currentUser信息在我的应用程序。

I want to be able to use the CurrentUser information from almost anywhere in my application.

使用线程的线程池,我怀疑,如果线程的重用会重置数据。如果没有,请shopw我如何使用线程来传递IUSER实例。

With threading as threads are pooled I am skeptical if the reuse of threads will reset the data. If not please shopw me how to use threading to pass IUser instance.

问候,

推荐答案

我使用的IoC做过这种事情。这样做的好处是,它是非常测试 - 你可以存根出你的用户信息进行测试 - 合理可读性和易于遵循

I've done this kind of thing before using IoC. The benefit of this is that it's very testable -- you can stub out your user info for testing -- and reasonably readable and easy to follow.

这篇关于如何通过当前用户的信息在DDD的所有图层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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