c# - Using Ninject IOC to replace a factory -
i've got factory method inside parser. load token handler token, or drop through default handler. i've implemented switch
, dictionary<string,type>
both approaches require me store mapping somewhere else handler class.
we using ninject ioc , i've realized can using
kernel.get<itokenhandler>(tokenname);
but doesn't save me storing information on token handler can deal in 2 locations. there way can decorate handler gets mapped automatically?
if follow question correctly, sounds want retrieve named binding. didn't mention version of ninject using, based on code snippet, guessing using ninject 2.0. if that's case think suffice binding in module:
bind<itokenhandler>().to<yourconcretetypehere>().named(tokenname);
you bind many concrete types same interface , differentiate them name, , retrieve them using precise syntax you've specified in question.
if missing key, let me know.
Comments
Post a Comment