# Get Gateway Context

**URL:** <https://forum.inductiveautomation.com/t/get-gateway-context/83376>\
**Category:** Module Development\
**Tags:** sdk\
**Created:** [December 20, 2023, 3:40pm UTC](https://forum.inductiveautomation.com/t/get-gateway-context/83376 "2023-12-20T15:40:18Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![BenS](https://avatars.discourse-cdn.com/v4/letter/b/9fc348/32.png) [@BenS](https://forum.inductiveautomation.com/u/BenS)\
**Post date:** [December 20, 2023, 3:40pm UTC](https://forum.inductiveautomation.com/t/get-gateway-context/83376/1 "2023-12-20T15:40:18Z")

</div>

Hello,

I am running into an issue when getting the gateway context while developing a module to write to tags.

The SDK example for writing to tags (located at [Read and Write Tags | Ignition SDK Programmer's Guide](https://www.sdk-docs.inductiveautomation.com/docs/appendix/tag-examples/read-and-write-tags)) begins with the following code:

```auto
private void writeReadTagValue() throws Exception {    
    IgnitionGateway context = IgnitionGateway.get();
    GatewayTagManager tagManager = context.getTagManager();
    TagProvider provider = tagManager.getTagProvider("default"); 

```

I have been unable to find the proper library for the IgnitionGateway class. Could you point me to the library I need to include?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [December 20, 2023, 3:42pm UTC](https://forum.inductiveautomation.com/t/get-gateway-context/83376/2 "2023-12-20T15:42:20Z")

</div>

Modules are given the `GatewayContext` in their `setup` methods. You should store it and/or pass it around.

`IgnitionGateway` is a private class.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 20, 2023, 3:42pm UTC](https://forum.inductiveautomation.com/t/get-gateway-context/83376/3 "2023-12-20T15:42:33Z")

</div>

Hmmm. Don't know why those example use `IgnitionGateway.get()`. Modules are handed a module context during setup, and are expected to save it for anything like this. (Module context is a thin wrapper around a gateway context.)

{ Sigh. Sniped. }

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [December 20, 2023, 3:44pm UTC](https://forum.inductiveautomation.com/t/get-gateway-context/83376/4 "2023-12-20T15:44:04Z")

</div>

> [@pturmel](#):
>
> Hmmm. Don't know why those example use `IgnitionGateway.get()`

The SDK doc refresh is being spearheaded by people with good intentions but the only involvement the dev team has is consultative / in review, AFAIK. It's not ideal, but we're all busy with 8.3 stuff ☹

---

<div class="post-metadata">

**Author:** ![BenS](https://avatars.discourse-cdn.com/v4/letter/b/9fc348/32.png) [@BenS](https://forum.inductiveautomation.com/u/BenS)\
**Post date:** [December 20, 2023, 3:57pm UTC](https://forum.inductiveautomation.com/t/get-gateway-context/83376/5 "2023-12-20T15:57:47Z")

</div>

Got it, thanks for the replies. The tag writing function is in a separate class from the GatewayHook, but still in the gateway scope. Since the context is set in the GatewayHook class, is there a recommended way to pass it over to the class with the tag writing function?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [December 20, 2023, 4:02pm UTC](https://forum.inductiveautomation.com/t/get-gateway-context/83376/6 "2023-12-20T16:02:39Z")

</div>

> [@BenS](#):
>
> is there a recommended way to pass it over to the class with the tag writing function?

You can make the GatewayContext available as a static/global variable in your hook, or you can pass it via constructor, or you can do whatever other thing you want. It's just a programming decision, not an Ignition SDK decision. Pretend you needed to make the choice in a scenario that didn't involve Ignition at all.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [December 20, 2023, 4:24pm UTC](https://forum.inductiveautomation.com/t/get-gateway-context/83376/7 "2023-12-20T16:24:20Z")

</div>

> [@Kevin.Herron](#):
>
> The SDK doc refresh is being spearheaded by people with good intentions but the only involvement the dev team has is consultative / in review

I was being a little unfair here.

All the docs start with this comment:

```auto
// This code example is Gateway scoped and assumes the `GatewayContext` object is available.

```

though it could be more clear that `IgnitionGateway.get()` is not how you actually get the context object, by passing `GatewayContext` as a param to the example function and truly leaving it as an exercise to the reader.

---

<div class="post-metadata">

**Author:** ![Mathias\_Melling](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mathias_melling/32/67682_2.png) [@Mathias\_Melling](https://forum.inductiveautomation.com/u/Mathias_Melling)\
**Post date:** [January 10, 2024, 8:27pm UTC](https://forum.inductiveautomation.com/t/get-gateway-context/83376/8 "2024-01-10T20:27:43Z")

</div>

Is `IgnitionGateway` the name of the GatewayHook in the example?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 10, 2024, 8:37pm UTC](https://forum.inductiveautomation.com/t/get-gateway-context/83376/9 "2024-01-10T20:37:17Z")

</div>

No, it is the name of the IA non-documented class that **implements** the gateway context interface for the whole gateway. You should not use it in any module code. Use the gateway context instance that your gateway hook is handed during startup.
