diff --git a/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php b/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php
index 702480aa81550c261757267568cd5c8f64338411..966af6726c08ab1d8a69396b4c6433ce34f54d20 100644
--- a/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php
+++ b/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php
@@ -6,6 +6,7 @@
 
 namespace Magento\Setup\Console\Command;
 
+use Magento\Framework\App\Filesystem\DirectoryList;
 use Magento\Framework\ObjectManagerInterface;
 use Magento\Framework\App\DeploymentConfig;
 use Magento\Setup\Model\ObjectManagerProvider;
@@ -36,19 +37,37 @@ class DiCompileCommand extends Command
      */
     private $taskManager;
 
+    /**
+     * @var DirectoryList
+     */
+    private $directoryList;
+
+    /**
+     * @var array
+     */
+    private $compiledPathsList;
+
+    /**
+     * @var array
+     */
+    private $excludedPathsList;
+
     /**
      * Constructor
      *
      * @param DeploymentConfig $deploymentConfig
+     * @param DirectoryList $directoryList
      * @param Manager $taskManager
      * @param ObjectManagerProvider $objectManagerProvider
      */
     public function __construct(
         DeploymentConfig $deploymentConfig,
+        DirectoryList $directoryList,
         Manager $taskManager,
         ObjectManagerProvider $objectManagerProvider
     ) {
         $this->deploymentConfig = $deploymentConfig;
+        $this->directoryList = $directoryList;
         $this->objectManager = $objectManagerProvider->get();
         $this->taskManager = $taskManager;
         parent::__construct();
@@ -61,7 +80,7 @@ class DiCompileCommand extends Command
     {
         $this->setName('setup:di:compile')
             ->setDescription(
-                'Generates DI configuration and all non-existing interceptors, proxies and factories'
+                'Generates DI configuration and all non-existing interceptors and factories'
             );
         parent::configure();
     }
@@ -71,19 +90,76 @@ class DiCompileCommand extends Command
      */
     protected function execute(InputInterface $input, OutputInterface $output)
     {
+        $appCodePath = $this->directoryList->getPath(DirectoryList::MODULES);
+        $libraryPath = $this->directoryList->getPath(DirectoryList::LIB_INTERNAL);
+        $generationPath = $this->directoryList->getPath(DirectoryList::GENERATION);
         if (!$this->deploymentConfig->isAvailable()) {
             $output->writeln('You cannot run this command because the Magento application is not installed.');
             return;
         }
-        $compiledPathsList = [
-            'application' => BP . '/'  . 'app/code',
-            'library' => BP . '/'  . 'lib/internal/Magento/Framework',
-            'generated_helpers' => BP . '/'  . 'var/generation'
+        $this->compiledPathsList = [
+            'application' => $appCodePath,
+            'library' => $libraryPath . '/Magento/Framework',
+            'generated_helpers' => $generationPath
         ];
-        $excludedPathsList = [
-            'application' => '#^' . BP . '/app/code/[\\w]+/[\\w]+/Test#',
-            'framework' => '#^' . BP . '/lib/internal/[\\w]+/[\\w]+/([\\w]+/)?Test#'
+        $this->excludedPathsList = [
+            'application' => '#^' . $appCodePath . '/[\\w]+/[\\w]+/Test#',
+            'framework' => '#^' . $libraryPath . '/[\\w]+/[\\w]+/([\\w]+/)?Test#'
+        ];
+        $this->configureObjectManager($output);
+
+        $operations = [
+            OperationFactory::REPOSITORY_GENERATOR => [
+                'path' => $this->compiledPathsList['application'],
+                'filePatterns' => ['di' => '/\/etc\/([a-zA-Z_]*\/di|di)\.xml$/']
+            ],
+            OperationFactory::APPLICATION_CODE_GENERATOR => [
+                $this->compiledPathsList['application'],
+                $this->compiledPathsList['library'],
+                $this->compiledPathsList['generated_helpers'],
+            ],
+            OperationFactory::INTERCEPTION => [
+                    'intercepted_paths' => [
+                        $this->compiledPathsList['application'],
+                        $this->compiledPathsList['library'],
+                        $this->compiledPathsList['generated_helpers'],
+                    ],
+                    'path_to_store' => $this->compiledPathsList['generated_helpers'],
+            ],
+            OperationFactory::AREA_CONFIG_GENERATOR => [
+                $this->compiledPathsList['application'],
+                $this->compiledPathsList['library'],
+                $this->compiledPathsList['generated_helpers'],
+            ],
+            OperationFactory::INTERCEPTION_CACHE => [
+                $this->compiledPathsList['application'],
+                $this->compiledPathsList['library'],
+                $this->compiledPathsList['generated_helpers'],
+            ]
         ];
+
+        try {
+            foreach ($operations as $operationCode => $arguments) {
+                $this->taskManager->addOperation(
+                    $operationCode,
+                    $arguments
+                );
+            }
+            $this->taskManager->process();
+            $output->writeln('<info>Generated code and dependency injection configuration successfully.</info>');
+        } catch (OperationException $e) {
+            $output->writeln('<error>' . $e->getMessage() . '</error>');
+        }
+    }
+
+    /**
+     * Configure Object Manager
+     *
+     * @param OutputInterface $output
+     * @return void
+     */
+    private function configureObjectManager(OutputInterface $output)
+    {
         $this->objectManager->configure(
             [
                 'preferences' => [
@@ -115,7 +191,7 @@ class DiCompileCommand extends Command
                 ],
                 'Magento\Setup\Module\Di\Code\Reader\ClassesScanner' => [
                     'arguments' => [
-                        'excludePatterns' => $excludedPathsList
+                        'excludePatterns' => $this->excludedPathsList
                     ]
                 ],
                 'Magento\Setup\Module\Di\Compiler\Log\Writer\Console' => [
@@ -125,47 +201,5 @@ class DiCompileCommand extends Command
                 ],
             ]
         );
-        $operations = [
-            OperationFactory::REPOSITORY_GENERATOR => [
-                'path' => $compiledPathsList['application'],
-                'filePatterns' => ['di' => '/\/etc\/([a-zA-Z_]*\/di|di)\.xml$/']
-            ],
-            OperationFactory::APPLICATION_CODE_GENERATOR => [
-                $compiledPathsList['application'],
-                $compiledPathsList['library'],
-                $compiledPathsList['generated_helpers'],
-            ],
-            OperationFactory::INTERCEPTION => [
-                    'intercepted_paths' => [
-                        $compiledPathsList['application'],
-                        $compiledPathsList['library'],
-                        $compiledPathsList['generated_helpers'],
-                    ],
-                    'path_to_store' => $compiledPathsList['generated_helpers'],
-            ],
-            OperationFactory::AREA_CONFIG_GENERATOR => [
-                $compiledPathsList['application'],
-                $compiledPathsList['library'],
-                $compiledPathsList['generated_helpers'],
-            ],
-            OperationFactory::INTERCEPTION_CACHE => [
-                $compiledPathsList['application'],
-                $compiledPathsList['library'],
-                $compiledPathsList['generated_helpers'],
-            ]
-        ];
-
-        try {
-            foreach ($operations as $operationCode => $arguments) {
-                $this->taskManager->addOperation(
-                    $operationCode,
-                    $arguments
-                );
-            }
-            $this->taskManager->process();
-            $output->writeln('<info>Generated code and dependency injection configuration successfully.</info>');
-        } catch (OperationException $e) {
-            $output->writeln('<error>' . $e->getMessage() . '</error>');
-        }
     }
 }
diff --git a/setup/src/Magento/Setup/Module/Di/Compiler/Config/Writer/Filesystem.php b/setup/src/Magento/Setup/Module/Di/Compiler/Config/Writer/Filesystem.php
index eeccf5525bad6b37842c47afcde4489e2fdb0fa9..c90c1582bc57b95e1dbca5aab0bc861490bf564b 100644
--- a/setup/src/Magento/Setup/Module/Di/Compiler/Config/Writer/Filesystem.php
+++ b/setup/src/Magento/Setup/Module/Di/Compiler/Config/Writer/Filesystem.php
@@ -7,10 +7,26 @@
 
 namespace Magento\Setup\Module\Di\Compiler\Config\Writer;
 
+use Magento\Framework\App\Filesystem\DirectoryList;
 use Magento\Setup\Module\Di\Compiler\Config\WriterInterface;
 
 class Filesystem implements WriterInterface
 {
+    /**
+     * @var DirectoryList
+     */
+    private $directoryList;
+
+    /**
+     * Constructor
+     *
+     * @param DirectoryList $directoryList
+     */
+    public function __construct(DirectoryList $directoryList)
+    {
+        $this->directoryList = $directoryList;
+    }
+
     /**
      * Writes config in storage
      *
@@ -23,7 +39,7 @@ class Filesystem implements WriterInterface
         $this->initialize();
 
         $serialized = serialize($config);
-        file_put_contents(BP . '/var/di/' . $key . '.ser', $serialized);
+        file_put_contents($this->directoryList->getPath(DirectoryList::DI) . '/' . $key . '.ser', $serialized);
     }
 
     /**
@@ -33,8 +49,8 @@ class Filesystem implements WriterInterface
      */
     private function initialize()
     {
-        if (!file_exists(BP . '/var/di')) {
-            mkdir(BP . '/var/di');
+        if (!file_exists($this->directoryList->getPath(DirectoryList::DI))) {
+            mkdir($this->directoryList->getPath(DirectoryList::DI));
         }
     }
 }
diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/DiCompileCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/DiCompileCommandTest.php
index 068093ba88850470fc10e99ff0ec0c29ee384217..b2c5e9a65254d11e3eb2a18f778a9276c022aed1 100644
--- a/setup/src/Magento/Setup/Test/Unit/Console/Command/DiCompileCommandTest.php
+++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/DiCompileCommandTest.php
@@ -48,7 +48,14 @@ class DiCompileCommandTest extends \PHPUnit_Framework_TestCase
         );
         $objectManagerProvider->expects($this->once())->method('get')->willReturn($this->objectManager);
         $this->manager = $this->getMock('Magento\Setup\Module\Di\App\Task\Manager', [], [], '', false);
-        $this->command = new DiCompileCommand($this->deploymentConfig, $this->manager, $objectManagerProvider);
+        $directoryList = $this->getMock('Magento\Framework\App\Filesystem\DirectoryList', [], [], '', false);
+        $directoryList->expects($this->exactly(3))->method('getPath');
+        $this->command = new DiCompileCommand(
+            $this->deploymentConfig,
+            $directoryList,
+            $this->manager,
+            $objectManagerProvider
+        );
     }
 
     public function testExecuteNotInstalled()