Skip to main content

Magento 2: How to get customer collection

<?php

protected $_customerFactory;

public function __construct(
    ...
    \Magento\Customer\Model\ResourceModel\Customer\CollectionFactory $customerFactory
    ...
) {
    ...
    $this->_customerFactory = $customerFactory;
    ...
}

/**
 * Get customer collection
 */
public function getCustomerCollection()
{
    return $this->_customerFactory->create();
}