Using Microsoft Unity IOC, how can you pass it an existing object to inject? -


so if have:

public class customerviewmodel {     public customerviewmodel(icustomer customer)     {         this.customer = customer     } } 

then there way achieve:

icustomerviewmodel customerviewmodel = container.resolve<icustomerviewmodel>(existingcustomer); 

if want build-up existing instance through property , method injection, can use following:

var model = new customerviewmodel(customer); model = container.buildup(model); 

in general not recommend using feature of unity. need it, it's warning sign fixed adjusting design bit work more naturally ioc pattern (not framework). more details on how using it, community can offer other options...


Comments