Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sample Code does not register analytics client as singleton #115

Open
dzins opened this issue Nov 22, 2024 · 1 comment
Open

Sample Code does not register analytics client as singleton #115

dzins opened this issue Nov 22, 2024 · 1 comment
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@dzins
Copy link

dzins commented Nov 22, 2024

Describe the bug
Your sample code for both Asp.Net and Asp.Net MVC you register the analytics client as scoped which effectively makes them per request but from what I am gathering it seems like it should be registered as a singleton, why are they registered as scoped?

Can you update somewhere in your documentation explicitly stating that the analytics client is thread safe and can be registered as a singleton (if that is the case) and then change your sample code to register them as singletons?

To Reproduce
Steps to reproduce the behavior:
This sample code:
https://github.com/segmentio/Analytics-CSharp/blob/main/Samples/AspNetMvcSample/Startup.cs
https://github.com/segmentio/Analytics-CSharp/blob/main/Samples/AspNetSample/Startup.cs

Expected behavior
They should be registering the analytics client as a singleton.

@wenxi-zeng
Copy link
Contributor

hi @dzins thanks for reporting this. whether to make it scoped or singleton depends on your use case. we do have customers prefer to do it purely stateless. you could also define your own flush behavior with scoped instance. the example only showcases one of the use cases. but you're right, I do feel the docs should be more elaborated on the options and their implications. will get the docs updated.

and yes, the client is thread safe. we built a thread management SDK to supervise all thread usages. they are disposed when the client is disposed. if you've observed any memory leak or thread issues, please let us know. thanks!

@wenxi-zeng wenxi-zeng added the documentation Improvements or additions to documentation label Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants