fix(service): add service constructor arguments

This commit is contained in:
Simon Vieille
2025-03-10 18:41:09 +01:00
parent 3058c225e0
commit 44fd4fab52
+28 -6
View File
@@ -3,6 +3,7 @@
namespace OCA\SideMenu\AppInfo; namespace OCA\SideMenu\AppInfo;
use OC; use OC;
use OC\App\AppStore\Fetcher\CategoryFetcher;
use OC\Security\CSP\ContentSecurityPolicyNonceManager; use OC\Security\CSP\ContentSecurityPolicyNonceManager;
use OC\User\User; use OC\User\User;
use OCA\SideMenu\Service\AppRepository; use OCA\SideMenu\Service\AppRepository;
@@ -12,8 +13,13 @@ use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\INavigationManager;
use OCP\IUserSession; use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\Util; use OCP\Util;
use Psr\Container\ContainerInterface;
/** /**
* class Application. * class Application.
@@ -48,16 +54,32 @@ class Application extends App implements IBootstrap
public function register(IRegistrationContext $context): void public function register(IRegistrationContext $context): void
{ {
$context->registerService('AppRepository', function () { $context->registerService(CategoryRepository::class, function (ContainerInterface $c) {
return new AppRepository(); return new CategoryRepository(
$c->get(CategoryFetcher::class),
$c->get(ConfigProxy::class),
$c->get(IConfig::class),
$c->get(IFactory::class),
$c->get(IUserSession::class)
);
}); });
$context->registerService('CategoryRepository', function () { $context->registerService(AppRepository::class, function (ContainerInterface $c) {
return new CategoryRepository(); return new AppRepository(
$c->get(\OC_App::class),
$c->get(INavigationManager::class),
$c->get(IFactory::class),
$c->get(ConfigProxy::class),
$c->get(CategoryRepository::class),
$c->get(IEventDispatcher::class),
$c->get(IUserSession::class)
);
}); });
$context->registerService('ConfigProxy', function () { $context->registerService(ConfigProxy::class, function (ContainerInterface $c) {
return new ConfigProxy(); return new ConfigProxy(
$c->get(IConfig::class),
);
}); });
} }