Ares Capital Corporation agreed to merge with MidCap Financial Investment Corporation in a stock-for-stock transaction valued at approximately $4.8 billion, creating a larger specialty finance company with a continued focus on lower middle market lending.