i've got working unity container configured code. have move xml configuration, can't make correctly. don't know missing - maybe out there knows solution , can me out!
my solution layering fix protocol library correctly, handle different vendor specific messages differently, have robust backing api that. have 2 interfaces:
public interface icriteria { bool aremet(message message); } public interface iconsumer { icriteria criteria { get; } void handlemessage(message message); }
there default abstract implementation consumers:
namespace fix.messagehandling { public abstract class consumer : iconsumer { private readonly icriteria criteria; protected readonly iprocessor processor; public icriteria criteria { { return this.criteria; } } protected consumer(iprocessor processor, icriteria criteria) { //... } } }
then i've got abstract implementations different fix message types: each consumer abstraction has own criteria abstraction. (referenced in constructor well) e.g.
namespace fix.messagehandling.executionreport { public abstract class consumer : messagehandling.consumer { protected consumer(iprocessor processor, criteria criteria) : base(processor, criteria) { // ... } } public abstract class criteria : icriteria { // ... } }
i register icriteria instances code:
container.registertype<icriteria, vendor.criteria.spot>("spotcriteria"); container.registertype<icriteria, vendor.criteria.swap>("swapcriteria"); // etc.
after register iconsumer insatnces, in case executionreportconsumer instances, mapping iconsumer:
container.registertype< iconsumer, vendor.consumer.spot>("spotconsumer", new injectionconstructor( container.resolve<iprocessor>(), container.resolve<icriteria>("spotcriteria"))); // etc.
when resolve iconsumer-s, can registered consumers unitycontainer:
container.resolveall<iconsumer>();
this how tried xml after defining aliases:
<register type="icriteria" mapto="forwardcriteria" name="forwardcriteria" /> <register type="iconsumer" mapto="forwardconsumer" name="forwardconsumer"> <constructor> <param name="processor" dependencytype="iprocessor" /> <param name="criteria" dependencytype="executionreportcriteria" dependencyname="forwardcriteria" /> </constructor> </register>
if use xml configuration , call resolveall iconsumers, i've got exception
resolution of dependency failed, type = "fix.messagehandling.iconsumer", name = "forwardconsumer". exception occurred while: while resolving.
exception is: invalidoperationexception - type criteria not have accessible constructor.
at time of exception, container was:
resolving fix.vendor.consumer.forward,forwardconsumer (mapped fix.messagehandling.iconsumer, forwardconsumer) resolving parameter "criteria" of constructor fix.vendor.consumer.forward(fix.messagehandling.iprocessor processor, fix.messagehandling.executionreport.criteria criteria) resolving fix.messagehandling.executionreport.criteria,forwardcriteria
ok, figured out myself , i'm newbie , don't know - answer own question :]
if register criteria interface , concrete criteria implementations correct abstract base class, works charm!
<register type="icriteria" /> <register type="executionreportcriteria" mapto="forwardcriteria" name="forwardcriteria" /> <register type="iconsumer" mapto="forwardconsumer" name="forwardconsumer"> <constructor> <param name="processor" dependencytype="iprocessor" /> <param name="criteria" dependencyname="forwardcriteria" /> </constructor> </register>
Comments
Post a Comment