web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

How to create a global singleton

(0) ShareShare
ReportReport
Posted on by 55

Hello community.

what is best practice approach (if existent) to the following problem:

I am using a C# HttpClient in D365. According to the remarks it should be only created once and reused throughout the apllication in order to prevent SocketException errors. I want to approach the problem with the singleton pattern but the implementation of the singleton pattern in D365 is per user session.

My question is:

What is an threadsafe approach to make the C# HttpClient class in D365 application wide avaible and only instantiate it at maximum once (maybe SysGlobal*)?

Thanks in advance and have a nice day,

Oliver

I have the same question (0)
  • Suggested answer
    huijij Profile Picture
    19,811 on at

    Hi sir,

    Please go through the link to see if it helps:

    stackoverflow.com/.../how-do-i-ensure-that-my-httpclient-only-gets-initialized-once-in-c

  • BringYourOwnDeveloper Profile Picture
    55 on at

    Hi Judy,

    thanks for the link.

    They actually resolved the problem via a singleton (in C#), but because singletons in D365 are user session based I will be instated once per user, per tab.

    Are singleton in C# instanced from D365 in the application scope or also in the user session scope?

    With kind regards,

    Oliver

  • BringYourOwnDeveloper Profile Picture
    55 on at

    Bump. Anyone have experience with this?

  • André Arnaud de Calavon Profile Picture
    301,130 Super User 2025 Season 2 on at

    Hi Oliver,

    Is your question related to Dynamics 365 Finance or e.g. Dynamics NAV or Dynamics 365 Business Central?

  • BringYourOwnDeveloper Profile Picture
    55 on at

    Hi Andre,

    my questions is about D365 Finamce and Supply Chain Management.
    If I missed (again) the right forum, I am sorry.
    With kind regards,
    Oliver

  • André Arnaud de Calavon Profile Picture
    301,130 Super User 2025 Season 2 on at

    Hi Oliver,

    You are in the correct forum then. I'm not able to help you on this topic.

  • Alex VN Profile Picture
    1,994 on at

    Hi,

    Regarding this issue, I think you might use SysGlobalCache to store the instance globally. I'm not 100% sure about this but I think it might give you some clues.

    Ref: daxonline.org/1600-singleton-pattern-template.html

    Regards,

    Anh Ong

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 456 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 429 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans