c# - Castle Windsor - Get Root Component type being resolved -
i using castle windsor ioc container , nlog in project. trying inject ilogger classes logging needed. want ilogger resolved logmanager.getlogger(roottypename).
is there way root type name? tried following, creationcontext.requestedtype doesnt root type.
container.register(component.for<ilogger>() .usingfactorymethod((y, creationcontext) => logmanager.getlogger(creationcontext.requestedtype.fullname)) .lifestyletransient());
structuremap has provision it
x.for<logger>().use(y => logmanager.getlogger(y.roottype.fullname));
you can achieve subresolver...
public class loggerresolver : isubdependencyresolver { public bool canresolve(creationcontext context, isubdependencyresolver contexthandlerresolver, componentmodel model, dependencymodel dependency) { return dependency.targettype == typeof(ilogger); } public object resolve(creationcontext context, isubdependencyresolver contexthandlerresolver, componentmodel model, dependencymodel dependency) { return new logmanager.getlogger(model.implementation.fullname); } }
than add kernel,
kernel.resolver.addsubresolver(new loggerresolver())
and drop previous ilogger registration.
Comments
Post a Comment