DeepLcom / deepl-dotnet

Official .NET library for the DeepL language translation API.
MIT License
181 stars 26 forks source link

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

Open tasutafat opened 1 year ago

tasutafat commented 1 year ago

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

JanEbbing commented 1 year ago

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.

tasutafat commented 1 year ago

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

antoniovalentini commented 1 year ago

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

DeeJayTC commented 1 year ago

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

antoniovalentini commented 1 year ago

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?

DeeJayTC commented 1 year ago

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