I have .net core web api service. Should i open new connection and close for every get/post request? Or, is there a performance way to use db connection like a global connection variable?
Yes. You use the AddDbContext extension method to configure your DbContext and it'll automatically create a Scoped instance of the context which is created and disposed with each request:
var connection = @"Server=(localdb)\mssqllocaldb;Database=EFGetStarted.AspNetCore.NewDb;Trusted_Connection=True;ConnectRetryCount=0";
services.AddDbContext<BloggingContext>
(options => options.UseSqlServer(connection));
For a full example visit: https://learn.microsoft.com/en-us/ef/core/get-started/aspnetcore/new-db?tabs=visual-studio