c# - Using constructor injection when caller expects a specific constructor signature -


i'm new di in .net c# & autofac , having problems understand how use di when can't control caller side.

there 2 scenarios have problems understand.

scenario 1: caller expects default constructor (without parameters)

how handle scenario when still want inject service interfaces when class constructed? thinking of constructor chaining, mean have know concrete type , works around idea of di. (at least think).

public class serviceworker {     iservice _service;      public serviceworker(iservice service)      {          _service = service     } }  public class caller {     // no way change this.      var serviceworker = new serviceworker(); } 

scneario 2: caller expects specific constructor signature (e.g.

same question here. how can inject additional dependencies when caller expects exact match constructor signature?

i think main issue in understanding concept is, don't see how di partially when not constructed di (caller)

public class serviceworker {     iservice _service;      public serviceworker(string name, string id, iservice service)      {          _service = service     } }  public class caller {     // no way change this.      var serviceworker = new serviceworker(name, id); } 

i know, pretty basic, believe need understand first before moving on. there alternatives?


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -