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

Announcements

No record found.

News and Announcements icon
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,813 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
    305,150 Super User 2026 Season 1 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
    305,150 Super User 2026 Season 1 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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

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

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 804

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 639 Super User 2026 Season 1

#3
Subra Profile Picture

Subra 528

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans