How to create a custom block and call in a region programming Drupal 9 [duplicate]

I am looking for a solution where i can create a block via my custom module that i already achieved.

class CustomExercise1Block extends BlockBase {

  public function build() {
  
    $build('wrapper')('#markup') ="Hello World!";
    return  $build;
  }

Now this block start appearing on Structure > Block Layout from there i can chose the block and call in any region which i want. But i am looking for additionally that stop this process and do via programming from same module

so once in above my custom module a block created it i assign it a region and page visibility so it start appeared in that region and page
I am looking for Drupal 9