开发者

How to passing parameter to constructor when Resolve a View..?

开发者 https://www.devze.com 2023-01-02 00:00 出处:网络
my View constructor: public View1(IRegionManager regionManager, IUnityContainer container, bool myParam)

my View constructor:

public View1(IRegionManager regionManager, IUnityContainer container, bool myParam)
{
}

How to set myParam开发者_如何学Python when I do Resolve<View1>()? Thank you.


You need to register the type with Unity and specify all the arguments:

this.container.RegisterType<View1>(new InjectionConstructor(this.container.Resolve<IRegionManager>(), this.container,true));

Then it'll know how to resolve it. Kind of defeats the purpose a little, which is why you may be better off setting the bool value as a property, and using InjectionProperty instead.

0

精彩评论

暂无评论...
验证码 换一张
取 消