Index Update issue in Sitecore 9.1

Want to Rebuild indexes on publish programmatically something like below in Sitecore 9.1,


We were using Sitecore 7.5 and for index update using below mentioned code. Now we have upgraded to Sitecore 9.1 and this code is not supporting. We searched for documentation but didn't found any. Can you please provide alternative for this or any solution for this ?


public static void UpdateAllIndexes()
{
var db = Sitecore.Configuration.Factory.GetDatabase(EnvironmentContext.ContentDatabase);
if (db == null)
{
return;
}

IndexingManager.Provider.UpdateIndex(db);
}

 

 

Please suggest an alternative for above issue  .