public T SetupService <T>(Type target) where T : class, IAgentService { if (!typeof(T).IsAssignableFrom(target)) { throw new ArgumentException("The target type must implement the specified interface"); } ServiceTypes.TryAdd(typeof(T), target); return(GetService <T>()); }