c# - How do I choose the implementation of a type been registered with Microsoft Unity -
say have interface named ipumaservices, , have 2 classes implement it: posixmlservices , taxmlservices.
now have interface called ipumanotification , class implementing called pumanotification. constructor of pumanotification receives ipumaservices implementation.
my question: in unity, how can register implementation of pumanotification injects posixmlservices in contructor , injects taxmlservices?
this have far.
using (_unitycontainer = new unitycontainer()) { _unitycontainer .registertype<ipumaservices, posixmlservices>("posixml") .registertype<ipumaservices, taxmlservices>("taxml") .registertype<ipumanotification, pumanotification>(); } i have not idea how make work requirements have above.
i not able research online issue not sure how describe issue facing.
i appreciate help.
you can specify resolved parameters constructor , resolve instance want:
using (_unitycontainer = new unitycontainer()) { _unitycontainer .registertype<ipumaservices, posixmlservices>("posixml") .registertype<ipumaservices, taxmlservices>("taxml") .registertype<ipumanotification, pumanotification>( new injectionconstructor( // explicitly specify constructor new resolvedparameter<ipumaservices>("taxml") // resolve parameter of type ); } if want register 2 ipumaservices, can name each 1 appropriately , resolve name when use them.
Comments
Post a Comment