Since this question is still not properly marked as duplicate: The way to register a Generic class:
services.AddScoped(typeof(IRepository<,>), typeof(Repository<,>));
now you can resolve it in the following way:
serviceProvider.GetService(typeof(IRepository<A,B>));
// or: with extensionmethod
serviceProvider.GetService<IRepository<A,B>>();