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

Why Creating new WcfProxy in constructor? #10

Open
Reena-Patel opened this issue Mar 18, 2021 · 1 comment
Open

Why Creating new WcfProxy in constructor? #10

Reena-Patel opened this issue Mar 18, 2021 · 1 comment

Comments

@Reena-Patel
Copy link

Here i have 2 concerns.

  1. 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));

  1. 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));
@jolmari
Copy link
Owner

jolmari commented Mar 24, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants