I have a few WCF services that all implement an All() method, so I made a generic base class that implements that All() method, but every WCF service call needs his own security role.
public class QueryService<T>
where T : class
{
public IQueryable<T> All()
{
// query data
return data;
}
}
public class CarService : QueryService<Car>
{
[PrincipalPermission(SecurityAction.Demand, Role = "Car_R")]
public new IQueryable<Car> All()
{
return base.All();
}
}
public class BikeService : QueryService<Bike>
{
[PrincipalPermission(SecurityAction.Demand, Role = "Bike_R")]
public new IQueryable<Bike> All()
{
return base.All();
}
}
Is there a way to move the PrincipalPermission annotation to the base class (QueryService) and define the Role string in my derived classes, that way I wouldn't have to override every method of my base class (and call base.xxx).
Something like this: (isn't working though ...)
public class QueryService<T>
where T : class
{
public const string RoleFromDerivedClass = "Default";
[PrincipalPermission(SecurityAction.Demand, Role = RoleFromDerivedClass)]
public IQueryable<T> All()
{
// query data
return data;
}
}
public class CarService : QueryService<Car>
{
public const string RoleFromDerivedClass = "Car_R";
}
public class BikeService : QueryService<Bike>
{
public const string RoleFromDerivedClass = "Bike_R";
}