MVC3,团结框架具有多个配置 [英] MVC3, Unity Framework with multiple configurations

查看:96
本文介绍了MVC3,团结框架具有多个配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有哪些需要每个公司独特的业务逻辑的多公司能现场。我们使用的构造函数依赖注入我们的控制器,但需要交换基于用户所在的公司正在使用的统一的容器。我在想,你可以设置容器为当前HttpContext前检查用户的cookie。这甚至可能?

We have a multi-company capable site which requires unique business logic for each company. We are using constructor dependency injection in our controllers, but would need to swap the unity container being used based upon a user's company. I was thinking that you could examine the user's cookie before setting the container for the current HttpContext. Is this even possible?

推荐答案

这是非常可行的。我会做的是建立一个大师容器,然后为每个公司一个子容器。这样,你有一个地方的默认配置,然后就可以按公司客户轻松而无需重新配置每一次。救子容器中一些容易索引的方法。(公司的字典 - >容器,也许)

It's very doable. What I'd do is set up a "master" container, and then a child container for each company. That way you have default configuration in one place, and then you can customer per company easily without having to reconfigure every time. Save the child containers in some easily indexed way (a dictionary of company -> container, perhaps).

然后,编写运行在管道早期找出请求的是哪个公司的HTTP模块实现。用它来计算出合适的容器来使用。并从那里你pretty多集。

Then, write an HttpModule implementation that runs early in the pipeline to figure out which company the request is for. Use that to figure out the appropriate container to use. And from there you're pretty much set.

我会担心因为你的系统,你没有足够的隔离我的数据的客户;不想跨越泄露客户信息和得到起诉。

I would be worried as a customer of your system that you're not isolating my data sufficiently; wouldn't want to leak information across customers and get sued.

这篇关于MVC3,团结框架具有多个配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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