deepl-dotnet icon indicating copy to clipboard operation
deepl-dotnet copied to clipboard

Is it meant to be used in dependency injection or not?

Open tasutafat opened this issue 2 years ago • 6 comments

Hello there, I was just wondering if it makes sense to create one Translator and use dependency injection to get it to the classes it's needed in or if there should be a new Translator each time it is needed?

Best regards, tasutafat

tasutafat avatar Feb 24 '23 11:02 tasutafat

Hello, on a technical level: The overhead to create multiple Translators itself is pretty low, the only thing is that multiple Translator objects would create multiple HTTP sessions (which is a bit of overhead). I think the main question here is just an architectural decision. By default I would lean towards creating a single Translator which you can expose to your Application as a singleton or something similar.

JanEbbing avatar Feb 24 '23 12:02 JanEbbing

Thank you very much for your response! I will add it to my Service collection!

tasutafat avatar Feb 24 '23 22:02 tasutafat

@daniel-jones-deepl, @JanEbbing, would you evaluate the possibility to add some service collection extensions? I wrote a small POC in this PR #28.

antoniovalentini avatar Mar 05 '23 15:03 antoniovalentini

Hey @antoniovalentini

Is this what you had in mind?

https://github.com/DeepLcom/deepl-dotnet/blob/issue-26%2B29/src/DeepL.Service/DeepLService.cs

How to use it: https://github.com/DeepLcom/deepl-dotnet/blob/75fd2c6c062ef2c9ab145d953d7ede79f419fd07/samples/ASP.NET/Program.cs#L19

DeeJayTC avatar Apr 18 '23 12:04 DeeJayTC

Hey @DeeJayTC, yes that's what I had in mind. Since you're integrating this into the development branch, I think my PR is not useful anymore. Should I close it?

antoniovalentini avatar Apr 21 '23 07:04 antoniovalentini

Yea, i alread had it sitting here unfinished. Your PR reminded me to get it done! 😇

DeeJayTC avatar Apr 21 '23 07:04 DeeJayTC