Ok, so I've solved it "myself" (all credits to stackoverflow). Finally I've came up with this code:
services.AddDbContext<IdentityDBContext>((serviceProvider, options) =>
{
var httpContext = serviceProvider.GetService<IHttpContextAccessor>().HttpContext;
var httpRequest = httpContext.Request;
var pathParts = httpRequest.Path.Value.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
var pathParsed = decimal.TryParse(pathParts[1], out decimal pathVersion);
var qsParsed = decimal.TryParse(httpRequest.Query["api-version"], out decimal qsVersion);
var useV1DB = (!pathParsed || pathVersion == 1) && (!qsParsed || qsVersion == 1);
options.UseSqlServer(Configuration.GetConnectionString(useV1DB ? "V1DB" : "V2DB"));
});
it allows me both to have version number as part of the path and as a querystring parameter "api-version"