title: Getting Current context in Oak with Typescript Class Syntax
body: <p>I'm struggling with the following scenario using Deno with Oak.
  Most tutorials use export <code>const xy = () =&gt; {}</code> syntax, when they separate controllers and routes.</p>
  <p>In the route then they commonly have something like <code>router.get(&quot;/the-route&quot;, xy)</code>, which is fine, but has several caveats that I want to avoid.</p>
  <h3 id="what-i-dont-want-nnk6">What I don't want</h3>
  <p>Look at this example:</p>
  <pre class="lang-js prettyprint-override"><code>const someController = async ({
    request,
    response,
  }: {
    request: any;
    response: any;
  }) =&gt; {
    // do something
  }
  </code></pre>
  <p>1.) request and response are explicitly &quot;any&quot;, which I try to avoid since there is no typesafty and no code-completion availabe.
  2.) I want to do this in a class-syntax with an extendable base-controller from which other classes are derived.</p>
  <h3 id="what-i-messed-up-gu8v">What I messed up</h3>
  <p>So currently I ended up with something like this (which is pretty senseless):</p>
  <pre class="lang-js prettyprint-override"><code>import type { RouterContext } from &quot;https://deno.land/x/oak@v8.0.0/mod.ts&quot;;
  
  export class BaseController {
    // deno-lint-ignore no-explicit-any
    protected ctx: RouterContext&lt;{ id: string }, Record&lt;string, any&gt;&gt;;
  
    // deno-lint-ignore no-explicit-any
    constructor(ctx: RouterContext&lt;{ id: string }, Record&lt;string, any&gt;&gt;) {
      this.ctx = this.getContext(ctx);
    }
  
    // deno-lint-ignore no-explicit-any
    getContext = (ctx: RouterContext&lt;{ id: string }, Record&lt;string, any&gt;&gt;) =&gt; {
      return ctx;
    };
  }
  </code></pre>
  <p>As you can see this does pretty much nothing but receiving some context passed down to the controller, which doesn't make any sense, since</p>
  <ol>
  <li>I need to do something like <code>router.get(&quot;/&quot;, (ctx) =&gt; { SomeController.createSomething(ctx) })</code> in my routes.</li>
  <li>I need to pass the context everywhere (which clearly is not the goal). If I extended a class with <code>BaseController</code> that has a constructor on it's own I even need to pass the context here with <code>super(ctx : UltraLongType&lt;ThatIDontWantHere&gt;)</code></li>
  </ol>
  <h3 id="what-i-really-want-to-achieve-tiw4">What I really want to achieve</h3>
  <p>Long story short: What I really want to do is to have <code>BaseController.getContext</code> really GET the current context without passing it everywhere.</p>
  <p>I unfortunately can't find some helper or injector or whatever service to receive the current RouterContext from &quot;outside&quot;.</p>
  <p>And I really don't get my head wrapped around this.</p>
  <p>Maybe someone can help me with this :)</p>
  <p>Thanks in advance and best regards :)</p>