{"id":22569380,"url":"https://github.com/rsaz/servicelocator","last_synced_at":"2025-10-12T13:23:14.728Z","repository":{"id":118950853,"uuid":"436900008","full_name":"rsaz/ServiceLocator","owner":"rsaz","description":"Service Locator Pattern Header-Only Library","archived":false,"fork":false,"pushed_at":"2022-01-11T00:54:34.000Z","size":26,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-12T13:23:12.321Z","etag":null,"topics":["cpp","header-only","service-locator-pattern","slocator"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rsaz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-12-10T08:10:11.000Z","updated_at":"2024-03-17T03:29:03.000Z","dependencies_parsed_at":"2023-03-16T16:45:17.126Z","dependency_job_id":null,"html_url":"https://github.com/rsaz/ServiceLocator","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rsaz/ServiceLocator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rsaz%2FServiceLocator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rsaz%2FServiceLocator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rsaz%2FServiceLocator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rsaz%2FServiceLocator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rsaz","download_url":"https://codeload.github.com/rsaz/ServiceLocator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rsaz%2FServiceLocator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279011465,"owners_count":26084947,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-12T02:00:06.719Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","header-only","service-locator-pattern","slocator"],"created_at":"2024-12-08T00:19:33.221Z","updated_at":"2025-10-12T13:23:14.715Z","avatar_url":"https://github.com/rsaz.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Service Locator\nVery fast, header-only C++ Service Locator Pattern library\n\n### What is the Service Locator Pattern\nThe Service Locator Pattern is a design pattern that encapsulates the processes involved in obtaining a service with a strong abstraction layer. This pattern uses a central registry know as the \"Service Locator\" to request either Singleton instances or make use of a factory to generate instances of a particular type. This pattern simplifies component-based application where all applications dependencies are cleanly listed at the beggining of the application boostrap.\n\n### Motivation\nTo simplify the classes relationships and dependencies, defining a single point of class registration and request. To reduce software development complexity\n\n### Advantages\n- Simplifies the use of singleton and static objects\n- Centralize the use of objects in one class called locator\n- The code is easy to test\n\n### Install\n##### Copy the includes [folder](https://github.com/rsaz/ServiceLocator/tree/master/include/slocator) to your build tree and use a C++ compilter \u003e= 11\n```\n\n$ git clone https://github.com/rsaz/ServiceLocator.git\n\n```\n### Platforms\n- Windows (msvc 2013+, cygwin)\n\n### Package Manager\n\n### Features\n- Register service ```RegisterService\u003ctype\u003e()```\n- Unregister service ```UnregisterService\u003ctype\u003e()```\n- Request service ```Get\u003ctype\u003e()```\n- Request service list ```ServicesList()```\n- Register service factory ```RegisterServiceFactory\u003ctype\u003e()```\n- Unregister service factory ```UnregisterServiceFactory\u003ctype\u003e()```\n- Request service factory ```Get\u003ctype\u003e()```\n- Request service factory list ```ServicesFactoryList()```\n\n### Usage examples\n```c++\n // Class Examples\nusing Locator::ServiceLocator;\n\n#pragma region Classes Examples\nclass ILogger\n{\npublic:\n\tvirtual void Info(const std::string\u0026 message) = 0;\n};\n\nclass Logger : public ILogger\n{\npublic:\n\t// Inherited via ILogger\n\tvirtual void Info(const std::string\u0026 message) override\n\t{\n\t\tstd::cout \u003c\u003c message \u003c\u003c std::endl;\n\t}\n};\n\nclass IConfiguration\n{\npublic:\n\tvirtual void Load() = 0;\n};\n\nclass Configuration : public IConfiguration\n{\npublic:\n\tvoid Load()\n\t{\n\t\tstd::cout \u003c\u003c \"Loading configuration\\n\";\n\t}\n};\n#pragma endregion\n\nauto main() -\u003e int\n{\n\t// Service Locator initialization\n\tauto locator = std::make_unique\u003cServiceLocator\u003e();\n\n\t// Service Registration\n\tlocator-\u003eRegisterService\u003cLogger\u003e();\n\tlocator-\u003eRegisterService\u003cConfiguration\u003e();\n\t\n\t// Check double registration\n\tlocator-\u003eRegisterService\u003cLogger\u003e();\n\n\t// Request the service\n\tauto logger1 = locator-\u003eGet\u003cLogger\u003e();\n\n\t// Guarantee same instance\n\tauto logger2 = locator-\u003eGet\u003cLogger\u003e();\n\tlogger1-\u003eInfo(\"information\");\n\tlogger2-\u003eInfo(\"information\");\n\n\t// Check Unregister Singleton Service\n\tlocator-\u003eServicesList();\n\tlocator-\u003eUnregisterService\u003cLogger\u003e();\n\tlocator-\u003eServicesList();\n\n\t// Clear all services (Singleton and Transients)\n\tlocator-\u003eClear();\n\n\t// Service Factory Creation\n\tlocator-\u003eRegisterServiceFactory\u003cConfiguration\u003e();\n\t\n\t// Get a new instance upon each request\n\tauto config1 = locator-\u003eGet\u003cConfiguration\u003e();\n\tauto config2 = locator-\u003eGet\u003cConfiguration\u003e();\n\tconfig1-\u003eLoad();\n\tconfig2-\u003eLoad();\n\n\t// Check Unregister Factory Services\n\tlocator-\u003eServicesFactoryList();\n\tlocator-\u003eUnregisterServiceFactory\u003cConfiguration\u003e();\n\tlocator-\u003eServicesFactoryList();\n\n\treturn 0;\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frsaz%2Fservicelocator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frsaz%2Fservicelocator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frsaz%2Fservicelocator/lists"}