You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Why we are creating instances using new? Can we register it by dependency injection and inject the IWcfProxy in the constructor.
private readonly IWcfProxy<IPersonService> clientProxy;
public PersonServiceWrapper(string endpointUrl)
{
clientProxy = new WcfProxy<IPersonServiceChannel>(endpointUrl);
}
public CountryServiceWrapper(IWcfProxy<ICountryServiceChannel> proxy)
{
clientProxy = proxy;
}
services.AddScoped<ICountryServiceWrapper>(provider => new CountryServiceWrapper(endpointsConfig.CountryService));
services.AddScoped<IPersonServiceWrapper>(provider => new PersonServiceWrapper(endpointsConfig.PersonService));
Another question is can we use the singleton registration for the WcfProxy class?
services.AddSingleton<IWcfProxy<ICarrierOperationsService>>(service =>
new WcfProxy<ICarrierOperationsServiceChannel>(service
.GetRequiredService<IOptions<ServiceEndpointConfiguration>>().Value.CarrierOperationsService));
The text was updated successfully, but these errors were encountered:
Thanks for there interest! The codebase here is pretty old and was done in a bit of a hurry, that's why the Dependency Injection part of the solution is lacking. You can indeed replace all of the explicit instantiations with injections in your own solution.
As for the second question, I think a singleton approach might be problematic when running multiple WcfProxy calls in parallel. I have not tested this out, but I think a scoped or transient solution is the safer choice.
Here i have 2 concerns.
The text was updated successfully, but these errors were encountered: