Skip to content

Instantly share code, notes, and snippets.

@stimms
Created December 17, 2012 17:56
Show Gist options
  • Save stimms/4320357 to your computer and use it in GitHub Desktop.
Save stimms/4320357 to your computer and use it in GitHub Desktop.
A token resolver
public class TagInformationResolver: IResolver
{
//The cache keeps track of the last n tags so we don't have to keep going to the database
//for data which isn't really changing
private static TagCache{get; set;}
public TagInformationResolver(ITagRepository tagRepository)
{//we could probably make the cache responsible for resolving its own information but that limits our ability
//to use dependency injection for different strategies.
TagCache.SetResolver(tagRepository);
}
public string TryResolve(string token, int tagId)
{
string result;
switch(token){
case "TAGNUMBER":
result = TagCache.GetTagById(Id).Name;
case "TAGTYPE":
result = TagCache.GetTagById(Id).TagType;
default:
result = null;
}
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment