{"id":446,"date":"2024-10-22T08:00:07","date_gmt":"2024-10-22T08:00:07","guid":{"rendered":"https:\/\/docs.sisus.co\/init-args\/?p=446"},"modified":"2025-07-29T06:27:29","modified_gmt":"2025-07-29T06:27:29","slug":"global-services","status":"publish","type":"post","link":"https:\/\/docs.sisus.co\/init-args\/reference\/global-services\/","title":{"rendered":"Global Services"},"content":{"rendered":"<p><img loading=\"lazy\" class=\" wp-image-914 aligncenter\" src=\"https:\/\/docs.sisus.co\/init-args\/wp-content\/uploads\/sites\/6\/2024\/10\/global-services-1.png\" alt=\"\" width=\"256\" height=\"256\" srcset=\"https:\/\/docs.sisus.co\/init-args\/wp-content\/uploads\/sites\/6\/2024\/10\/global-services-1.png 512w, https:\/\/docs.sisus.co\/init-args\/wp-content\/uploads\/sites\/6\/2024\/10\/global-services-1-300x300.png 300w, https:\/\/docs.sisus.co\/init-args\/wp-content\/uploads\/sites\/6\/2024\/10\/global-services-1-150x150.png 150w\" sizes=\"(max-width: 256px) 100vw, 256px\" \/><\/p>\n<p>Services that can automatically be delivered to <strong><a href=\"https:\/\/docs.sisus.co\/init-args\/clients\/monobehaviour-t\/\">clients<\/a><\/strong> by Init(args) can be split into two groups based on their availability: <strong>global<\/strong> and <strong><a href=\"https:\/\/docs.sisus.co\/init-args\/reference\/local-services\/\">local services<\/a><\/strong>.<\/p>\n<p>A global service is a service that is available to all clients, regardless of their location in the scene hierarchies.<\/p>\n<h2>Registering Global Services<\/h2>\n<p>The main way to register global services is using\u00a0<strong><a href=\"https:\/\/docs.sisus.co\/init-args\/features\/service-attribute\/\">[Service] attribute<\/a><\/strong>.<\/p>\n<p>It&#8217;s also technically possible to create global services using any of the following methods:<\/p>\n<ol>\n<li>Attach the <strong><a href=\"https:\/\/docs.sisus.co\/init-args\/features\/service-tag\/\">Service Tag<\/a><\/strong> to a component in the first scene and set <em>Availability<\/em> to <em>Everywhere<\/em>.<\/li>\n<li>Drag an Object into a <strong><a href=\"https:\/\/docs.sisus.co\/init-args\/features\/services-component\/\">Services component<\/a> <\/strong>in the first scene and set <em>For Clients<\/em>\u00a0to <em>Everywhere<\/em>.<\/li>\n<li>Manually register an object as a service by calling <strong><a href=\"https:\/\/docs.sisus.co\/init-args-reference\/class_sisus_1_1_init_1_1_service.html\">Service.Set<\/a>\u00a0<\/strong>during the initialization of the application.<\/li>\n<\/ol>\n<h2>Registering Plain C# Objects<\/h2>\n<p>Plain C# objects can be registered as global services using any the following methods:<\/p>\n<ol>\n<li>By adding the <strong>[Service] attribute<\/strong> directly to its class.<\/li>\n<li>By <a href=\"https:\/\/docs.sisus.co\/init-args\/advanced\/transient-services\/\">adding the <strong>[Service] attribute<\/strong> to a <strong>value provider<\/strong><\/a> class.<\/li>\n<li>By attaching the <strong>Service Tag<\/strong> to a <strong><a href=\"https:\/\/docs.sisus.co\/init-args\/features\/wrapper\/\">Wrapper<\/a><\/strong> that wraps the plain C# object and setting <em>Availability<\/em> to <em>Everywhere<\/em>.<\/li>\n<li>By dragging a <strong><a href=\"https:\/\/docs.sisus.co\/init-args\/reference\/ivalueprovider\/\">value provider<\/a><\/strong> that returns the plain C# object into a <strong><a href=\"https:\/\/docs.sisus.co\/init-args\/features\/services-component\/\">Services component<\/a><\/strong> and setting <em>For Clients<\/em>\u00a0to <em>Everywhere<\/em>.<\/li>\n<li>By manually registering it as a service by calling <strong><a href=\"https:\/\/docs.sisus.co\/init-args-reference\/class_sisus_1_1_init_1_1_service_afa86ad1d7582e8285718d1cfcc2cf061.html\">Service.Set<\/a><\/strong><\/li>\n<\/ol>\n<h2>Best Practices<\/h2>\n<p>Global services should typically exists for the entire lifetime of the application after being initialized. You always want to avoid situations where a client could live longer than one of the services that it depends on. Since all clients can receive global services, destroying or disposing global service after they have already been delivered to some clients is risky.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Services that can automatically be delivered to clients by Init(args) can be split into two groups based on their availability: global and local services. A global service is a service that is available to all clients, regardless of their location in the scene hierarchies. Registering Global Services The main way to register global services is ..<\/p>\n<div class=\"clear-fix\"><\/div>\n<p><a href=\"https:\/\/docs.sisus.co\/init-args\/reference\/global-services\/\" title=\"read more\">Read more<\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7],"tags":[],"_links":{"self":[{"href":"https:\/\/docs.sisus.co\/init-args\/wp-json\/wp\/v2\/posts\/446"}],"collection":[{"href":"https:\/\/docs.sisus.co\/init-args\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.sisus.co\/init-args\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.sisus.co\/init-args\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.sisus.co\/init-args\/wp-json\/wp\/v2\/comments?post=446"}],"version-history":[{"count":15,"href":"https:\/\/docs.sisus.co\/init-args\/wp-json\/wp\/v2\/posts\/446\/revisions"}],"predecessor-version":[{"id":992,"href":"https:\/\/docs.sisus.co\/init-args\/wp-json\/wp\/v2\/posts\/446\/revisions\/992"}],"wp:attachment":[{"href":"https:\/\/docs.sisus.co\/init-args\/wp-json\/wp\/v2\/media?parent=446"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.sisus.co\/init-args\/wp-json\/wp\/v2\/categories?post=446"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.sisus.co\/init-args\/wp-json\/wp\/v2\/tags?post=446"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}