protected function registerEntityAuditConfigurations(Repository $config)
    {
        $this->app->afterResolving(IlluminateRegistry::class, function ($registry) use ($config) {
            $table         = $config->get('entity_audit.global.table');
            $users         = $config->get('entity_audit.global.username_for');
            $columns       = $config->get('entity_audit.global.ignore_columns');
            $auditRegistry = $this->app->make(AuditRegistry::class);

            foreach ($config->get('entity_audit.entity_managers', []) as $emName => $emConfig) {
                $users       = array_merge($users, data_get($emConfig, 'username_for', []));
                $metadata    = new MetadataFactory(data_get($emConfig, 'entities', []));
                $auditConfig = new AuditConfiguration(
                    new UserResolver(
                        $this->app->make(Guard::class),
                        $users['unknown_authenticated_user'],
                        $users['unknown_unauthenticated_user']
                    ),
                    new TableConfiguration(array_merge($table, data_get($emConfig, 'table', []))),
                    data_get($emConfig, 'ignore_columns', $columns)
                );
                /** @var IlluminateRegistry $registry */
                /** @var EntityManager $em */
                $em      = $registry->getManager($emName);
                $reader  = new AuditReader($em, $auditConfig, $metadata);
                $manager = new AuditManager($auditConfig, $metadata, $reader);

                $em->getEventManager()->addEventSubscriber(new CreateSchemaListener($manager));
                $em->getEventManager()->addEventSubscriber(new LogRevisionsListener($manager));

                $auditRegistry->add($emName, $manager);

                $this->app->instance(sprintf('entity_audit.%s.manager', $emName), $manager);
                $this->app->instance(sprintf('entity_audit.%s.reader', $emName), $reader);
            }
        });
    }