# Accessing ManagedTagProvider from Servlet

**URL:** <https://forum.inductiveautomation.com/t/accessing-managedtagprovider-from-servlet/64032>\
**Category:** Module Development\
**Created:** [September 13, 2022, 11:35pm UTC](https://forum.inductiveautomation.com/t/accessing-managedtagprovider-from-servlet/64032 "2022-09-13T23:35:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bfreeman](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bfreeman/32/87436_2.png) [@bfreeman](https://forum.inductiveautomation.com/u/bfreeman)\
**Post date:** [September 13, 2022, 11:35pm UTC](https://forum.inductiveautomation.com/t/accessing-managedtagprovider-from-servlet/64032/1 "2022-09-13T23:35:08Z")

</div>

Hi,

I’ve been looking at the [Managed Tag Provider SDK example](https://github.com/inductiveautomation/ignition-sdk-examples/tree/master/managed-tag-provider).

I’d like to add a Servlet that would write to tags in the managed tag provider. What is the correct way of accessing the `ManagedTagProvider` inside the Servlet’s methods? Is it to simply copy/paste the [`ProviderConfiguration` from the `ManagedProviderGatewayHook` `setup` method](https://github.com/inductiveautomation/ignition-sdk-examples/blob/ddf234b4a900f28835bf16a350faf265e39f93df/managed-tag-provider/managed-tag-provider-gateway/src/main/java/com/inductiveautomation/ignition/examples/mtp/ManagedProviderGatewayHook.java#L48-L54) and calling `context.getTagManager().getOrCreateManagedProvider(configuration)` again? Or is there a way to share the `ManagedTagProvider` between the `ManagedProviderGatewayHook` and the Servlet?

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:** [September 14, 2022, 12:07am UTC](https://forum.inductiveautomation.com/t/accessing-managedtagprovider-from-servlet/64032/2 "2022-09-14T00:07:00Z")

</div>

Servlets are instantiated with their no-args constructor by the webserver infrastructure itself. Which means the only way for your servlet to access anything else is via static methods, either on your servlet (where your managed tag provider instance is set on the servlet), or on your gateway hook, where your hook sets static fields with the appropriate information and provides a static method to read them. Or perhaps a static field to hold the one instance of the gateway hook itself. Or possibly your module context.

---

<div class="post-metadata">

**Author:** ![bfreeman](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bfreeman/32/87436_2.png) [@bfreeman](https://forum.inductiveautomation.com/u/bfreeman)\
**Post date:** [September 14, 2022, 11:34am UTC](https://forum.inductiveautomation.com/t/accessing-managedtagprovider-from-servlet/64032/3 "2022-09-14T11:34:01Z")

</div>

I see. Thank you for the explanation!  
How does the module context work?

---

<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:** [September 14, 2022, 12:13pm UTC](https://forum.inductiveautomation.com/t/accessing-managedtagprovider-from-servlet/64032/4 "2022-09-14T12:13:25Z")

</div>

In most of my modules, the gateway hook has a private static field named `myContext` and a public static method `getMyContext`. The field is assigned by the `setup()` method. Other parts of the module can get the module context from the static method any time after that.

---

<div class="post-metadata">

**Author:** ![bfreeman](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bfreeman/32/87436_2.png) [@bfreeman](https://forum.inductiveautomation.com/u/bfreeman)\
**Post date:** [September 14, 2022, 9:43pm UTC](https://forum.inductiveautomation.com/t/accessing-managedtagprovider-from-servlet/64032/5 "2022-09-14T21:43:11Z")

</div>

Interesting. Thanks for the tip!
