public static IHaveToken <T> GetHaveToken <T>(this TokenStore store, IDiagInfo diagInfo, string name) { var token = store.GetToken <T>(name); if (token != null) { return(new HaveToken <T>(token)); } return(new LazyHaveToken <T>(() => store.GetToken <T>(name), name, diagInfo)); }
public static void SaveToken <T>(this TokenStore store, IDiagInfo diagInfo, string name, IToken <T> token) { if (store.GetToken <T>(name) != null) { throw new RegistrationException($"Definition for {token} is already registered", diagInfo); } if (token == null) { throw new RegistrationException($"Attempted to register null as token for {typeof(T).Name} \"{name}\"", diagInfo); } store.Tokens.Set(token, name); token.Name = name; }