and so that the LORD may fulfill His promise to me: ‘If your descendants take heed to walk faithfully before Me with all their heart and soul, you will never fail to have a man on the throne of Israel.’
David connects that obedience to the LORD's promise that his line will remain on Israel's throne if his descendants walk faithfully.
It places Solomon's reign inside the larger Davidic promise.
1As the time drew near for David to die, he charged his son Solomon, 2“I am about to go the way of all the earth. So be strong and prove yourself a man. 3And keep the charge of the LORD your God to walk in His ways and to keep His statutes, commandments, ordinances, and decrees, as written in the Law of Moses, so that you may prosper in all you do and wherever you turn, 4and so that the LORD may fulfill His promise to me: ‘If your descendants take heed to walk faithfully before Me with all their heart and soul, you will never fail to have a man on the throne of Israel.’ 5Moreover, you know what Joab son of Zeruiah did to me— what he did to Abner son of Ner and Amasa son of Jether, the two commanders of the armies of Israel. He killed them in peacetime to avenge the blood of war. He stained with the blood of war the belt around his waist and the sandals on his feet. 6So act according to your wisdom, and do not let his gray head go down to Sheol in peace. 7But show loving devotion to the sons of Barzillai the Gileadite, and let them be among those who eat at your table, because they stood by me when I fled from your brother Absalom. 8Keep an eye on Shimei the son of Gera, the Benjamite from Bahurim who is with you. He called down bitter curses against me on the day I went to Mahanaim, but when he came down to meet me at the Jordan, I swore to him by the LORD: ‘I will never put you to the sword.’ 9Now therefore, do not hold him guiltless, for you are a wise man. You know what you ought to do to him to bring his gray head down to Sheol in blood.”