add factory mode and singleton mode