private object GetOwningEntity(AccountType accountType, long accountId) { var repositoryType = typeof(IRepository <>).MakeGenericType(accountType.GetAccountType()); var getById = repositoryType.GetMethod("GetById"); var repository = ComponentContext.Resolve(repositoryType); return(getById.Invoke(repository, new object[] { accountId })); }