-
Notifications
You must be signed in to change notification settings - Fork 10
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
Use ISerializerService in Dependency Injection Setup #221
Comments
We would more likely have to create a marker interface for each of the SerializerService implementations, as they hold specific configurations for the supported API. But overall yes we are open for supporting a interface instead of a specific implementation |
Okay I must say that I don't fully understand the purpose of a marker interface and how and where it is used. But I trust, that you guys know the potential benefits of using it. |
Just opened a PR which adds the API specific marker interfaces. For backwards compatibility the registration of the SerializerService classes are still there, but internally it will be only retrieved by it's interface. So it should be possible to mock or replace them e.g. in tests. We need the marker interfaces as the serialization configuration can be a little bit different and even conflicting between the APIs. |
Hey, perfect! Thank you for the fast implementation. Really appreciate it. I now understand better what you meant by the marker interfaces. After seeing your changes and implementation. Just for my understanding: ...
services.UseCommercetoolsApiSerialization();
... And the use the marker interface in the constructor for example like this: private readonly IApiSerializerService _serializerService;
public ExampleService(IApiSerializerService serializerService)
{
_serializerService = serializerService;
} Thank you a lot again :) |
Yes. That's the idea behind it. And for testing purposes you could inject whatever implementation you mark with the interface ;) |
Is your feature request related to a problem? Please describe.
I want to be able to use the interface
ISerializerService
in constructor injection instead ofSerializerService
, when setting up the SerializerService with Dependency Injection viaservices.UseCommercetoolsApiSerialization();
. Then it would also be better for testing and mocking.Describe the solution you'd like
I would like to change the service registration in the DI setup like this:
Describe alternatives you've considered
Right now I have the current workaround in place to be able to use the interface:
Additional context
Acutally the expected behaviour was introduced within #23 in commit (6c04123) but, also removed in the same PR with commit (0ded78e)
The DI should be the same for:
commercetools.Sdk.Api/DependencyInjectionSetup.cs
,commercetools.Sdk.HistoryApi/DependencyInjectionSetup.cs
,commercetools.Sdk.ImportApi/DependencyInjectionSetup.cs
andcommercetools.Sdk.MLApi/DependencyInjectionSetup.cs
The text was updated successfully, but these errors were encountered: