Search code examples
asp.net-mvc-2asp.net-mvc-3sqlprofileprovider

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.


Solution

  • 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?