{"id":485,"date":"2024-11-22T18:14:48","date_gmt":"2024-11-22T18:14:48","guid":{"rendered":"https:\/\/docs.sisus.co\/init-args\/?p=485"},"modified":"2025-07-14T19:30:16","modified_gmt":"2025-07-14T19:30:16","slug":"service-defining-type","status":"publish","type":"post","link":"https:\/\/docs.sisus.co\/init-args\/reference\/service-defining-type\/","title":{"rendered":"Service Defining Type"},"content":{"rendered":"<p>When you register a <a href=\"https:\/\/docs.sisus.co\/init-args\/reference\/global-services\/\">global<\/a> or a <a href=\"https:\/\/docs.sisus.co\/init-args\/reference\/local-services\/\">local service<\/a>, you will always have to specify &#8211; either implicitly or explicitly &#8211; one or more defining types for it.<\/p>\n<p>In the below example, the Logger class is configured to be a global service with the defining types Logger and ILogger, by explicitly specifying the types in the constructor of the [Service] attribute:<\/p>\n<pre>[Service(typeof(Logger), typeof(ILogger))]\r\nclass Logger : ILogger { }<\/pre>\n<p>Components that derive from <a href=\"https:\/\/docs.sisus.co\/init-args\/features\/monobehaviour-t\/\">MonoBehaviour&lt;T&#8230;&gt;<\/a> will automatically receive a global service as an Init method argument, if the type of the argument matches one of the defining types of the service.<\/p>\n<pre>class ClientA : MonoBehaviour&lt;ILogger&gt;\r\n{\r\n     protected override void Init(ILogger logger) =&gt; Debug.Log($\"ClientA received {logger}.\");\r\n}\r\n\r\nclass ClientB : MonoBehaviour&lt;Logger&gt;\r\n{\r\n     protected override void Init(Logger logger) =&gt; Debug.Log($\"ClientB received {logger}.\");\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>When you register a global or a local service, you will always have to specify &#8211; either implicitly or explicitly &#8211; one or more defining types for it. In the below example, the Logger class is configured to be a global service with the defining types Logger and ILogger, by explicitly specifying the types in ..<\/p>\n<div class=\"clear-fix\"><\/div>\n<p><a href=\"https:\/\/docs.sisus.co\/init-args\/reference\/service-defining-type\/\" 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\/485"}],"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=485"}],"version-history":[{"count":5,"href":"https:\/\/docs.sisus.co\/init-args\/wp-json\/wp\/v2\/posts\/485\/revisions"}],"predecessor-version":[{"id":802,"href":"https:\/\/docs.sisus.co\/init-args\/wp-json\/wp\/v2\/posts\/485\/revisions\/802"}],"wp:attachment":[{"href":"https:\/\/docs.sisus.co\/init-args\/wp-json\/wp\/v2\/media?parent=485"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.sisus.co\/init-args\/wp-json\/wp\/v2\/categories?post=485"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.sisus.co\/init-args\/wp-json\/wp\/v2\/tags?post=485"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}