【发布时间】:2017-08-25 06:39:54
【问题描述】:
我正在使用 Unity 来控制我的 Xamarin Forms 应用程序中的依赖注入。我有一个视图模型类,它采用父 ID 和统一注入服务作为构造函数参数。
public class BrowseViewModel {
public BrowseViewModel(int parentId, IInjectedService injectedService) {
}
}
我已经在统一容器中注册了这个类。
unityContainer.registerType<BrowseViewModel>();
我也在统一容器中注册了服务。
unityContainer.registerType<IInjectedService, InjectedService>();
我的问题是,当 Unity 创建我的类的实例时,如何指定 parentId 的值?我不认为我应该指定injectedService参数,因为我已经用unity注册了这个类,它是一个单例类。
【问题讨论】:
标签: c# xamarin dependency-injection xamarin.forms unity-container