Add service programmatically

It’s all very alien to me and seems quite complex. Is there example code somewhere?