Let's say I have the following model:
public class Dojo
{
public int DojoId {get;set;}
public DojoProperty PropOne{get;protected set;}
public DojoProperty PropTwo{ get;protected set; }
public virtual ICollection<ISamurai> Warriors { get; set; }
private IDojoService _dojoService;
public Dojo(IDojoService dojoService)
{
_dojoService = dojoService;
}
}
I'm using the latest ninject for DI and want to have a factory method and also implement the latest version of Entity Framework for ORM so I refactor the class as follows:
public class Dojo
{
public int DojoId {get;set;}
public DojoProperty PropOne{get;protected set;}
public DojoProperty PropTwo{ get;protected set; }
public virtual ICollection<ISamurai> Warriors { get; set; }
private IDojoService _dojoService;
private Dojo(IDojoService dojoService)
{
_dojoService = dojoService;
}
public static Dojo Create(IDojoService dojoService, IDojoConfig dojoConfig)
{
return new Dojo(dojoService) {PropOne = dojoConfig.PropOne, PropTwo = dojoConfig.PropTwo};
}
}
My question is, how do I get Entity Framework to use the IoC container to inject the IDojoService when I retrieve the Dojo from the database i.e.:
context.Dojos.Find(dojoId);