November Happy Hour will be moved to Thursday December 5th.

multiple inheritance

Vote:
 

Ok, so this is not really multiple inheritance, but rather repeated inheritance... I am trying to create more than one class inheriting from the Club module in StarCommunity. I created two classes with one entity provider each, and added the entity providers to the EntityProviders.config file. Unfortunately, I can only get one of them working (it will take over and ClubHandler will always return that class and I will get a cast error).

<EntityProvider>
<Name>AEntityProvider, AAssembly</Name>
<SupportedTypes>
<SupportedType><Name>A, AAssembly</Name></SupportedType>
<SupportedType><Name>StarCommunity.Modules.Club.Club, StarCommunity.Modules.Club</Name></SupportedType>
</SupportedTypes>
</EntityProvider>
<EntityProvider>
<Name>
BEntityProvider, BAssembly</Name>
<SupportedTypes>
<SupportedType><Name>B, BAssembly</Name></SupportedType>
<SupportedType><Name>StarCommunity.Modules.Club.Club, StarCommunity.Modules.Club</Name></SupportedType>
</SupportedTypes>
</EntityProvider>

My question is, how do I inherit the same class more than once?

#21476
Jun 29, 2008 18:06
Vote:
 

Hi,

It is up to the entityprovider to return the correct instance and it does not really matter what the configuration says. The configuration is used to identify which types your provider supports (so we get your provider when we ask for Club) and you don't need multiple providers to support multiple types.

Later on when your provider is called it is up to you to return the correct instance, if you want that to be type A or type B is up to you. The problem as I see it is to know which type is the correct one, that you will have to do based on let's say, an attribute value of the Club.

For example:
public object GetEntityInstance(Type type, DbDataReader reader)
{
if (type == typeof(Club))
{
  Club club = new Club(reader);
  if(club.GetAttributeValue<string>("clubtype") == "A")
   return new ClubA(reader);
  else if(club.GetAttributeValue<string>("clubtype") == "B")
   return new ClubB(reader);
  else
   throw new ApplicationException("Unhandled club type");
}
else
  return null;
}

#21568
Edited, Jul 01, 2008 17:18
This thread is locked and should be used for reference only. Please use the Legacy add-ons forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.