Container::get should be optimistic
Currently, Container::get
is pessimistic: it considers that it is likely that the passed parameter is not registered. This forces the return type of Container::get
to be T | undefined
. It forces consumers to always test for the result even though they are positive that the token has been registered.
Let's make the get function optimistic and consider that it is likely that the passed parameter is registered. Would the token not be resgistered, an expection woudl be thrown. Consumers would have to catch the exception when they are not sure that the passed token has been previously registered.