alternative to profileprovider in asp.net mvc
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.
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?
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.
精彩评论