c# - Resolving generics in Windsor Castle -
i'm trying resolve object inherits template class
using system; using controller; namespace controller { public interface icontrollerbase<t> t:iviewbase { } public class controllerbase { public string modulename { get; set; } } public class controllerbase<t> : controllerbase, icontrollerbase<t> t : iviewbase { public virtual t view { get; set; } public controllerbase (t instance) { view = instance; } } } icontrollerbase added recently, match strategy: container.register (component.for(typeof(icontrollerbase<iviewbase>)).implementedby(typeof(controllerbase<iviewbase>)).lifestyle.transient);
next have class derrived controllerbase
using system; namespace hardwareconnections { public class hardwareconnectionscontroller : controller.controllerbase<ihardwareconnections> { public hardwareconnectionscontroller(ihardwareconnections view) : base(view) { base.modulename = "hardware connections"; console.writeline("\n\n\n\n"); console.writeline("constructor fired"); console.writeline("\n\n\n\n"); } } }
i'm trying resolve hardwareconnectionscontroller first resolving view class implements iviewbase interface , works fine, i'm getting instance of view , passing in constructor
but have problem resolving controller class
var hcon = container.resolve<controllerbase<iviewbase>>(new { view = plug});
error is:
castle.microkernel.componentnotfoundexception has been thrown no component supporting service petcontroller.controllerbase`1[[petcontroller.iviewbase, petcontroller, version=1.0.4988.28227, culture=neutral, publickeytoken=null]] found stack:
castle.microkernel.componentnotfoundexception: no component supporting service petcontroller.controllerbase`1[[petcontroller.iviewbase, petcontroller, version=1.0.4988.28227, culture=neutral, publickeytoken=null]] found @ castle.microkernel.defaultkernel.castle.microkernel.ikernelinternal.resolve (system.type service, idictionary arguments, ireleasepolicy policy) [0x00000] in <filename unknown>:0 @ castle.microkernel.defaultkernel.resolve (system.type service, idictionary arguments) [0x00000] in <filename unknown>:0 @ castle.windsor.windsorcontainer.resolve[controllerbase`1] (system.object argumentsasanonymoustype) [0x00000] in <filename unknown>:0 @ (wrapper remoting-invoke-with-check) castle.windsor.windsorcontainer:resolve (object) @ petcontroller.pluginfactory.loadplugins[iviewbase] (system.string searchlocation) [0x001f6] in /home/konrad/hg/pet/pet/petcontroller/utils/pluginfactory.cs:67 @ mainwindow..ctor () [0x00034] in /home/konrad/hg/pet/pet/petcontroller/mainwindow.cs:19 @ petcontroller.mainclass.main (system.string[] args) [0x00005] in /home/konrad/hg/pet/pet/petcontroller/main.cs:11 enter code here
i'm little bit confused sample... speaking if registered component for(typeof(icontrollerbase<iviewbase>))
have resolve using same type.
instead of
var hcon = container.resolve<controllerbase<iviewbase>>(new { view = plug});
try
var hcon = container.resolve<icontrollerbase<iviewbase>>(new { view = plug});
i'm not sure why registering component using implementation generic type instead of real one... that's might use instead
container.register (component.for(typeof(icontrollerbase<iviewbase>)).implementedby(typeof(hardwareconnectionscontroller)).lifestyle.transient);
Comments
Post a Comment