# Getting PerspectiveContext

**URL:** <https://forum.inductiveautomation.com/t/getting-perspectivecontext/73834>\
**Category:** Module Development\
**Tags:** ignition81, perspective\
**Created:** [May 17, 2023, 12:36pm UTC](https://forum.inductiveautomation.com/t/getting-perspectivecontext/73834 "2023-05-17T12:36:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robert\_McIlvenna](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/robert_mcilvenna/32/80238_2.png) [@Robert\_McIlvenna](https://forum.inductiveautomation.com/u/Robert_McIlvenna)\
**Post date:** [May 17, 2023, 12:36pm UTC](https://forum.inductiveautomation.com/t/getting-perspectivecontext/73834/1 "2023-05-17T12:36:22Z")

</div>

I'm trying to find how many Perspective sessions are currently open with Session Monitor. I've tried to use PerspectiveContext.get(context) inside GatewayHook, but it causes the module to fault. Is there some reason this can't be called in setup()?

I'm not sure of where to go from here and can't find very much on why it wouldn't work. If you know the proper way to use it or why it might cause problems please do reply with it, thanks

---

<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:** [May 17, 2023, 1:09pm UTC](https://forum.inductiveautomation.com/t/getting-perspectivecontext/73834/2 "2023-05-17T13:09:15Z")

</div>

> [@Robert\_McIlvenna](#):
>
> some reason this can't be called in setup()?

It isn't an independent singleton in the same way as Ignition's gateway context. If you look at the [static method definition](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.1/com/inductiveautomation/perspective/gateway/api/PerspectiveContext.html#get(com.inductiveautomation.ignition.gateway.model.GatewayContext)), you'll find it needs one argument.

---

<div class="post-metadata">

**Author:** ![Robert\_McIlvenna](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/robert_mcilvenna/32/80238_2.png) [@Robert\_McIlvenna](https://forum.inductiveautomation.com/u/Robert_McIlvenna)\
**Post date:** [May 17, 2023, 1:35pm UTC](https://forum.inductiveautomation.com/t/getting-perspectivecontext/73834/3 "2023-05-17T13:35:03Z")

</div>

Yes, I have supplied the argument  
public void setup(GatewayContext gatewayContext) {

```
 this.context = gatewayContext;
 logger.info("setup()");

 PerspectiveContext pc = PerspectiveContext.get(gatewayContext);

```

Then in the gateway, it faults, giving the error:

Faulted  
com/. . . /perspective/common/PerspectiveModuleRpc

---

<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:** [May 17, 2023, 1:41pm UTC](https://forum.inductiveautomation.com/t/getting-perspectivecontext/73834/4 "2023-05-17T13:41:44Z")

</div>

Does your module declare the Perspective module as a dependency?

If it does, and this still doesn't work, you'll just have to try doing it later in the hook. Maybe in `startup()` instead.

---

<div class="post-metadata">

**Author:** ![Robert\_McIlvenna](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/robert_mcilvenna/32/80238_2.png) [@Robert\_McIlvenna](https://forum.inductiveautomation.com/u/Robert_McIlvenna)\
**Post date:** [May 17, 2023, 1:47pm UTC](https://forum.inductiveautomation.com/t/getting-perspectivecontext/73834/5 "2023-05-17T13:47:16Z")

</div>

Sorry, still learning module development. How do I declare Perspective as a dependency?

Putting in startup caused an exception, so I'll try that and see if it still happens.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [May 17, 2023, 2:50pm UTC](https://forum.inductiveautomation.com/t/getting-perspectivecontext/73834/6 "2023-05-17T14:50:07Z")

</div>

Are you building with Maven, Gradle, or something else?

With the first two, you need to adjust the Ignition module plugin settings in your build files to have perspective as a dependency in the output module XML. It should be fairly straightforward to set up.

If you're using some other build tool, that's still what you have to do, but there's no convenient module plugin available.

---

<div class="post-metadata">

**Author:** ![Robert\_McIlvenna](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/robert_mcilvenna/32/80238_2.png) [@Robert\_McIlvenna](https://forum.inductiveautomation.com/u/Robert_McIlvenna)\
**Post date:** [May 17, 2023, 4:36pm UTC](https://forum.inductiveautomation.com/t/getting-perspectivecontext/73834/7 "2023-05-17T16:36:15Z")

</div>

Ah, was using maven. Thanks for the help, was able to find [SDK transfert data from gateway to perspective - Module Development - Inductive Automation Forum](https://forum.inductiveautomation.com/t/sdk-transfert-data-from-gateway-to-perspective/36349/11)  
Once I got

```auto
                    <depends>
                        <depend>
                            <scope>G</scope>
                            <moduleId>com.inductiveautomation.perspective</moduleId>
                        </depend>
                        <depend>
                            <scope>D</scope>
                            <moduleId>com.inductiveautomation.perspective</moduleId>
                        </depend>
                    </depends>

```

in the gateway pom it worked
