1"use strict";(globalThis.webpackChunkkoin_website||=[]).push([[1876],{9682(e,n,i){i.r(n),i.d(n,{assets:()=>c,contentTitle:()=>a,default:()=>x,frontMatter:()=>r,metadata:()=>o,toc:()=>d});const o=JSON.parse('{"id":"reference/koin-core/extension-manager","title":"Extension Manager","description":"Here is a brief description of KoinExtension manager, dedicated to add new features inside Koin framework.","source":"@site/versioned_docs/version-4.0/reference/koin-core/extension-manager.md","sourceDirName":"reference/koin-core","slug":"/reference/koin-core/extension-manager","permalink":"/docs/4.0/reference/koin-core/extension-manager","draft":false,"unlisted":false,"editUrl":"https://github.com/InsertKoinIO/koin/tree/main/versioned_docs/version-4.0/reference/koin-core/extension-manager.md","tags":[],"version":"4.0","frontMatter":{"title":"Extension Manager"}}');var t=i(4848),s=i(8453);const r={title:"Extension Manager"},a=void 0,c={},d=[{value:"Defining an extension",id:"defining-an-extension",level:2},{value:"Starting an extension",id:"starting-an-extension",level:2}];function l(e){const n={code:"code",h2:"h2",p:"p",pre:"pre",...(0,s.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(n.p,{children:["Here is a brief description of ",(0,t.jsx)(n.code,{children:"KoinExtension"})," manager, dedicated to add new features inside Koin framework."]}),"\n",(0,t.jsx)(n.h2,{id:"defining-an-extension",children:"Defining an extension"}),"\n",(0,t.jsxs)(n.p,{children:["A Koin extension consist in having a class inheriting from ",(0,t.jsx)(n.code,{children:"KoinExtension"})," interface:"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-kotlin",children:"interface KoinExtension {\n \n var koin : Koin\n \n fun onClose()\n}\n"})}),"\n",(0,t.jsxs)(n.p,{children:["this interface allow to ensure you get passed a ",(0,t.jsx)(n.code,{children:"Koin"})," instance, and the extension is called when Koin is closing."]}),"\n",(0,t.jsx)(n.h2,{id:"starting-an-extension",children:"Starting an extension"}),"\n",(0,t.jsxs)(n.p,{children:["To start an extension, just extend the right place of the system, and register it with ",(0,t.jsx)(n.code,{children:"Koin.extensionManager"}),"."]}),"\n",(0,t.jsxs)(n.p,{children:["Below here is how we define the ",(0,t.jsx)(n.code,{children:"coroutinesEngine"})," extension:"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-kotlin",children:"fun KoinApplication.coroutinesEngine() {\n with(koin.extensionManager) {\n if (getExtensionOrNull<KoinCoroutinesEngine>(EXTENSION_NAME) == null) {\n registerExtension(EXTENSION_NAME, KoinCoroutinesEngine())\n }\n }\n}\n"})}),"\n",(0,t.jsxs)(n.p,{children:["Below here is how we call the ",(0,t.jsx)(n.code,{children:"coroutinesEngine"})," extension:"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-kotlin",children:"val Koin.coroutinesEngine: KoinCoroutinesEngine get() = extensionManager.getExtension(EXTENSION_NAME)\n"})})]})}function x(e={}){const{wrapper:n}={...(0,s.R)(),...e.components};return n?(0,t.jsx)(n,{...e,children:(0,t.jsx)(l,{...e})}):l(e)}},8453(e,n,i){i.d(n,{R:()=>r,x:()=>a});var o=i(6540);const t={},s=o.createContext(t);function r(e){const n=o.useContext(s);return o.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function a(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(t):e.components||t:r(e.components),o.createElement(s.Provider,{value:n},e.children)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.