Created
December 17, 2012 17:56
-
-
Save stimms/4320357 to your computer and use it in GitHub Desktop.
A token resolver
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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