/**
  * @param \Magento\Framework\Service\Data\ObjectFactory $objectFactory
  * @param AttributeValueBuilder $valueBuilder
  * @param RegionBuilder $regionBuilder
  * @param CustomerMetadataServiceInterface $metadataService
  */
 public function __construct(\Magento\Framework\Service\Data\ObjectFactory $objectFactory, AttributeValueBuilder $valueBuilder, RegionBuilder $regionBuilder, CustomerMetadataServiceInterface $metadataService)
 {
     parent::__construct($objectFactory, $valueBuilder);
     $this->_metadataService = $metadataService;
     $this->_regionBuilder = $regionBuilder;
     $this->_data[Address::KEY_REGION] = $regionBuilder->create();
 }
 /**
  * Add address to customer during create account
  *
  * @return \Magento\Customer\Service\V1\Data\Address|null
  */
 protected function _extractAddress()
 {
     if (!$this->getRequest()->getPost('create_address')) {
         return null;
     }
     $addressForm = $this->_formFactory->create('customer_address', 'customer_register_address');
     $allowedAttributes = $addressForm->getAllowedAttributes();
     $addressData = array();
     foreach ($allowedAttributes as $attribute) {
         $attributeCode = $attribute->getAttributeCode();
         $value = $this->getRequest()->getParam($attributeCode);
         if (is_null($value)) {
             continue;
         }
         switch ($attributeCode) {
             case 'region_id':
                 $this->_regionBuilder->setRegionId($value);
                 break;
             case 'region':
                 $this->_regionBuilder->setRegion($value);
                 break;
             default:
                 $addressData[$attributeCode] = $value;
         }
     }
     $this->_addressBuilder->populateWithArray($addressData);
     $this->_addressBuilder->setRegion($this->_regionBuilder->create());
     $this->_addressBuilder->setDefaultBilling($this->getRequest()->getParam('default_billing', false))->setDefaultShipping($this->getRequest()->getParam('default_shipping', false));
     return $this->_addressBuilder->create();
 }