How to inject UserManager to Program.cs or Startup.cs

You should not build provider and resolve something from it inside the handler (it is definitely not an operation you want to do for each principal validation), just use the context parameter of it:

new CookieAuthenticationEvents
{
    OnValidatePrincipal = context =>
    {
        var userManager = context.HttpContext.RequestServices.GetRequiredService<UserManager<MyUser>>();
    }
}