Membership Providers as Generics - possible?

Membership Providers as Generics - possible?

Old forum URL: forums.lhotka.net/forums/t/2062.aspx


skagen00 posted on Tuesday, January 02, 2007

The path I'll be taking with the Membership API in my ASP.Net application will be to utilize the SqlMembershipProvider but to provide a wrapper class to shuttle it to the application server (if so configured) via a CSLA command class object.

The bottom line is that I'd like to be able to utilize a class:

CslaMembershipProvider<T> : MembershipProvider where T : MembershipProvider

And then to be able to provide SqlMembershipProvider, for instance, as a valid generic parameter. I'm not entirely sure it'll work as such - I'm overriding Initialize() on CslaMembershipProvider to function as such:

public override void Initialize(string name, NameValueCollection config)

{

_wrappedProvider = Activator.CreateInstance<T>();

_wrappedProvider.Initialize(name, config);

}

Unfortunately, before it gets to the Initialize code, I think there are issues with my MembershipProvider being a generic class.

In my web config, I'm doing this:

<membership defaultProvider="CslaMembershipProvider">

<providers>

<clear />

<add name="CslaMembershipProvider" type="CslaMembershipProvider&lt;SqlMembershipProvider&gt;"

...other attributes... />

I had attempted to place the generic parameter in the defaultProvider and name attributes above as well to no avail.

My error occurs when the membership API is accessed and the following error is thrown: Could not load type 'CslaMembershipProvider<SqlMembershipProvider>'. (c:\inetpub\wwwroot\xxx\web.config line 133)

Any one have an idea as to if using a generic class as a provider is possible?

 

skagen00 replied on Tuesday, January 02, 2007

Strike this, I'm going to do this without generics.

 

Copyright (c) Marimer LLC