ASP.NET MVC 中 ProfileProvider 的替代方案
我正在开发一个 ASP.NET MVC 站点,它实际上使用自定义 profileProvider 来检索与存储在自定义数据库中的单个用户相关的信息(例如访问的最后一页、在网格中查看的最大记录数、通过邮件通知等) 。 我不喜欢这种技术,因为 profileProvider 不容易注入,有另一种方法可以获取配置文件提供程序公开的相同功能吗?我认为可能可以使用 asp.net 模块,但我不是专家。
i'm developing an ASP.NET MVC site that actually use a custom profileProvider to retrieve info (like last page visited, max number of record to view in a grid, notification via mail etc) related to a single user stored in a custom database.
I don't like this technique because profileProvider is not easely injectable, there is an alternative way to obtains the same functionality exposed by profile provider? I think that probably is possible to use an asp.net module but i'm not an expert.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为 tartafe 的意思是提供程序(也是您的自定义 ProfileProvider)由外部代码(System.Web.Configuration.ProvidersHelper)实例化和控制。
依赖注入模式表示您的自定义提供程序依赖的任何对象都应该由控制器(或容器)传入。比照。 松耦合的依赖注入)。通常,您的控制器将初始化存储库、数据上下文或其他对象,并通过构造函数或属性将其传入。但这对于自定义提供程序来说是不可能的,因为它的“控制器”被密封在 System.Web.Configuration 中。
我认为问题是:有什么方法可以影响 ProvidersHelper 如何实例化和控制我们的自定义提供程序?
I think what tartafe means is that providers (also your custom ProfileProvider) are instantiated and controlled by external code (System.Web.Configuration.ProvidersHelper).
The Dependency Injection pattern says any objects your custom provider relies on, should be passed in by a controller (or container). Cfr. Dependency Injection for Loose Coupling). Typically your controller will initialize a repository, datacontext, or other object and pass it in through the constructor or a property. But that is not possible with a custom provider since its 'controller' is sealed in System.Web.Configuration.
I think the question than becomes: is there any way to influence how ProvidersHelper instantiates and controls our custom providers?
不容易注射到底是什么意思?
如果您只是不想在控制器中使用它,则创建一个操作过滤器来添加查看数据所需的用户信息模型。
如果您的意思是您不希望在使用配置文件信息的地方存在 System.Web 依赖项,请创建一个适配器接口(如 IProfileService)并使用配置文件提供程序包装器来实现它。
如果你的意思不是我猜的这两件事中的任何一个,那么请尝试解释一下,因为语言有点不清楚。
What exactly do you mean by it is not easily injectable?
If you just mean that you don't want it in your Controller, then create an action filter that adds the model of user info you need to view data.
If you mean that you don't want a System.Web dependency somewhere that you are using the profile information, then create an adapter interface like
IProfileService
and implement it with a profile-provider wrapper.If you don't mean either of the two things I guessed, then please try to explain, because the language is a bit unclear.