33namespace DirectoryTree \OpenSearchScoutDriver ;
44
55use DirectoryTree \OpenSearchAdapter \Documents \DocumentManager ;
6+ use DirectoryTree \OpenSearchAdapter \Documents \DocumentManagerInterface ;
67use DirectoryTree \OpenSearchAdapter \Indices \IndexManager ;
8+ use DirectoryTree \OpenSearchAdapter \Indices \IndexManagerInterface ;
79use DirectoryTree \OpenSearchClient \OpenSearchManager ;
810use DirectoryTree \OpenSearchScoutDriver \Factories \DocumentFactory ;
911use DirectoryTree \OpenSearchScoutDriver \Factories \DocumentFactoryInterface ;
1012use DirectoryTree \OpenSearchScoutDriver \Factories \ModelFactory ;
1113use DirectoryTree \OpenSearchScoutDriver \Factories \ModelFactoryInterface ;
1214use DirectoryTree \OpenSearchScoutDriver \Factories \SearchRequestFactory ;
1315use DirectoryTree \OpenSearchScoutDriver \Factories \SearchRequestFactoryInterface ;
16+ use Illuminate \Contracts \Foundation \Application ;
1417use Illuminate \Support \ServiceProvider ;
1518use Laravel \Scout \EngineManager ;
1619
@@ -26,17 +29,28 @@ public function register(): void
2629 {
2730 $ this ->mergeConfigFrom (__DIR__ .'/../config/opensearch-scout.php ' , 'opensearch-scout ' );
2831
29- $ this ->app ->bindIf (ModelFactoryInterface::class, ModelFactory::class);
30- $ this ->app ->bindIf (DocumentFactoryInterface::class, DocumentFactory::class);
31- $ this ->app ->bindIf (SearchRequestFactoryInterface::class, SearchRequestFactory::class);
32+ $ this ->app ->bind (ModelFactoryInterface::class, ModelFactory::class);
33+ $ this ->app ->bind (DocumentFactoryInterface::class, DocumentFactory::class);
34+ $ this ->app ->bind (SearchRequestFactoryInterface::class, SearchRequestFactory::class);
3235
33- $ this ->app ->singletonIf (DocumentManager ::class, function ($ app ) {
36+ $ this ->app ->singleton (DocumentManagerInterface ::class, function (Application $ app ) {
3437 return new DocumentManager ($ app ->make (OpenSearchManager::class)->default ());
3538 });
3639
37- $ this ->app ->singletonIf (IndexManager ::class, function ($ app ) {
40+ $ this ->app ->singleton (IndexManagerInterface ::class, function (Application $ app ) {
3841 return new IndexManager ($ app ->make (OpenSearchManager::class)->default ());
3942 });
43+
44+ $ this ->app ->bind (Engine::class, function (Application $ app ) {
45+ return new Engine (
46+ $ app ->make (ModelFactoryInterface::class),
47+ $ app ->make (IndexManagerInterface::class),
48+ $ app ->make (DocumentManagerInterface::class),
49+ $ app ->make (DocumentFactoryInterface::class),
50+ $ app ->make (SearchRequestFactoryInterface::class),
51+ $ app ['config ' ]->get ('opensearch-scout.refresh_documents ' , false ),
52+ );
53+ });
4054 }
4155
4256 /**
@@ -48,7 +62,7 @@ public function boot(): void
4862 __DIR__ .'/../config/opensearch-scout.php ' => config_path ('opensearch-scout.php ' ),
4963 ]);
5064
51- $ this ->app ->make (EngineManager::class)->extend ('opensearch ' , function ($ app ) {
65+ $ this ->app ->make (EngineManager::class)->extend ('opensearch ' , function (Application $ app ) {
5266 return $ app ->make (Engine::class);
5367 });
5468 }
0 commit comments