I'm interested in your opinions on this one, because Relate+ is implemented one way, and in the documentation (Developers handbook, by Netstar) recommends extending your objects (Blog, User, Image etc.) with new, inherited objects, for use in your project. Today Relate+ is using a lot of extension methods that are great for some uses, but I'm not convinced it is the best way to go about when you are using Attributes on a user.
So, what are your experiences and advice?
Today the way of getting a users attribute for Region is implemented with an extension method
public static string GetRegion(this IUser user)
string s = user.GetAttributeValue("Region");
return s == "-1" ? string.Empty : s;
But would it not be more correct to utilize inheritance and good OO practice to har your own User object that implements those methods as Properties like this?
public class CustomUser : EPiServer.Common.Security.User
public string JobTitle
string s = this.GetAttributeValue("Jobtitle");
if (string.IsNullOrEmpty(s) || s == "-1")
and then use
string jobTitle = user.JobTitle
and be happier?
Go debate! :)
Bump! This area need attention - how to properly extend the IUser/User object for your project. Or is eveyone really happy with calling GetAttributeValue or using a lot of extension methods?
I think this very much depends on the usage scernario. If you are only adding strong-typed access to a few values then extensions methods are all well and good.Any more than a few, and I I think that you're be better off creating a CustomUser class that inherits from the User class. This object more accurately reveals your code's intentions. That is, that a CustomUser is a significant piece of your domain puzzle.