Using MVVM's SimpleIoc, I would like to register an implementation for a given interface, but the implementation requires one parameter in its constructor:
public class MyServiceImplementation : IMyService {
public MyServiceImplementation(string contructorString) { ... }
}
I was hoping that registering the implementation of the interface would work, but SimpleIoc doesn't consider the hint when it tries to resolve the interface.
SimpleIoc.Default.Register<MyServiceImplementation>(() => {
return new MyServiceImplementation("Hello World");
});
SimpleIoc.Default.Register<IMyService, MyServiceImplementation>();
Would there be a way to do this with SimpleIoc, or should I consider using a more complete Ioc?
Edit: This does the trick, but I still wonder why the form above doesn't work.
SimpleIoc.Default.Register<IMyService>(() => {
return new MyServiceImplementation("Hello World");
});
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…