我已阅读文档,但找不到任何关于解析类型并同时覆盖其某些依赖项的信息。举个例子最容易说明
public class A
{
public A(IServiceA a, IServiceB b) {}
}
// Resolve scenarion
type =>
{
// type is A
var a = Container.Resolve<IServiceA>();
a.SomeProperty = "magic";
return Container.Resolve(type) // TODO: How to resolve A using a
}
是否有意义?正在寻找类似的东西
return Container.Resolve(type, Rule.Override.TypeOf<IServiceA>(a));
DryIoc 做得很好
编辑(2016-05-26)我的问题具有误导性。下面是完整的代码示例(对于prism)
ViewModelLocationProvider.SetDefaultViewModelFactory((view, type) =>
{
var page = view as Page;
if (page != null)
{
var navigationService = Container.Resolve<INavigationService>();
((IPageAware)navigationService).Page = page;
var @override = Container.Resolve<Func<INavigationService, type>>(); // How to do this
return @override(navigationService);
}
return Container.Resolve(type);
});